I have a large org file containing all my notes from a course at my university this semester. Each section contains two level-three headers called "Screenings" and "Readings". When calling org-export-to-pdf
, I'd like to filter out all these headings and promote the subheadings of these sections recursively (likely a recursive call to org-do-promote
).
While the org mode manual is typically an excellent resource for this kind of thing, I'm finding the Advanced Configuration section to be a little brief in detail for the young, blossoming org-mode user (aka me) to grasp fully. If the more experienced Emacs user could kindly guide me in the right direction for constructing this function, it would be much appreciated.
I've hacked something together using the documentation on org-map-entries
(Using the mapping API) and the hook example in the Advanced Configuration section of the manual.
(defun promote-screenings-and-readings (&optional backend)
(org-map-entries
(lambda ()
(let ((point (point))
(heading
(buffer-substring-no-properties
(point)
(save-excursion
(forward-line)
(point)))))
(when
(or
(string= heading "*** Screenings\n")
(string= heading "*** Readings\n"))
(org-map-entries
(lambda ()
(unless (= (point) point)
(org-promote)))
nil
'tree)
(forward-line)
(delete-region point (point)))))))
(add-hook 'org-export-before-parsing-hook 'promote-screenings-and-readings)
promote-screenings-and-readings
promotes all entries in the subtree except the root of the subtree and then deletes the heading. E.g running it on the file
* Foo
** Bar
*** Screenings
**** A
***** D
**** B
**** C
produces
* Foo
** Bar
*** A
**** D
*** B
*** C
Caveat: promote-screenings-and-readings
only removes the header, not content that is written under it, but before the first Screening or Reading. If you need that, simply return (point)
from the lambda and instead of forwarding the line, use the minimal point (if it exists).