From 66faa937f894c32e562ad49d4e08695b61f22e9f Mon Sep 17 00:00:00 2001 From: Eric Schulte Date: Wed, 22 Jul 2009 16:04:19 -0600 Subject: [PATCH] DONE deeply nested arguments still fails added a function `org-babel-ref-split-args' for splitting arguments into top-level balanced expressions --- lisp/org-babel-ref.el | 19 ++++++++++++++++++- org-babel.org | 7 ++++--- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/lisp/org-babel-ref.el b/lisp/org-babel-ref.el index 8bf0814ac..b2f872222 100644 --- a/lisp/org-babel-ref.el +++ b/lisp/org-babel-ref.el @@ -100,7 +100,7 @@ return nil." (when (> (length new-refere) 0) (if (> (length new-referent) 0) (setq args (mapcar (lambda (ref) (cons :var ref)) - (split-string new-referent ",[ \f\t\n\r\v]*")))) + (org-babel-ref-split-args new-referent)))) (message "args=%S" args) (setq ref new-refere))) (when (string-match "\\(.+\\):\\(.+\\)" ref) @@ -143,6 +143,23 @@ return nil." (if (symbolp result) (format "%S" result) result)) ('lob (setq result (org-babel-execute-src-block t lob-info args))))))) +(defun org-babel-ref-split-args (arg-string) + "Split ARG-STRING into top-level arguments of balanced parenthesis." + (let ((index 0) (depth 0) (buffer "") holder return) + ;; crawl along string, splitting at any ","s which are on the top level + (while (< index (length arg-string)) + (setq holder (substring arg-string index (+ 1 index))) + (setq buffer (concat buffer holder)) + (setq index (+ 1 index)) + (cond + ((string= holder ",") + (when (= depth 0) + (setq return (reverse (cons (substring buffer 0 -1) return))) + (setq buffer ""))) + ((string= holder "(") (setq depth (+ 1 depth))) + ((string= holder ")") (setq depth (- 1 depth))))) + (reverse (cons buffer return)))) + (defun org-babel-ref-at-ref-p () "Return the type of reference located at point or nil if none of the supported reference types are found. Supported reference diff --git a/org-babel.org b/org-babel.org index ba082ce80..795e93189 100644 --- a/org-babel.org +++ b/org-babel.org @@ -2558,7 +2558,7 @@ arg #+resname: : 99 -*** TODO deeply nested arguments still fails +*** DONE deeply nested arguments still fails #+srcname: level-one-nesting #+begin_src python :var arg=adder(a=adder(a=one(),b=one()),b=adder(a=one(),b=one())) @@ -2566,7 +2566,7 @@ arg #+end_src #+resname: -: 99 +: 8 results in this error : supplied params=nil @@ -2581,7 +2581,8 @@ results in this error : reference 'one(' not found in this buffer Need to change the regexp in [[file:lisp/org-babel-ref.el::assign%20any%20arguments%20to%20pass%20to%20source%20block][org-babel-ref-resolve-reference]] so that -it only matches when the parenthesis are balanced. +it only matches when the parenthesis are balanced. Maybe look at +[[http://www.gnu.org/software/emacs/elisp/html_node/List-Motion.html][this]]. ** TODO allow srcname to omit function call parentheses Someone needs to revisit those regexps. Is there an argument for