Sfoglia il codice sorgente

DONE One supplied, one default

  We are now skipping results lines when resolving references which
  specify arguments, as the arguments would change the value of the
  source-code block.
Eric Schulte 17 anni fa
parent
commit
fe0532e509
3 ha cambiato i file con 25 aggiunte e 11 eliminazioni
  1. 8 6
      lisp/org-babel-ref.el
  2. 2 1
      lisp/org-babel.el
  3. 15 4
      org-babel.org

+ 8 - 6
lisp/org-babel-ref.el

@@ -96,12 +96,12 @@ return nil."
       (when (string-match "^\\(.+?\\)\(\\(.*\\)\)$" ref)
         (setq new-refere (match-string 1 ref))
         (setq new-referent (match-string 2 ref))
-        (message (format "first second %S -- %S" new-refere new-referent)) ;; debugging
+        (message "new-refere=%S, new-referent=%S" new-refere new-referent) ;; debugging
         (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]*"))))
-          (message "nested args = %S" args)
+          (message "args=%S" args)
           (setq ref new-refere)))
       (when (string-match "\\(.+\\):\\(.+\\)" ref)
         (find-file (match-string 1 ref))
@@ -111,8 +111,10 @@ return nil."
                                        (regexp-quote ref) "[ \t]*$"))
                 (regexp (concat "^#\\+SRCNAME:[ \t]*"
                                 (regexp-quote ref) "\\(\(.*\)\\)?" "[ \t]*$")))
-            (or (re-search-forward result_regexp nil t)
-                (re-search-forward result_regexp nil t)
+            ;; goto ref in the current buffer
+            (or (and (not args)
+                     (or (re-search-forward result_regexp nil t)
+                         (re-search-forward result_regexp nil t)))
                 (re-search-forward regexp nil t)
                 (re-search-backward regexp nil t)
                 ;; check the Library of Babel
@@ -132,12 +134,12 @@ return nil."
           (beginning-of-line)
           (if (or (= (point) (point-min)) (= (point) (point-max)))
               (error "reference not found"))))
+      (message "type=%S" type) ;; debugging
       (case type
         ('results-line (org-babel-ref-read-result))
         ('table (org-babel-ref-read-table))
         ('source-block
-         (setq result (org-babel-execute-src-block
-                       t nil (org-combine-plists args nil)))
+         (setq result (org-babel-execute-src-block t nil args))
          (if (symbolp result) (format "%S" result) result))
         ('lob (setq result (org-babel-execute-src-block t lob-info args)))))))
 

+ 2 - 1
lisp/org-babel.el

@@ -159,6 +159,7 @@ Optionally supply a value for INFO in the form returned by
 Optionally supply a value for PARAMS which will be merged with
 the header arguments specified at the source code block."
   (interactive)
+  (message "supplied params=%S" params)
   (let* ((info (or info (org-babel-get-src-block-info)))
          (lang (first info))
          (body (second info))
@@ -169,7 +170,7 @@ the header arguments specified at the source code block."
 	 (result-type (fourth processed-params))
          (cmd (intern (concat "org-babel-execute:" lang)))
          result)
-    ;; (message "params=%S" params) ;; debugging statement
+    (message "params=%S" params) ;; debugging statement
     (unless (member lang org-babel-interpreters)
       (error "Language is not in `org-babel-interpreters': %s" lang))
     (when arg (setq result-params (cons "silent" result-params)))

+ 15 - 4
org-babel.org

@@ -2357,7 +2357,7 @@ plot data using 1:2 with lines
               node.name += c
 #+end_src
     
-*** discussion
+*** discussion / investigation
 I believe that this issue should be addressed as a bug rather than as
 a point for new development.   The code in [[file:lisp/org-babel-ref.el][org-babel-ref.el]] already
 resolves variable references in a recursive manner which *should* work
@@ -2378,6 +2378,17 @@ resolution of nested arguments.  We should capture this functionality
 in a test to ensure that we continue to test it as we move forward.  I
 can take a look at implementing this once I get a chance.
 
+Looks like the problem may be in [[file:lisp/org-babel.el::defun%20org%20babel%20merge%20params%20rest%20plists][org-babel-merge-params]], which seems
+to be trampling the provided :vars values.
+
+Nope, now it seems that we are actually looking up the results line,
+rather than the actual source-code block, which would make sense given
+that the results-line will return the same value regardless of the
+arguments supplied.  See the output of this [[file:lisp/org-babel-ref.el::message%20type%20S%20type%20debugging][debug-statement]].
+
+We need to be sure that we don't read from a =#+resname:= line when we
+have a non-nil set of arguments.
+
 **** demonstration
 After uncommenting the debugging statements located [[file:lisp/org-babel-ref.el::message%20format%20first%20second%20S%20S%20new%20refere%20new%20referent%20debugging][here]] and more
 importantly [[file:lisp/org-babel-ref.el::message%20nested%20args%20S%20args%20debugging][here]], we can see that the current reference code does
@@ -2448,18 +2459,18 @@ a+b
 
         updated [[file:lisp/org-babel-lob.el::defvar%20org%20babel%20lob%20one%20liner%20regexp%20lob%20t%20n%20n%20t%20n][org-babel-lob-one-liner-regexp]]
 
-****** TODO One supplied, one default
+****** DONE One supplied, one default
 #+lob: adder1(a=0)
 
 #+resname: adder1(a=0)
-: 30
 ## should be 10
+: 20
 
 #+lob: adder1(b=0)
 
 #+resname: adder1(b=0)
-: 30
 ## should be 10
+: 10
 
 ****** TODO Both supplied
 #+lob: adder1(a=1,b=2)