Kaushalmodi uses #+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.
The Solution
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-begin and :range-end keywords to
the statement
and then write a function which
goes through each #+INCLUDE: statement in the buffer,
checks if it has :range-begin and/or :range-end keywords 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 defcustom.
Updating org-mode #+INCLUDE: statements on the fly
26 Sep 2014, by Artur Malabarba.Emacs.SE Lessons post series
Today’s post regards my answer to kaushalmodi's question. Since the beta is still private, you might not be able to follow those links quite yet, so I’ll summ it up here.
The Question
Kaushalmodi uses
#+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.
The Solution
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-begin
and:range-end
keywords to the statementand then write a function which
#+INCLUDE:
statement in the buffer,:range-begin
and/or:range-end
keywords and takes their arguments as regular expressions,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 adefcustom
.Tags: org-mode, emacs,
Aggressive Auto-indentation »
« Auto-focus a Relevant File in Dired Buffers
Related Posts
Define context-aware keys in Emacs in org-mode
Changing the org-mode ellipsis in org-mode
Better time-stamps in org-export in org-mode
Content © 2019, All rights reserved. Icons under CC3.0.