mirror of
https://git.savannah.gnu.org/git/emacs/org-mode.git
synced 2024-11-23 07:18:53 +00:00
passing header arguments through to called code blocks
* lisp/ob-lob.el (org-babel-lob-get-info): including pass-through header arguments in results variable header argument string * lisp/ob.el (org-babel-execute-src-block): working with new header argument setup (org-babel-parse-header-arguments): only split header argument strings when []'s are balanced
This commit is contained in:
parent
6630edbd0f
commit
c676f62361
@ -39,7 +39,6 @@
|
||||
(defvar org-babel-lob-one-liner-regexp)
|
||||
(defvar org-babel-ref-split-regexp)
|
||||
(declare-function org-babel-lob-get-info "ob-lob" ())
|
||||
(declare-function org-babel-ref-literal "ob-ref" (ref))
|
||||
|
||||
(add-to-list 'org-export-interblocks '(src org-babel-exp-inline-src-blocks))
|
||||
(add-to-list 'org-export-interblocks '(lob org-babel-exp-lob-one-liners))
|
||||
|
@ -71,7 +71,8 @@ If you change the value of this variable then your files may
|
||||
(concat
|
||||
"^\\([ \t]*\\)#\\+\\(?:"
|
||||
(mapconcat #'regexp-quote org-babel-lob-call-aliases "\\|")
|
||||
"\\):[ \t]+\\([^\(\)\n]+\\)\(\\([^\n]*\\)\)\\(\\[.+\\]\\|\\)[ \t]*\\([^\n]*\\)")
|
||||
"\\):[ \t]+\\([^\(\)\n]+?\\)\\(\\[\\(.*\\)\\]\\|\\(\\)\\)"
|
||||
"\(\\([^\n]*\\)\)\\(\\[.+\\]\\|\\)[ \t]*\\([^\n]*\\)")
|
||||
"Regexp to match calls to predefined source block functions.")
|
||||
|
||||
;; functions for executing lob one-liners
|
||||
@ -94,9 +95,12 @@ if so then run the appropriate source block from the Library."
|
||||
(append
|
||||
(mapcar #'org-babel-clean-text-properties
|
||||
(list
|
||||
(format "%s(%s)%s"
|
||||
(match-string 2) (match-string 3) (match-string 4))
|
||||
(match-string 5)))
|
||||
(format "%s%s(%s)%s"
|
||||
(match-string 2)
|
||||
(if (match-string 4)
|
||||
(concat "[" (match-string 4) "]") "")
|
||||
(or (match-string 6) "") (match-string 7))
|
||||
(match-string 8)))
|
||||
(list (length (match-string 1))))))))
|
||||
|
||||
(defun org-babel-lob-execute (info)
|
||||
|
@ -73,46 +73,39 @@ the variable."
|
||||
(let ((var (match-string 1 assignment))
|
||||
(ref (match-string 2 assignment)))
|
||||
(cons (intern var)
|
||||
((lambda (val)
|
||||
(if (equal :ob-must-be-reference val)
|
||||
(org-babel-ref-resolve ref) val))
|
||||
(org-babel-ref-literal ref))))))
|
||||
|
||||
(defun org-babel-ref-literal (ref)
|
||||
"Return the value of REF if it is a literal value.
|
||||
Determine if the right side of a header argument variable
|
||||
assignment is a literal value or is a reference to some external
|
||||
resource. REF should be a string of the right hand side of the
|
||||
assignment. If REF is literal then return it's value, otherwise
|
||||
return nil."
|
||||
(let ((out (org-babel-read ref)))
|
||||
(if (equal out ref)
|
||||
(if (string-match "^\".+\"$" ref)
|
||||
(read ref)
|
||||
:ob-must-be-reference)
|
||||
out)))
|
||||
(let ((out (org-babel-read ref)))
|
||||
(if (equal out ref)
|
||||
(if (string-match "^\".+\"$" ref)
|
||||
(read ref)
|
||||
(org-babel-ref-resolve ref))
|
||||
out))))))
|
||||
|
||||
(defvar org-babel-library-of-babel)
|
||||
(defun org-babel-ref-resolve (ref)
|
||||
"Resolve the reference REF and return its value."
|
||||
(save-excursion
|
||||
(let ((case-fold-search t)
|
||||
type args new-refere new-referent result lob-info split-file split-ref
|
||||
index index-row index-col)
|
||||
type args new-refere new-header-args new-referent result
|
||||
lob-info split-file split-ref index index-row index-col)
|
||||
;; if ref is indexed grab the indices -- beware nested indices
|
||||
(when (and (string-match "\\[\\(.+\\)\\]" ref)
|
||||
(when (and (string-match "\\[\\([^\\[]+\\)\\]$" ref)
|
||||
(let ((str (substring ref 0 (match-beginning 0))))
|
||||
(= (org-count ?( str) (org-count ?) str))))
|
||||
(setq index (match-string 1 ref))
|
||||
(setq ref (substring ref 0 (match-beginning 0))))
|
||||
;; assign any arguments to pass to source block
|
||||
(when (string-match "^\\(.+?\\)\(\\(.*\\)\)$" ref)
|
||||
(setq new-refere (match-string 1 ref))
|
||||
(setq new-referent (match-string 2 ref))
|
||||
(when (string-match
|
||||
"^\\(.+?\\)\\(\\[\\(.*\\)\\]\\|\\(\\)\\)\(\\(.*\\)\)$" ref)
|
||||
(setq new-refere (match-string 1 ref))
|
||||
(setq new-header-args (match-string 3 ref))
|
||||
(setq new-referent (match-string 5 ref))
|
||||
(when (> (length new-refere) 0)
|
||||
(if (> (length new-referent) 0)
|
||||
(setq args (mapcar (lambda (ref) (cons :var ref))
|
||||
(org-babel-ref-split-args new-referent))))
|
||||
(when (> (length new-referent) 0)
|
||||
(setq args (mapcar (lambda (ref) (cons :var ref))
|
||||
(org-babel-ref-split-args new-referent))))
|
||||
(when (> (length new-header-args) 0)
|
||||
(setq args (append (org-babel-parse-header-arguments new-header-args)
|
||||
args)))
|
||||
(setq ref new-refere)))
|
||||
(when (string-match "^\\(.+\\):\\(.+\\)$" ref)
|
||||
(setq split-file (match-string 1 ref))
|
||||
|
51
lisp/ob.el
51
lisp/ob.el
@ -362,10 +362,12 @@ block."
|
||||
(new-hash (when cache? (org-babel-sha1-hash info)))
|
||||
(old-hash (when cache? (org-babel-result-hash info)))
|
||||
(body (setf (nth 1 info)
|
||||
(if (and (cdr (assoc :noweb params))
|
||||
(string= "yes" (cdr (assoc :noweb params))))
|
||||
(org-babel-expand-noweb-references info)
|
||||
(nth 1 info))))
|
||||
(let ((noweb (cdr (assoc :noweb params))))
|
||||
(if (and noweb
|
||||
(or (string= "yes" noweb)
|
||||
(string= "tangle" noweb)))
|
||||
(org-babel-expand-noweb-references info)
|
||||
(nth 1 info)))))
|
||||
(cmd (intern (concat "org-babel-execute:" lang)))
|
||||
(dir (cdr (assoc :dir params)))
|
||||
(default-directory
|
||||
@ -378,7 +380,7 @@ block."
|
||||
result)
|
||||
(unwind-protect
|
||||
(flet ((call-process-region (&rest args)
|
||||
(apply 'org-babel-tramp-handle-call-process-region args)))
|
||||
(apply 'org-babel-tramp-handle-call-process-region args)))
|
||||
(unless (fboundp cmd)
|
||||
(error "No org-babel-execute function for %s!" lang))
|
||||
(if (and (not arg) new-hash (equal new-hash old-hash))
|
||||
@ -892,17 +894,32 @@ may be specified at the top of the current buffer."
|
||||
|
||||
(defun org-babel-parse-header-arguments (arg-string)
|
||||
"Parse a string of header arguments returning an alist."
|
||||
(if (> (length arg-string) 0)
|
||||
(delq nil
|
||||
(mapcar
|
||||
(lambda (arg)
|
||||
(if (string-match
|
||||
"\\([^ \f\t\n\r\v]+\\)[ \f\t\n\r\v]+\\([^ \f\t\n\r\v]+.*\\)"
|
||||
arg)
|
||||
(cons (intern (concat ":" (match-string 1 arg)))
|
||||
(org-babel-read (org-babel-chomp (match-string 2 arg))))
|
||||
(cons (intern (concat ":" arg)) nil)))
|
||||
(split-string (concat " " arg-string) "[ \f\t\n\r\v]+:" t)))))
|
||||
(when (> (length arg-string) 0)
|
||||
(delq nil
|
||||
(mapcar
|
||||
(lambda (arg)
|
||||
(if (string-match
|
||||
"\\([^ \f\t\n\r\v]+\\)[ \f\t\n\r\v]+\\([^ \f\t\n\r\v]+.*\\)"
|
||||
arg)
|
||||
(cons (intern (match-string 1 arg))
|
||||
(org-babel-read (org-babel-chomp (match-string 2 arg))))
|
||||
(cons (intern (concat ":" arg)) nil)))
|
||||
;; walk the list splitting on balanced instances of [ \t]:
|
||||
(let ((balance 0) (partial nil) (lst nil) (last 0))
|
||||
(mapc (lambda (ch)
|
||||
(setq balance (+ balance
|
||||
(cond ((equal 91 ch) 1)
|
||||
((equal 93 ch) -1)
|
||||
(t 0))))
|
||||
(setq partial (cons ch partial))
|
||||
(when (and (= ch 58) (= balance 0)
|
||||
(or (= last 32) (= last 9)))
|
||||
(setq lst (cons (apply #'string (nreverse (cddr partial)))
|
||||
lst))
|
||||
(setq partial (list ch)))
|
||||
(setq last ch))
|
||||
(string-to-list arg-string))
|
||||
(nreverse (cons (apply #'string (nreverse partial)) lst)))))))
|
||||
|
||||
(defun org-babel-process-params (params)
|
||||
"Expand variables in PARAMS and add summary parameters."
|
||||
@ -1598,7 +1615,7 @@ parameters when merging lists."
|
||||
(:tangle ;; take the latest -- always overwrite
|
||||
(setq tangle (or (list (cdr pair)) tangle)))
|
||||
(:noweb
|
||||
(setq noweb (e-merge '(("yes" "no")) noweb
|
||||
(setq noweb (e-merge '(("yes" "no" "tangle")) noweb
|
||||
(split-string (or (cdr pair) "")))))
|
||||
(:cache
|
||||
(setq cache (e-merge '(("yes" "no")) cache
|
||||
|
Loading…
Reference in New Issue
Block a user