mirror of
https://git.savannah.gnu.org/git/emacs/org-mode.git
synced 2024-09-29 18:00:49 +00:00
evaluate source code blocks as spreadsheet formulas in tables
This commit is contained in:
parent
71b6ca8005
commit
c26c393c9c
|
@ -36,6 +36,7 @@
|
|||
(require 'litorgy-ref)
|
||||
(require 'litorgy-ui)
|
||||
(require 'litorgy-exp)
|
||||
(require 'litorgy-table)
|
||||
|
||||
;; language specific files
|
||||
(require 'litorgy-script)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
60
rorg.org
60
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"))
|
||||
|
|
Loading…
Reference in a new issue