1

I'm on Org 9.3. I run the following test.

[OP@localhost bug1]$ ls
real.org  test.org

The contents of real.org are:

[OP@localhost bug1]$ cat real.org
#+PROPERTY: header-args :tangle yes

#+begin_src emacs-lisp
(setq count (+ 1 count))
#+end_src

The contents of test.org are:

[OP@localhost bug1]$ cat test.org
#+begin_src emacs-lisp
(setq count 0)
#+end_src

#+begin_src emacs-lisp 
(org-babel-load-file "real.org")
count
#+end_src

I then do:

[OP@localhost bug1]$ touch real.el

Now executing test.org, I get:

#+begin_src emacs-lisp
(setq count 0)
#+end_src

#+RESULTS:
: 0

#+begin_src emacs-lisp 
(org-babel-load-file "real.org")
count
#+end_src

#+RESULTS:
: 0

And the file real.el is still empty. I have two questions:

  • Why does this happen?
  • Is there a way to force .el file regeneration every time?

Some further observations:

  • If the org file being loaded (real.org in the above) is a symlink, the .el file is never regenerated.
  • If the org file being loaded is newer, even if the .el file exists, the .el file will be regenerated.
  • Finally, obviously if the .el file doesn't exist, it is created.
1

touch real.el generates an empty file (if the file does not exist already) and gives it the current time as its modification time, so it is newer than real.org. Since it is newer, it will not be regenerated: org-babel-load tangles only if the org file is newer[1].

So that gives you a few ways to ensure regeneration:

  • delete real.el every time.
  • touch real.org every time.
  • add or delete a character to real.org and save it every time.
  • open real.org, mark it modified with (set-buffer-modified-p t) and save it.

All of those make real.el either non-existent or older than real.org so it will be regenerated.

[1] Clicking on the link is supposed to take you to the definition of org-babel-load-file but it seems to take a while to do so: be patient (like wait-for-30-seconds patient). Not sure why it is so slow.

| improve this answer | |

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.