From 796c6a55e2ece026a17268bd9a021895fa1be273 Mon Sep 17 00:00:00 2001 From: rasmus Date: Fri, 20 Feb 2015 12:56:06 +0100 Subject: [PATCH] ox.el: Introduce file-specific init-files. * ox.el (org-export-options-alist): Add :init-file. (org-export-async-start): Use :init-file. * ox-publish.el (org-publish) (org-publish-all) (org-publish-current-file): Use :init-file if noninteractive. * ox-icalendar.el (org-icalendar-export-agenda-files), (org-icalendar-combine-agenda-files): Use :init-file if noninteractive. Allows specifying a file-specific init-file via #+INIT. --- lisp/ox-icalendar.el | 4 ++-- lisp/ox-odt.el | 2 +- lisp/ox-publish.el | 6 +++--- lisp/ox.el | 18 +++++++++++------- 4 files changed, 17 insertions(+), 13 deletions(-) diff --git a/lisp/ox-icalendar.el b/lisp/ox-icalendar.el index b473f11..3a489f7 100644 --- a/lisp/ox-icalendar.el +++ b/lisp/ox-icalendar.el @@ -832,7 +832,7 @@ Return ICS file name." When optional argument ASYNC is non-nil, export happens in an external process." (interactive) - (if async + (if (or async noninteractive) ;; Asynchronous export is not interactive, so we will not call ;; `org-check-agenda-file'. Instead we remove any non-existent ;; agenda file from the list. @@ -870,7 +870,7 @@ the `org-export-stack' interface. The file is stored under the name chosen in `org-icalendar-combined-agenda-file'." (interactive) - (if async + (if (or async noninteractive) (let ((files (org-remove-if-not 'file-exists-p (org-agenda-files t)))) (org-export-async-start (lambda (dummy) diff --git a/lisp/ox-odt.el b/lisp/ox-odt.el index 4a94de1..a3fd43b 100644 --- a/lisp/ox-odt.el +++ b/lisp/ox-odt.el @@ -4232,7 +4232,7 @@ file-local settings. Return output file's name." (interactive) (let ((outfile (org-export-output-file-name ".odt" subtreep))) - (if async + (if (or async noninteractive) (org-export-async-start (lambda (f) (org-export-add-to-stack f 'odt)) `(expand-file-name (org-odt--export-wrap diff --git a/lisp/ox-publish.el b/lisp/ox-publish.el index d450c0e..c5b0a76 100644 --- a/lisp/ox-publish.el +++ b/lisp/ox-publish.el @@ -884,7 +884,7 @@ publishing will be done asynchronously, in another process." (assoc project org-publish-project-alist)))) (cond ((not project)) - (async + ((or async noninteractive) (org-export-async-start (lambda (results) nil) `(let ((org-publish-use-timestamps-flag ,(and (not force) org-publish-use-timestamps-flag))) @@ -905,7 +905,7 @@ directory and force publishing all projects. With a non-nil optional argument ASYNC, publishing will be done asynchronously, in another process." (interactive "P") - (if async + (if (or async noninteractive) (org-export-async-start (lambda (results) nil) `(progn (when ',force (org-publish-remove-all-timestamps)) @@ -927,7 +927,7 @@ optional argument ASYNC is non-nil, publishing will be done asynchronously, in another process." (interactive "P") (let ((file (buffer-file-name (buffer-base-buffer)))) - (if async + (if (or async noninteractive) (org-export-async-start (lambda (results) nil) `(let ((org-publish-use-timestamps-flag (if ',force nil ,org-publish-use-timestamps-flag))) diff --git a/lisp/ox.el b/lisp/ox.el index 6a16997..6cf728b 100644 --- a/lisp/ox.el +++ b/lisp/ox.el @@ -108,6 +108,7 @@ (:select-tags "SELECT_TAGS" nil org-export-select-tags split) (:exclude-tags "EXCLUDE_TAGS" nil org-export-exclude-tags split) (:creator "CREATOR" nil org-export-creator-string) + (:init-file "INIT" nil org-export-async-init-file t) (:headline-levels nil "H" org-export-headline-levels) (:preserve-breaks nil "\\n" org-export-preserve-breaks) (:section-numbers nil "num" org-export-with-section-numbers) @@ -859,7 +860,7 @@ automatically. But you can retrieve them with \\[org-export-stack]." :type 'boolean) (defcustom org-export-async-init-file nil - "File used to initialize external export process. + "File used to initialize external and batch export processes. Value must be either nil or an absolute file name. When nil, the external process is launched like a regular Emacs session, @@ -868,7 +869,9 @@ configuration. If a file is provided, it, and only it, is loaded at start-up. Therefore, using a specific configuration makes the process to -load faster and the export more portable." +load faster and the export more portable. + +In ox-publish projects the value :init-file takes precedence." :group 'org-export-general :version "24.4" :package-version '(Org . "8.0") @@ -5646,7 +5649,8 @@ and `org-export-to-file' for more specialized functions." ;; Sexp to evaluate in the buffer. (print (progn ,,@body)))))) ;; Start external process. - (let* ((process-connection-type nil) + (let* ((init (plist-get :init (org-export--get-inbuffer-options))) + (process-connection-type nil) (,proc-buffer (generate-new-buffer-name "*Org Export Process*")) (,process (apply @@ -5656,8 +5660,8 @@ and `org-export-to-file' for more specialized functions." ,proc-buffer (expand-file-name invocation-name invocation-directory) "--batch") - (if org-export-async-init-file - (list "-Q" "-l" org-export-async-init-file) + (if init + (list "-Q" "-l" init) (list "-l" user-init-file)) (list "-l" ,temp-file))))) ;; Register running process in stack. @@ -5724,7 +5728,7 @@ use it to set a major mode there, e.g, This function returns BUFFER." (declare (indent 2)) - (if async + (if (or async noninteractive) (org-export-async-start `(lambda (output) (with-current-buffer (get-buffer-create ,buffer) @@ -5790,7 +5794,7 @@ or FILE." (if (not (file-writable-p file)) (error "Output file not writable") (let ((ext-plist (org-combine-plists `(:output-file ,file) ext-plist)) (encoding (or org-export-coding-system buffer-file-coding-system))) - (if async + (if (or async noninteractive) (org-export-async-start `(lambda (file) (org-export-add-to-stack (expand-file-name file) ',backend)) -- 2.3.0