Steal everything from ox-extra in org-contrib

This commit is contained in:
Gerard Vermeulen 2021-12-13 21:01:08 +01:00
parent 329ef63e16
commit 5085d5438b

View File

@ -824,14 +824,54 @@ Stolen from [[https://git.sr.ht/~bzg/org-contrib/tree/master/item/lisp/ox-extra.
#+begin_src emacs-lisp
(with-eval-after-load 'ox
(defun my-org-export-ignore-headline-filter (_)
"Ignore all headlines with the \":ignore:\" tag."
(org-map-entries
(lambda ()
(delete-region (point) (line-beginning-position 2)))
":ignore:"))
(defun org-export-ignore-headlines (data backend info)
"Remove headlines tagged \"ignore\" retaining contents and promoting children.
Each headline tagged \"ignore\" will be removed retaining its
contents and promoting any children headlines to the level of the
parent."
(org-element-map data 'headline
(lambda (object)
(when (member "ignore" (org-element-property :tags object))
(let ((level-top (org-element-property :level object))
level-diff)
(mapc (lambda (el)
;; recursively promote all nested headlines
(org-element-map el 'headline
(lambda (el)
(when (equal 'headline (org-element-type el))
(unless level-diff
(setq level-diff (- (org-element-property :level el)
level-top)))
(org-element-put-property
el :level (- (org-element-property :level el)
level-diff)))))
;; insert back into parse tree
(org-element-insert-before el object))
(org-element-contents object)))
(org-element-extract-element object)))
info nil)
(org-extra--merge-sections data backend info)
data)
(defun my-org-latex-header-blocks-filter (backend)
(defun org-extra--merge-sections (data _backend info)
(org-element-map data 'headline
(lambda (hl)
(let ((sections
(cl-loop
for el in (org-element-map (org-element-contents hl)
'(headline section) #'identity info)
until (eq (org-element-type el) 'headline)
collect el)))
(when (and sections
(> (length sections) 1))
(apply #'org-element-adopt-elements
(car sections)
(cl-mapcan (lambda (s) (org-element-contents s))
(cdr sections)))
(mapc #'org-element-extract-element (cdr sections)))))
info))
(defun org-latex-header-blocks-filter (backend)
"Convert marked LaTeX export blocks to \"#+latex_header: \" lines.
The marker is a line \"#+header: :header yes\" preceding the block.
@ -874,10 +914,12 @@ Stolen from [[https://git.sr.ht/~bzg/org-contrib/tree/master/item/lisp/ox-extra.
(defun my-activate-buffer-local-org-export-filters ()
"Activate my export filters locally in the current buffer."
(interactive)
(add-hook 'org-export-before-parsing-hook
#'my-org-export-ignore-headline-filter nil 'local)
(add-hook 'org-export-before-parsing-hook
#'my-org-latex-header-blocks-filter nil 'local)))
(set (make-local-variable 'org-export-filter-parse-tree-functions)
(cl-pushnew #'org-export-ignore-headlines
org-export-filter-parse-tree-functions))
(set (make-local-variable 'org-export-before-parsing-hook)
(cl-pushnew #'org-latex-header-blocks-filter
org-export-before-parsing-hook))))
#+end_src
#+name: emacs-lisp-setup