diff --git a/library-of-babel.org b/library-of-babel.org index ee86fe713..df08c4a61 100644 --- a/library-of-babel.org +++ b/library-of-babel.org @@ -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 diff --git a/lisp/org-babel-lob.el b/lisp/org-babel-lob.el index c3373b19e..58e55a741 100644 --- a/lisp/org-babel-lob.el +++ b/lisp/org-babel-lob.el @@ -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 diff --git a/lisp/org-babel.el b/lisp/org-babel.el index bd498a13d..3b2c40cd6 100644 --- a/lisp/org-babel.el +++ b/lisp/org-babel.el @@ -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))