3

In org mode, :var header arg definitions can actually call other SRC blocks, which is very nice! However I've run into a problem exemplified by the following org file:

#+NAME: add3
#+BEGIN_SRC elisp :var num=0
(+ 3 num)
#+END_SRC

* Use function drawer header arg
:PROPERTIES:
:header-args: :var n=add3(5)
:END:

#+NAME: whatIsN
#+BEGIN_SRC sh
echo $n
#+END_SRC

#+RESULTS: whatIsN
: 8

#+BEGIN_SRC sh :var a=whatIsN
echo $a
#+END_SRC

# !!!!ERROR!!!!: "variable binding depth exceeds max-specpdl-size"

This exact same example works fine if the :var for n is defined inline (instead of in the :PROPERTIES: drawer), like:

#+NAME: whatIsN
#+BEGIN_SRC sh :var n=add3(5)
echo $n
#+END_SRC

Anyone know what's causing org mode to stumble when the :var is defined in the :PROPERTIES: section?

org-version 9.1.11

  • 1
    There is some sort of infinite recursion going on. If you toggle-debug-on-error you'll see that org-babel get's stuck parsing the expression n=add3(5). – dangom Apr 25 '18 at 16:37
  • 1
    The problem is fixed in the current master of orgmode but not in the maint branch of orgmode. – Tobias Dec 4 '18 at 23:59
  • Did you test org-version 9.1.14? The problematic bit is still present in that branch of the org repository. (See the edit at the end of my answer.) I just did update and test. In spite of what Charles said: org 9.1.14 has the same problem. – Tobias Dec 5 '18 at 15:44
  • Yup, just tested 9.1.14 and the same error happens, as you say. – Chris Clark Dec 6 '18 at 0:45
  • I just tried this again in org mode 9.2.2 and it is indeed fixed. – Chris Clark Mar 12 '19 at 20:24
1

The problem is located in org-babel-get-src-block-info.

The function org-babel-params-from-properties is used there. Its doc-string is:

Retrieve parameters specified as properties. Return a list of association lists of source block params specified in the properties of the current outline entry.

But they do not say what the current outline entry is. In org-babel-get-src-block-info they assumed that the current outline entry would be that one at point but org-babel-params-from-properties uses also org-babel-current-src-block-location to retrieve parameters from there.

Even if (point) is 1 for the first source block add3 the variable org-babel-current-src-block-location in org-babel-params-from-properties points to the source block whatIsN.

So not the header-args for add3 are collected by org-babel-params-from-properties but those of whatIsN.

The consequence is that add3 gets the header arg n=add3(5) from the drawer. Naturally, that leads to infinite recursion.

The funny thing is that they already tried to make sure that org-babel-params-from-properties gets the right header args from the location of datum. I cite a small section of org-babel-get-src-block-info:

           ;; If DATUM is provided, make sure we get node
           ;; properties applicable to its location within
           ;; the document.
           (org-with-point-at (org-element-property :begin datum)
             (org-babel-params-from-properties lang))

You can avoid the error if you additionally let-bind org-babel-current-src-block-location to the location of datum:

           ;; If DATUM is provided, make sure we get node
           ;; properties applicable to its location within
           ;; the document.
           (let ((org-babel-current-src-block-location (org-element-property :begin datum)))
             (org-with-point-at org-babel-current-src-block-location
               (org-babel-params-from-properties lang)))

I am not sure about the full consequences of that change through.

Note that I sent a bug-report to emacs-orgmode@gnu.org.


EDIT: I already got a response on emacs-orgmode@gnu.org from Charles Berry. He wrote that he could not reproduce the problem on Orgmode 9.1.14.

I had a quick look at the current master of the orgmode repository. They fixed the bug by substituting the reference to org-babel-current-src-block-location with (point) in org-babel-params-from-properties.

Nevertheless, the problem is still present in the current maint branch of orgmode.

The problematic reference of org-babel-current-src-block-location within org-babel-params-from-properties is even present in the release_9.14 branch of orgmode. In spite of what Charles said.

  • This is fantastic! You are awesome Tobias. – Chris Clark Dec 5 '18 at 9:32

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.