Explorar o código

evaluate source code blocks as spreadsheet formulas in tables

Eric Schulte %!s(int64=16) %!d(string=hai) anos
pai
achega
c26c393c9c
Modificáronse 4 ficheiros con 37 adicións e 33 borrados
  1. 1 0
      litorgy/litorgy-init.el
  2. 4 2
      litorgy/litorgy-ref.el
  3. 1 2
      litorgy/litorgy-table.el
  4. 31 29
      rorg.org

+ 1 - 0
litorgy/litorgy-init.el

@@ -36,6 +36,7 @@
 (require 'litorgy-ref)
 (require 'litorgy-ref)
 (require 'litorgy-ui)
 (require 'litorgy-ui)
 (require 'litorgy-exp)
 (require 'litorgy-exp)
+(require 'litorgy-table)
 
 
 ;; language specific files
 ;; language specific files
 (require 'litorgy-script)
 (require 'litorgy-script)

+ 4 - 2
litorgy/litorgy-ref.el

@@ -89,7 +89,8 @@ return nil."
 (defun litorgy-ref-resolve-reference (ref)
 (defun litorgy-ref-resolve-reference (ref)
   "Resolve the reference and return it's value"
   "Resolve the reference and return it's value"
   (save-excursion
   (save-excursion
-    (let (type args new-ref)
+    (let ((case-fold-search t)
+          type args new-ref) ;; case search?
       ;; assign any arguments to pass to source block
       ;; assign any arguments to pass to source block
       (when (string-match "\\(.+\\)\(\\(.+\\)\)" ref)
       (when (string-match "\\(.+\\)\(\\(.+\\)\)" ref)
         (save-match-data
         (save-match-data
@@ -109,7 +110,8 @@ return nil."
         ;;       buffer (marker-buffer id-loc)
         ;;       buffer (marker-buffer id-loc)
         ;;       loc (marker-position id-loc))
         ;;       loc (marker-position id-loc))
         ;; (move-marker id-loc nil)
         ;; (move-marker id-loc nil)
-        (error (format "reference '%s' not found in this buffer" ref)))
+        (progn (message (format "reference '%s' not found in this buffer" ref))
+               (error (format "reference '%s' not found in this buffer" ref))))
       (while (not (setq type (litorgy-ref-at-ref-p)))
       (while (not (setq type (litorgy-ref-at-ref-p)))
         (forward-line 1)
         (forward-line 1)
         (beginning-of-line)
         (beginning-of-line)

+ 1 - 2
litorgy/litorgy-table.el

@@ -68,7 +68,6 @@ source code block.
 #+begin_src emacs-lisp :var results=source-block(n=2, m=3) :results silent
 #+begin_src emacs-lisp :var results=source-block(n=2, m=3) :results silent
 results
 results
 #+end_src"
 #+end_src"
-  (message "sbe: executing source block")
   (let ((params (eval `(litorgy-parse-header-arguments
   (let ((params (eval `(litorgy-parse-header-arguments
                         (concat ":var results="
                         (concat ":var results="
                                 (symbol-name ,source-block)
                                 (symbol-name ,source-block)
@@ -77,8 +76,8 @@ results
                                              (format "%S=%s" (first var-spec) (second var-spec)))
                                              (format "%S=%s" (first var-spec) (second var-spec)))
                                            ',variables ", ")
                                            ',variables ", ")
                                 ")")))))
                                 ")")))))
-    (message (format "litorgy-execute-src-block emacs-lisp results %S" (org-combine-plists params '((:results . "silent")))))
     (litorgy-execute-src-block
     (litorgy-execute-src-block
      nil (list "emacs-lisp" "results" (org-combine-plists params '((:results . "silent")))))))
      nil (list "emacs-lisp" "results" (org-combine-plists params '((:results . "silent")))))))
 
 
+(provide 'litorgy-table)
 ;;; litorgy-table.el ends here
 ;;; litorgy-table.el ends here

+ 31 - 29
rorg.org

@@ -3,7 +3,7 @@
 #+SEQ_TODO:  TODO OPEN PROPOSED | DONE RESOLVED REJECTED
 #+SEQ_TODO:  TODO OPEN PROPOSED | DONE RESOLVED REJECTED
 #+STARTUP: oddeven
 #+STARTUP: oddeven
 
 
-* Tasks [7/17]
+* Tasks [8/16]
 
 
 ** TODO share litorgy
 ** TODO share litorgy
 how should we share litorgy?
 how should we share litorgy?
@@ -65,21 +65,6 @@ source-code block.  If the assertion fails then the point could be
 moved to the block, and error messages and highlighting etc... could
 moved to the block, and error messages and highlighting etc... could
 ensue
 ensue
 
 
-** TODO integration with org tables
-We should make it easy to call litorgy source blocks from org-mode
-table formulas.  This is practical now that it is possible to pass
-arguments to litorgical source blocks.
-
-See the related [[* (sandbox) integration w/org tables][sandbox]] header for tests/examples.
-
-*** digging in org-table.el
-In the past [[file:~/src/org/lisp/org-table.el::org%20table%20el%20The%20table%20editor%20for%20Org%20mode][org-table.el]] has proven difficult to work with.
-
-Should be a hook in [[file:~/src/org/lisp/org-table.el::defun%20org%20table%20eval%20formula%20optional%20arg%20equation][org-table-eval-formula]].
-
-Looks like I need to change this [[file:~/src/org/lisp/org-table.el::if%20lispp][if statement]] (line 2239) into a cond
-expression.
-
 ** TODO inline source code blocks [3/5]
 ** TODO inline source code blocks [3/5]
    Like the =\R{ code }= blocks
    Like the =\R{ code }= blocks
 
 
@@ -185,6 +170,21 @@ one that comes to mind is the ability to treat a source-code block
 like a function which accepts arguments and returns results. Actually
 like a function which accepts arguments and returns results. Actually
 this can be it's own TODO (see [[* source blocks as functions][source blocks as functions]]).
 this can be it's own TODO (see [[* source blocks as functions][source blocks as functions]]).
 
 
+** DONE integration with org tables
+We should make it easy to call litorgy source blocks from org-mode
+table formulas.  This is practical now that it is possible to pass
+arguments to litorgical source blocks.
+
+See the related [[* (sandbox) integration w/org tables][sandbox]] header for tests/examples.
+
+*** digging in org-table.el
+In the past [[file:~/src/org/lisp/org-table.el::org%20table%20el%20The%20table%20editor%20for%20Org%20mode][org-table.el]] has proven difficult to work with.
+
+Should be a hook in [[file:~/src/org/lisp/org-table.el::defun%20org%20table%20eval%20formula%20optional%20arg%20equation][org-table-eval-formula]].
+
+Looks like I need to change this [[file:~/src/org/lisp/org-table.el::if%20lispp][if statement]] (line 2239) into a cond
+expression.
+
 ** DONE source blocks as functions
 ** DONE source blocks as functions
 
 
 Allow source code blocks to be called like functions, with arguments
 Allow source code blocks to be called like functions, with arguments
@@ -689,19 +689,21 @@ produces an error when called from inside the table.  I think there
 must be some narrowing going on during intra-table emacs-lisp
 must be some narrowing going on during intra-table emacs-lisp
 evaluation.
 evaluation.
 
 
-| original | fibbd  |
-|----------+--------|
-|        0 | #ERROR |
-|        1 |        |
-|        2 |        |
-|        3 |        |
-|        4 |        |
-|        5 |        |
-|        6 |        |
-|        7 |        |
-|        8 |        |
-|        9 |        |
-#+TBLFM: @2$2='(sbe 'fibbd (n $1))
+| original | fibbd |
+|----------+-------|
+|        0 |     1 |
+|        1 |     1 |
+|        2 |     2 |
+|        3 |     3 |
+|        4 |     5 |
+|        5 |     8 |
+|        6 |    13 |
+|        7 |    21 |
+|        8 |    34 |
+|        9 |    55 |
+#+TBLFM: $2='(sbe 'fibbd (n $1))
+
+silent-result
 
 
 #+begin_src emacs-lisp :results silent
 #+begin_src emacs-lisp :results silent
 (sbe 'fibbd (n "8"))
 (sbe 'fibbd (n "8"))