Add +org-export-pre-hook to prepare the buffer before export

This commit is contained in:
Case Duckworth 2022-04-24 17:00:36 -05:00
parent 3219bf88cc
commit 3f925fc0e3
2 changed files with 35 additions and 2 deletions

View File

@ -796,7 +796,8 @@
org-attach-id-uuid-folder-format)))
(setup ox ; org-export
(:also-load ox-md)
(:also-load +ox
ox-md)
(:option org-export-coding-system 'utf-8-unix
org-export-headline-levels 8
org-export-with-drawers nil
@ -804,8 +805,11 @@
org-export-with-smart-quotes t
org-export-with-sub-superscripts t
org-export-with-toc nil)
(with-eval-after-load 'ox
(+org-export-pre-hooks-insinuate))
(add-hook '+org-export-pre-hook #'+flyspell-correct-buffer)
(with-eval-after-load 'user-save
(advice-add 'org-export-as :before #'user-save-run-hooks)))
(add-hook '+org-export-pre-hook #'user-save-run-hooks)))
(setup password-cache
(:option password-cache t

29
lisp/+ox.el Normal file
View File

@ -0,0 +1,29 @@
;;; +ox.el --- org-export helpers -*- lexical-binding: t; -*-
;;; Commentary:
;;; Code:
(require 'ox)
;;; Run hooks before doing any exporting at all
(defcustom +org-export-pre-hook nil
"Functions to run /before/ `org-export-as' does anything.
These will run on the buffer about to be exported, NOT a copy."
:type 'hook)
(defun +org-export-pre-run-hooks (&rest _)
"Run hooks in `+org-export-pre-hook'."
(run-hooks '+org-export-pre-hook))
(defun +org-export-pre-hooks-insinuate ()
"Advise `org-export-as' to run `+org-export-pre-hook'."
(advice-add 'org-export-as :before #'+org-export-pre-run-hooks))
(defun +org-export-pre-hooks-remove ()
"Remove pre-hook advice on `org-export-as'."
(advice-remove 'org-export-as #'+org-export-pre-run-hooks))
(provide '+ox)
;;; +ox.el ends here