0

I have an org document with various source code blocks. Some of blocks should be evaluated conditionally on org-babel-execute-buffer; however, these blocks are scattered throughout the document, which means I'm not able to set :eval no under a single heading and call it a day.

I've attempted to do this via a property, but the following fails and both blocks are evaluated:

#+PROPERTY: maybe-eval no

#+BEGIN_SRC emacs-lisp :eval yes
(message "want this block evaluated")
#+END_SRC

#+BEGIN_SRC emacs-lisp :eval (org-entry-get nil "maybe-eval" t)
(message "don't want this block evaluated but to my chagrin it happens anyway")
#+END_SRC

Is it possible to use properties like this or is there another way to achieve the same behavior?

1 Answer 1

1

You have the wrong function: you want org-entry-get, not org-get-entry. Use C-h f <function name> to read about each one.

If I do M-x org-babel-execute-buffer on your example (after the correction), I get this:

#+PROPERTY: maybe-eval no

#+BEGIN_SRC emacs-lisp :eval yes
(message "want this block evaluated")
#+END_SRC

#+RESULTS:
: want this block evaluated

#+BEGIN_SRC emacs-lisp :eval (org-entry-get nil "maybe-eval" t)
(message "don't want this block evaluated but to my chagrin it happens anyway")
#+END_SRC

The second is not evaluated and I get a message in the echo area:

Evaluation of this emacs-lisp code block is disabled.

If you have just added the #+PROPERTY line in the buffer, the property is not known until you do one of three things:

  • press C-c C-c on the #+PROPERTY line (or any such keyword line)

  • do M-x normal-mode to reestablish the mode and activate all keyword lines

  • save and kill the buffer and reopen the file

This might be the reason that you thought that it didn't work. Also, be sure to delete old results before M-x org-babel-evaluate-buffer: they don't go away on reevaluation, so that might also fool you into thinking that it did not work.

2
  • 1
    The above was a typo (I'll change it), but I was calling the correct org-entry-get. The issue was that I hadn't C-c C-c on the property line to refresh the local setup. Oy. How is it I've been using org-mode this long and still make these silly mistakes. At any rate, hopefully someone can benefit from my foibles if they stumble on this post. Thanks so much! Commented Jun 12 at 3:26
  • Well, if it makes you feel better, I still do it too...
    – NickD
    Commented Jun 12 at 15:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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