1

After upgrade org mode version to 9, the babel variable params is void.

Below example works fine in org 8 version:

#+BEGIN_SRC emacs-lisp :results output
(print params)
#+END_SRC

#+RESULTS:
: 
: ((:comments . "") (:shebang . "") (:cache . "no") (:padline . "") (:noweb . "no") (:tangle . "no") (:exports . "code") (:results . "replace output") (:session . "none") (:hlines . "yes") (:colnames . "no") (:result-type . output) (:result-params "output" "replace") (:rowname-names) (:colname-names))

But if we run the same code in org 9.0.5, I got below error message:

let: Symbol’s value as variable is void: params

Is it changed to another name?

1

The variable is now called org-babel-default-header-args. There are also similar variables for each language supported by babel. I don't remember what params meant in older versions, however, so I'm not sure if this is an exact replacement.

BTW, C-h-v org-babel- TAB is a nice way to find out all the variables whose names have the prefix org-babel-. And one thing that org 9.x has going for it is that it has much more predictable names for variables and functions in general.

EDIT: I read your comment and took a look through the code: I don't think that what you want can be done with unmodified org-mode. I was only able to do it by adding a (dynamically bound) variable and assigning to it the (internal) value of params just before the block was executed. Obviously, that invalidates your warranty :-). Here's the diff:

diff --git a/lisp/ob-core.el b/lisp/ob-core.el
index 9f67000..dfcc7a9 100644
--- a/lisp/ob-core.el
+++ b/lisp/ob-core.el
@@ -628,6 +628,8 @@ a list with the following pattern:
    (setf (nth 2 info) (org-babel-generate-file-param name (nth 2 info)))
    info))))

+(defvar org-babel-params)
+
 ;;;###autoload
 (defun org-babel-execute-src-block (&optional arg info params)
   "Execute the current source code block.
@@ -696,6 +698,7 @@ block."
         (capitalize lang)
         (let ((name (nth 4 info)))
           (if name (format " (%s)" name) "")))
+       (setq org-babel-params params)
    (if (member "none" result-params)
        (progn (funcall cmd body params)
           (message "result silenced"))

The source block would be modified to print org-babel-params.

11
  • Thanks, this is the default ones, but I wish to get the merged list with user defined list (e.g. :results output above). I see a function org-babel-merge-params in ob-core.el but not sure if I can call it.
    – lucky1928
    Apr 6 '17 at 13:03
  • You can call it but the problem is with what args? Both info and params are only known internally. I edited my answer to "externalize" the value of params (after it is set to its final value), but it requires changes to the code.
    – NickD
    Apr 7 '17 at 1:46
  • Cool, I have updated my ob-core at ~/.emacs.d/elpa/org-plus-contrib-20170210, but it didn't take effect. Any special steps need to be done?
    – lucky1928
    Apr 7 '17 at 2:47
  • Just googled and run the compile command from emacs, now change works for my test example above. Really cool.But I still fail to run the example from orgmode.org/worg/org-tutorials/org-dot-diagrams.html. So that means call org-babel-execute:dot from elisp code doesn't work on org 9 now! Wish it can be fixed in later release.
    – lucky1928
    Apr 7 '17 at 2:52
  • That's because org-babel-execute:dot returns nil , but the code block is run by org-babel-execute:emacs-lisp which turns it into the string "nil". org-babel-execute:dot expects the caller to interpret that as "I've already written the file, so you shouldn't bother" but org-babel-execute-src-block does not know that (it does not get nil back, it gets the string "nil") and proceeds to write the file with "nil" in it. You might want to post this on the org-mode mailing list and point back here for context.
    – NickD
    Apr 7 '17 at 3:55
3

Call function org-babel-get-src-block-info and access the 3rd element instead.

#+NAME: nodes
| From | To | Weight |
|------+----+--------|
| A    | B  |      3 |
| A    | C  |      2 |
| B    | D  |      4 |
| B    | E  |      5 |
| C    | F  |     10 |

#+BEGIN_SRC elisp :imagename test.png :results output raw :var nodes=nodes
  (defun rowfun(x)
    (format "%s -> %s [label=%s];" (nth 0 x) (nth 1 x) (nth 2 x)))
  (defun dotgen(nodes)
    (let ((dotbegin "digraph {\nnode [shape=circle]\n")
          (dotend "\n}"))
      (concat dotbegin
              (mapconcat #'rowfun nodes "\n")
              dotend)))
  (let* ((params (nth 2 (org-babel-get-src-block-info)))
         (imagename (cdr (assq :imagename params))))
    (assq-delete-all :imagename params)
    (push `(:file . ,imagename) params)
    (org-babel-execute:dot (dotgen nodes) params) 
    (princ (format "[[./%s]]" imagename)))
#+END_SRC

#+RESULTS:
[[./test.png]]

Output:

enter image description here

Another more generic solution is using two src block, one for elisp to generate the dot description; the other one is the dot src block with the elisp src as input var.

#+NAME: nodes
| From | To | Weight |
|------+----+--------|
| A    | B  |     13 |
| A    | C  |      2 |
| B    | D  |      4 |
| B    | E  |      5 |
| C    | F  |     10 |

#+NAME: elisp-src
#+BEGIN_SRC elisp :var nodes=nodes
  (defun rowfun(x)
    (format "%s -> %s [label=%s];" (nth 0 x) (nth 1 x) (nth 2 x)))
  (defun dotgen(nodes)
    (let ((dotbegin "digraph {\nnode [shape=circle]\n")
          (dotend "\n}"))
      (concat dotbegin
              (mapconcat #'rowfun nodes "\n")
              dotend)))
  (dotgen nodes)
#+END_SRC

#+BEGIN_SRC dot :file dot.png :var dotdesc=elisp-src
$dotdesc
#+END_SRC

#+RESULTS:
[[file:dot.png]]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.