0

I would like to execute emacs-lisp code at export time and that this code to be defined in another file (using SETUPFILE).

Let's consider this two simple files :

  • main.org
#+setupfile: setup.org

Something
  • setup.org
#+name: mycode
#+begin_src emacs-lisp :export results :eval yes :results silent
(message "DEBUG")
#+end_src

When I try to export main.org I thought that the DEBUG message should be printed in Emacs Messages which is not the case.

I thought that live code block were evaluated at export which, here, is not the case.

Am I doing something wrongly or did I miss something in the doc?

I am using Emacs 27.1 (from Debian bullseye) and org-mode 9.4 (from elpa).

Update: as stated by @NickD in his comment the word :results was misspelled in my example. Once corrected everything seems to work correctly when using #+INCLUDE: but still not working with #+SETUPFILE:.

8
  • You might want to use #+INCLUDE: rather than #+SETUPFILE: in this case.
    – NickD
    Commented Feb 15, 2023 at 9:15
  • I tried before posting the question but the result is exactly the same. Commented Feb 15, 2023 at 19:15
  • 1
    You might want to fix the code block header: it's :exports with an s, but :exports results and :results silent will cancel each other out and produce nothing (maybe last option wins but I have not tested). Try :exports code or :exports both and lose the :results silent if you want the results to be part of the exported output.
    – NickD
    Commented Feb 15, 2023 at 20:26
  • Thank's a lot! I effectively misspelled :exports. In my example :exports results and :result silent do not cancel each other since the code has the side effect of writing to the Messages buffer. Commented Feb 16, 2023 at 17:10
  • By "cancel each other out" I meant that nothing appears in the exported output.
    – NickD
    Commented Feb 16, 2023 at 21:05

1 Answer 1

2

A 2–minute peek at the source code (the function org--collect-keywords-1 in org.el) reveals that when it sees the SETUPFILE keyword, it opens the named file, searches for more keywords in that file, then throws the file away. It doesn’t import the whole file, plonk it in the middle of your org file, and then process all the source blocks in it; it just looks for keywords and nothing else.

You probably read between the lines of the manual and assumed more features than actually exist. The chapter 13.2 13.2 Export Settings of the Org Mode manual says that when there is a SETUPFILE keyword it looks in that file for more keywords. That’s it; that’s all it does. It doesn’t say that it does anything else with that file.

4
  • Well I read chapter 17.8 Summary of In-Buffer Settings where it is explicitly written that Org also parses and loads the document during normal exporting process. Org parses the contents of this document as if it was included in the buffer. It can be another Org file.. Did I understand it wrongly? Commented Feb 15, 2023 at 19:23
  • Huh, I missed that part of the documentation. I see no evidence that it’s true. There’s the code that makes C-c C-c open the file for you, and the code that reads settings from it, but nothing else. You might report that as a bug to the maintainers. They have a mailing list.
    – db48x
    Commented Feb 15, 2023 at 20:03
  • Please report that as a bug in the manual with M-x org-submit-bug-report.
    – NickD
    Commented Feb 17, 2023 at 4:56
  • 1
    Done. @yantar92 proposed a patch. Commented Feb 18, 2023 at 14:01

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.