From c26c393c9c5c9ca1182e750774d98278934ac459 Mon Sep 17 00:00:00 2001 From: Eric Schulte Date: Sun, 10 May 2009 19:47:22 -0700 Subject: [PATCH] evaluate source code blocks as spreadsheet formulas in tables --- litorgy/litorgy-init.el | 1 + litorgy/litorgy-ref.el | 6 ++-- litorgy/litorgy-table.el | 3 +- rorg.org | 60 +++++++++++++++++++++------------------- 4 files changed, 37 insertions(+), 33 deletions(-) diff --git a/litorgy/litorgy-init.el b/litorgy/litorgy-init.el index 63700c381..71421a553 100644 --- a/litorgy/litorgy-init.el +++ b/litorgy/litorgy-init.el @@ -36,6 +36,7 @@ (require 'litorgy-ref) (require 'litorgy-ui) (require 'litorgy-exp) +(require 'litorgy-table) ;; language specific files (require 'litorgy-script) diff --git a/litorgy/litorgy-ref.el b/litorgy/litorgy-ref.el index e6bd873b9..984676510 100644 --- a/litorgy/litorgy-ref.el +++ b/litorgy/litorgy-ref.el @@ -89,7 +89,8 @@ return nil." (defun litorgy-ref-resolve-reference (ref) "Resolve the reference and return it's value" (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 (when (string-match "\\(.+\\)\(\\(.+\\)\)" ref) (save-match-data @@ -109,7 +110,8 @@ return nil." ;; buffer (marker-buffer id-loc) ;; loc (marker-position id-loc)) ;; (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))) (forward-line 1) (beginning-of-line) diff --git a/litorgy/litorgy-table.el b/litorgy/litorgy-table.el index b57392efc..b6e7cb1b1 100644 --- a/litorgy/litorgy-table.el +++ b/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 results #+end_src" - (message "sbe: executing source block") (let ((params (eval `(litorgy-parse-header-arguments (concat ":var results=" (symbol-name ,source-block) @@ -77,8 +76,8 @@ results (format "%S=%s" (first var-spec) (second var-spec))) ',variables ", ") ")"))))) - (message (format "litorgy-execute-src-block emacs-lisp results %S" (org-combine-plists params '((:results . "silent"))))) (litorgy-execute-src-block nil (list "emacs-lisp" "results" (org-combine-plists params '((:results . "silent"))))))) +(provide 'litorgy-table) ;;; litorgy-table.el ends here diff --git a/rorg.org b/rorg.org index 9b49a9a6c..e18f57e23 100644 --- a/rorg.org +++ b/rorg.org @@ -3,7 +3,7 @@ #+SEQ_TODO: TODO OPEN PROPOSED | DONE RESOLVED REJECTED #+STARTUP: oddeven -* Tasks [7/17] +* Tasks [8/16] ** TODO 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 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] 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 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 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 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 (sbe 'fibbd (n "8"))