From 0fba37a1a1cc1a53e1712fa81fa324865c2d22a5 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Thu, 1 Feb 2018 16:36:54 -0500 Subject: [PATCH] lang/org: refactor +export; improve central export logic Will use centralized export location only for exports that don't provide an explicit export location. --- modules/lang/org/+export.el | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/modules/lang/org/+export.el b/modules/lang/org/+export.el index dad8588c9..5b3b1637c 100644 --- a/modules/lang/org/+export.el +++ b/modules/lang/org/+export.el @@ -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))