lang/org: refactor +export; improve central export logic

Will use centralized export location only for exports that don't provide
an explicit export location.
This commit is contained in:
Henrik Lissner 2018-02-01 16:36:54 -05:00
parent dadfeec506
commit 0fba37a1a1
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395

View file

@ -3,15 +3,14 @@
(add-hook 'org-load-hook #'+org|init-export)
;; I don't have any beef with org's built-in export system, but I do wish it
;; would export to a central directory, rather than `default-directory'. This is
;; because all my org files are usually in one place, and I want to be able to
;; refer back to old exports if needed.
;; would export to a central directory (by default), rather than
;; `default-directory'. This is because all my org files are usually in one
;; place, and I want to be able to refer back to old exports if needed.
(def-package! ox-pandoc
:defer t
:config
(when (executable-find "pandoc")
(push 'pandoc org-export-backends))
(push 'pandoc org-export-backends)
(setq org-pandoc-options
'((standalone . t)
(mathjax . t)
@ -19,20 +18,23 @@
;;
(defun +org|init-export ()
(add-transient-hook! #'org-export-dispatch (require 'ox-pandoc))
(setq org-export-backends '(ascii html latex md)
org-publish-timestamp-directory (concat doom-cache-dir "/org-timestamps/"))
(setq org-export-directory (expand-file-name ".export" +org-dir)
org-export-backends '(ascii html latex md)
org-export-with-toc t
org-export-with-author t)
(when (executable-find "pandoc")
(require 'ox-pandoc))
;; Always export to a central location
;; Export to a central location by default or if target isn't in `+org-dir'.
(setq org-export-directory (expand-file-name ".export" +org-dir))
(unless (file-directory-p org-export-directory)
(make-directory org-export-directory t))
(defun +org*export-output-file-name (args)
"Return a centralized export location."
(unless (nth 2 args)
"Return a centralized export location unless one is provided or the current
file isn't in `+org-dir'."
(when (and (not (nth 2 args))
buffer-file-name
(file-in-directory-p (file-truename buffer-file-name) (file-truename +org-dir)))
(setq args (append args (list org-export-directory))))
args)
(advice-add #'org-export-output-file-name
:filter-args #'+org*export-output-file-name))
(advice-add #'org-export-output-file-name :filter-args #'+org*export-output-file-name))