Updating org-mode #+INCLUDE: statements on the fly26 Sep 2014, by Artur Malabarba.
Emacs.SE Lessons post series
#+INCLUDE: statements with line specifications in his
org files. Here is an example similar to his. 14 and 80 are the first
and last line of a class declaration in the source file, so they’re
quite obvious for a human to identify.
The problem here is that whenever “my-class.sv” is edited those line numbers are likely to become outdated. So you would have to go through each org file which might include “my-class.sv” and update the numbers.
Unfortunately, org-mode doesn’t have a flexible way of declaring include statements. You either specify the line numbers or you don’t.
The solution was to add
:range-end keywords to
and then write a function which
- goes through each
#+INCLUDE:statement in the buffer,
- checks if it has
:range-endkeywords and takes their arguments as regular expressions,
- visits the relevant file and searches for these regular expressions,
- checks what the line numbers are now,
- and updates them accordingly in the org buffer.
This function can then be assigned to a key, added to
before-save-hook, or added to one of org-mode’s bajillion available
hooks. Finally, to go the extra mile, we make the behaviour
customizable per file extension through a