forked from mirrors/org-mode
Enabling LoB to put results in buffer, and slowly moving towards more
unified concept of function calls. Previously LoB calls were not able to produce results in the buffer. These changes go some way to allowing them to do that. [There are still some bugs to deal with]. That meant changing org-babel.el so that there is a notion of the `source block name' for a LoB line, in order to construct a #+resname (currently I've made the name the same as the function call). I'm also slowly moving towards unifying the notion of `function calls' a bit more: I've changed the org-babel-lob-one-liner-regexp so that instead of a monolithic match it now matches first the function name, and second the function arguments in parentheses. org-babel-lob-get-info makes that match, and although it still concatenates them and returns the string, the two elements can be accessed immediately afterwards using match-string. So that situation is very similar to org-babel-get-src-block-name, whose job (in this branch) is also to parse the function *name* and the function *arguments*. In a few places in the code (esp. function names), I think the word `info' should be replaced with `call' or `function call', which I believe more accurately indicates what the `info' is: a function definition, together with bound arguments/references. The function call syntax, i.e. function-name(arg1=ref1), originally introduced for references (and thereby in LoB), and which I'm proposing we use throughout, raises the question of default arguments, and those being over-ridden by supplied arguments, as in e.g. python, and R.
This commit is contained in:
parent
42fe3144b7
commit
44adc98505
|
@ -14,19 +14,36 @@
|
|||
* Plotting code
|
||||
Plot column 2 (y axis) against column 1 (x axis). Columns 3 and beyond, if present, are ignored.
|
||||
|
||||
#+resname: R-plot-default-data
|
||||
| 0 | 0 |
|
||||
|
||||
#+srcname: R-plot
|
||||
#+begin_src R :results silent :var data=R-plot-default-data
|
||||
#+srcname: R-plot(data=R-plot-example-data)
|
||||
#+begin_src R :session *R*
|
||||
plot(data)
|
||||
"R plot complete"
|
||||
#+end_src
|
||||
|
||||
#+tblname: example-R-plot-data
|
||||
|
||||
|
||||
#+tblname: R-plot-example-data
|
||||
| 1 | 2 |
|
||||
| 2 | 4 |
|
||||
| 3 | 9 |
|
||||
| 4 | 16 |
|
||||
| 5 | 25 |
|
||||
|
||||
#+lob: R-plot(data=example-R-plot-data)
|
||||
#+lob: R-plot(data=R-plot-example-data)
|
||||
|
||||
|
||||
|
||||
#+tblname: XX
|
||||
| 1 | 1 |
|
||||
| 2 | .5 |
|
||||
| 3 | .3333 |
|
||||
| 4 | .25 |
|
||||
| 5 | .2 |
|
||||
| 6 | .1666 |
|
||||
| 7 | 0.1428 |
|
||||
|
||||
#+srcname: python-identity(a=5)
|
||||
#+begin_src python
|
||||
a
|
||||
#+end_src
|
||||
|
|
|
@ -62,7 +62,7 @@ add files to this list use the `org-babel-lob-ingest' command."
|
|||
|
||||
;; functions for executing lob one-liners
|
||||
|
||||
(defvar org-babel-lob-one-liner-regexp "#\\+lob:[ \t]+\\([^\n]+\\)\n")
|
||||
(defvar org-babel-lob-one-liner-regexp "#\\+lob:[ \t]+\\(.+?\\)\(\\(.*\\)\)")
|
||||
|
||||
(defun org-babel-lob-execute-maybe ()
|
||||
"Detect if this is context for a org-babel Library Of Babel
|
||||
|
@ -75,19 +75,27 @@ the Library."
|
|||
(add-hook 'org-ctrl-c-ctrl-c-hook 'org-babel-lob-execute-maybe)
|
||||
|
||||
(defun org-babel-lob-get-info ()
|
||||
"Return the information of the current Library of Babel line as
|
||||
a list of the following form.
|
||||
"Return the function call supplied on the current Library of
|
||||
Babel line as a string.
|
||||
|
||||
(source-block-name header-arguments-alist)"
|
||||
This function is analogous to org-babel-get-src-block-name. For
|
||||
both functions, after they are called, (match-string 1) matches
|
||||
the function name, and (match-string 2) matches the function
|
||||
arguments inside the parentheses. I think perhaps these functions
|
||||
should be renamed to bring out this similarity, perhaps involving
|
||||
the word 'call'."
|
||||
(let ((case-fold-search t))
|
||||
(save-excursion
|
||||
(move-beginning-of-line 1)
|
||||
(if (looking-at org-babel-lob-one-liner-regexp)
|
||||
(org-babel-clean-text-properties (match-string 1))))))
|
||||
(org-babel-clean-text-properties
|
||||
(format "%s(%s)" (match-string 1) (match-string 2)))))))
|
||||
|
||||
(defun org-babel-lob-execute (info)
|
||||
(let ((params (org-babel-parse-header-arguments (concat ":var results=" info))))
|
||||
(org-babel-execute-src-block t (list "emacs-lisp" "results" params))))
|
||||
(let ((params (org-babel-merge-params
|
||||
org-babel-default-header-args
|
||||
(org-babel-parse-header-arguments (concat ":var results=" info)))))
|
||||
(org-babel-execute-src-block nil (list "emacs-lisp" "results" params))))
|
||||
|
||||
(provide 'org-babel-lob)
|
||||
;;; org-babel-lob.el ends here
|
||||
|
|
|
@ -255,16 +255,26 @@ replaced, and may need to be reinstated in this function. "
|
|||
(widen)))
|
||||
|
||||
(defun org-babel-get-src-block-name ()
|
||||
"Return the name of the current source block if one exists"
|
||||
"Return the name of the current source block if one exists.
|
||||
|
||||
This function is analogous to org-babel-lob-get-info. For both
|
||||
functions, after they are called, (match-string 1) matches the
|
||||
function name, and (match-string 2) matches the function
|
||||
arguments inside the parentheses. I think perhaps these functions
|
||||
should be renamed to bring out this similarity, perhaps involving
|
||||
the word 'call'."
|
||||
(let ((case-fold-search t)
|
||||
(head (org-babel-where-is-src-block-head)))
|
||||
(when head
|
||||
(save-excursion
|
||||
(goto-char head)
|
||||
(if (save-excursion
|
||||
(forward-line -1)
|
||||
(looking-at "#\\+srcname:[ \f\t\n\r\v]*\\([^ \f\t\n\r\v]+\\)\(\\(.*\\)\)"))
|
||||
(org-babel-clean-text-properties (match-string 1)))))))
|
||||
(if head
|
||||
(save-excursion
|
||||
(goto-char head)
|
||||
(if (save-excursion
|
||||
(forward-line -1)
|
||||
(looking-at "#\\+srcname:[ \f\t\n\r\v]*\\([^ \f\t\n\r\v]+\\)\(\\(.*\\)\)"))
|
||||
(org-babel-clean-text-properties (match-string 1))))
|
||||
;; Try testing if we're on a lob one-liner; if so use the LoB
|
||||
;; function call as the name
|
||||
(org-babel-lob-get-info))))
|
||||
|
||||
(defun org-babel-get-src-block-info ()
|
||||
"Return the information of the current source block as a list
|
||||
|
@ -282,7 +292,8 @@ of the following form. (language body header-arguments-alist)"
|
|||
(defun org-babel-get-src-block-function-args ()
|
||||
(when (org-babel-get-src-block-name)
|
||||
(mapcar (lambda (ref) (cons :var ref))
|
||||
(split-string (match-string 2) ",[ \f\t\n\r\v]*"))))
|
||||
(split-string (org-babel-clean-text-properties (match-string 2))
|
||||
",[ \f\t\n\r\v]*"))))
|
||||
|
||||
(defmacro org-babel-map-source-blocks (file &rest body)
|
||||
"Evaluate BODY forms on each source-block in FILE."
|
||||
|
@ -378,10 +389,12 @@ source block. Specifically at the beginning of the #+RESNAME:
|
|||
line. If no result exists for this block then create a
|
||||
#+RESNAME: line following the source block."
|
||||
(save-excursion
|
||||
(goto-char (org-babel-where-is-src-block-head))
|
||||
(let ((name (org-babel-get-src-block-name)) end head)
|
||||
(let ((on-lob-line (progn (beginning-of-line 1)
|
||||
(looking-at org-babel-lob-one-liner-regexp)))
|
||||
(name (org-babel-get-src-block-name)) end head)
|
||||
(unless on-lob-line (goto-char (org-babel-where-is-src-block-head)))
|
||||
(or (and name (message name) (org-babel-find-named-result name))
|
||||
(and (re-search-forward "#\\+end_src" nil t)
|
||||
(and (or on-lob-line (re-search-forward "#\\+end_src" nil t))
|
||||
(progn (move-end-of-line 1)
|
||||
(if (eobp) (insert "\n") (forward-char 1))
|
||||
(setq end (point))
|
||||
|
|
Loading…
Reference in New Issue