Przeglądaj źródła

DONE deeply nested arguments still fails

  added a function `org-babel-ref-split-args' for splitting arguments
  into top-level balanced expressions
Eric Schulte 16 lat temu
rodzic
commit
66faa937f8
2 zmienionych plików z 22 dodań i 4 usunięć
  1. 18 1
      lisp/org-babel-ref.el
  2. 4 3
      org-babel.org

+ 18 - 1
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

+ 4 - 3
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