0

The following code doesn't work, yet adding :tangle tangleobject.org manually to each source block provides us with the expected tangle result. Any clue why?

#+PROPERTY: header-args :tangle tangleobject.org

#+begin_src org
testing
#+end_src

#+begin_src org
testing2
#+end_src
3
  • Did you C-c C-c on the property line after adding it? Or killed the buffer and reopened the file? Or invoked M-x normal-mode? Or restarted Emacs? You need to somehow tell Org mode that you added something that might affect its future processing: the C-c C-c method (on any #+keyword line) is probably the easiest, but you have to remember to do it. See the third bullet in The very busy C-c C-c key or the second paragraph of Summary of in-buffer settings.
    – NickD
    Dec 6, 2023 at 0:43
  • @NickD thanks for your very instructive comment, I didn't know this was actually how Emacs functioned!
    – shintuku
    Dec 6, 2023 at 3:58
  • Related question: emacs.stackexchange.com/questions/69475/… - both the question and the answer mention the C-c C-c method. Not quite a duplicate but close.
    – NickD
    Dec 7, 2023 at 5:22

1 Answer 1

1

[Just to summarize my comments since I didn't quite succeed in finding a duplicate. This is a common question and I'm sure I've answered it before, but it may be that it's only been answered in comments. I looked for duplicates and found this question which mentions the solution but is a different question. If anybody finds a true duplicate, we can close this question and I'll delete this answer; otherwise I plan to use this answer as the ur-answer to mark any similar questions as duplicates.]

Adding a #+PROPERTY: line to an Org mode buffer is not enough to make Org mode recognize that it is there. Org mode only checks keyword lines (any lines that are of the form #+KEYWORD: ) when the file is opened (or more precisely, when the mode function, i.e. org-mode, is called, which happens when the file is opened). After that, it does not check again until the user tells it that it needs to (e.g. after adding a new keyword line). There are a couple of different ways to tell it; all basically call the mode function again:

  • you can do C-c C-c on any #+keyword line (usually, the one you just added is the most convenient, but any keyword line will do).

  • you can say M-x normal-mode - that is what find-file calls in the first place to set the mode of the new buffer.

  • you can save and kill the Org mode buffer and reopen the file.

In all these cases, the mode function gets executed again and so Org mode now knows about the new #+keyword line you added.

C-c C-c is probably the easiest method but you have to remember to do it.

It is documented in the Org mode manual in (at least) three places:

  • in section Setting up keywords for individual files - see footnote(1) at the bottom of the section:

Org mode parses these lines only when Org mode is activated after visiting a file. ‘C-c C-c’ with point in a line starting with ‘#+’ is simply restarting Org mode for the current buffer

If point is in one of the special ‘KEYWORD’ lines, scan the buffer for these lines and update the information.

‘C-c C-c’ activates any changes to the in-buffer settings. Closing and reopening the Org file in Emacs also activates the changes.

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.