1

I need to have automatic evaluation turned on for elisp (or emacs-lisp) because I have huge documents that I export to PDF with batch scripts, and it's intolerable to have to go in and manually evaluate elisp blocks. Here is an MVE:

Consider the following org-babel file

#+BEGIN_SRC elisp :exports both
(+ 1 41)
#+END_SRC

#+BEGIN_SRC python :exports both :results output
print 'only python, no lisp for y00'
#+END_SRC

I can evaluate either code block by placing point in them and typing C-c C-c. In each block, I get an interactive security question Evaluate this (elisp / python) code block on your system? Great, no problem. Doing that for both, I get

#+BEGIN_SRC elisp :exports both
(+ 1 41)
#+END_SRC

#+RESULTS:
: 42

#+BEGIN_SRC python :exports both :results output
print 'only python, no lisp for y00'
#+END_SRC

#+RESULTS:
: only python, no lisp for y00

Ok, I now remove the #+RESULTS blocks and type M-x org-babel-export-to-pdf. I only get the security question for the python block, and not for the elisp block. The PDF output only has the results for the python block and not for the elisp block.

Looks like some setting has auto-evaluation-on-export or some such turned off for elisp. Changing the code type to emacs-lisp for the elisp block does not fix it.

  • 1
    Your example doesn't reproduce here if I change elisp to emacs-lisp. Also I have org-confirm-babel-evaluate set to nil and emacs-lisp mentioned in org-babel-do-load-languages. – wvxvw Sep 22 '15 at 21:49
  • That was the answer (block type is emacs-lisp and emacs-lisp mentioned in org-babel-do-load-languages). The setting of org-confirm-babel-evaluate does not seem to matter. I had to do a restart of emacs to see it operate correctly. If you promote your comment to an answer, I will mark it so. – Reb.Cabin Sep 23 '15 at 16:10
1

After some investigation it seems like the condition for being able to evaluate the code block by pressing C-c C-c is that a function with the name org-babel-execute:<type> where <type> is the mode / language of the source block, be defined, while executing Babel source block during exporting will also look into the contents of org-babel-load-languages to decide whether to execute it. This is apart from the header arguments, which instruct Babel to take certain action during export.

In the OP's case, evaluation via C-c C-c works whether the header arguments specify language elisp or emacs-lisp, but evaluation via export only works if the header arguments specify language emacs-lisp, which alone matches the language specified in org-babel-load-languages. elisp is not recognized as a valid language for export purposes in org-babel-load-languages; specifying it there results in an error.

  • Confirmed that :exports should be either both or results for the emacs-lisp block. An elisp-block :exports none wont evaluate on export. A way to suppress output of results is with :exports results :results none; such a block will be evaluated on export. A nice thing to put in there is (setq org-confirm-babel-evaluate nil) if you trust all the remaining code in the document (that was my original use case because I have a lot of blocks and it's infeasible to manually confirm them all). – Reb.Cabin Sep 24 '15 at 1:54

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.