forked from mirrors/org-mode
ox-latex: Call compilation commands asynchronously
* lisp/ox-latex.el (org-latex-compile): Make use of the new `org-async-call' to call compilation commands asynchronously. When running ox-export via the command line, the expectation is the Emacs process will not exit until the export has completed. This assumption is violated with async export, so when the current Emacs session is `noninteractive' we go back to the previous (synchronously) method of compiling.
This commit is contained in:
parent
6b6aff2ef2
commit
72ba4116eb
|
@ -110,9 +110,9 @@
|
||||||
(?l "As LaTeX file" org-latex-export-to-latex)
|
(?l "As LaTeX file" org-latex-export-to-latex)
|
||||||
(?p "As PDF file" org-latex-export-to-pdf)
|
(?p "As PDF file" org-latex-export-to-pdf)
|
||||||
(?o "As PDF file and open"
|
(?o "As PDF file and open"
|
||||||
(lambda (a s v b)
|
(lambda (async subtreep visable-only body-only)
|
||||||
(if a (org-latex-export-to-pdf t s v b)
|
(if async (org-latex-export-to-pdf t subtreep visable-only body-only)
|
||||||
(org-open-file (org-latex-export-to-pdf nil s v b)))))))
|
(org-latex-export-to-pdf-and-open nil subtreep visable-only body-only))))))
|
||||||
:filters-alist '((:filter-options . org-latex-math-block-options-filter)
|
:filters-alist '((:filter-options . org-latex-math-block-options-filter)
|
||||||
(:filter-paragraph . org-latex-clean-invalid-line-breaks)
|
(:filter-paragraph . org-latex-clean-invalid-line-breaks)
|
||||||
(:filter-parse-tree org-latex-math-block-tree-filter
|
(:filter-parse-tree org-latex-math-block-tree-filter
|
||||||
|
@ -4452,13 +4452,21 @@ Return PDF file's name."
|
||||||
async subtreep visible-only body-only ext-plist
|
async subtreep visible-only body-only ext-plist
|
||||||
#'org-latex-compile)))
|
#'org-latex-compile)))
|
||||||
|
|
||||||
(defun org-latex-compile (texfile &optional snippet)
|
(defun org-latex-export-to-pdf-and-open (&optional async subtreep visible-only body-only ext-plist)
|
||||||
|
(let ((outfile (org-export-output-file-name ".tex" subtreep)))
|
||||||
|
(org-export-to-file 'latex outfile
|
||||||
|
async subtreep visible-only body-only ext-plist
|
||||||
|
(lambda (f) (org-latex-compile f nil t)))))
|
||||||
|
|
||||||
|
(defun org-latex-compile (texfile &optional snippet open-pdf)
|
||||||
"Compile a TeX file.
|
"Compile a TeX file.
|
||||||
|
|
||||||
TEXFILE is the name of the file being compiled. Processing is
|
TEXFILE is the name of the file being compiled. Processing is
|
||||||
done through the command specified in `org-latex-pdf-process',
|
done through the command specified in `org-latex-pdf-process',
|
||||||
which see. Output is redirected to \"*Org PDF LaTeX Output*\"
|
which see. Output is redirected to \"*Org PDF LaTeX Output*\"
|
||||||
buffer.
|
buffer. When the process is a shell command (and not a
|
||||||
|
function), it will be run asyncronously via `org-async-call',
|
||||||
|
unless the current session is `noninteractive'.
|
||||||
|
|
||||||
When optional argument SNIPPET is non-nil, TEXFILE is a temporary
|
When optional argument SNIPPET is non-nil, TEXFILE is a temporary
|
||||||
file used to preview a LaTeX snippet. In this case, do not
|
file used to preview a LaTeX snippet. In this case, do not
|
||||||
|
@ -4493,16 +4501,34 @@ produced."
|
||||||
(?L . ,(shell-quote-argument compiler))))
|
(?L . ,(shell-quote-argument compiler))))
|
||||||
(log-buf-name "*Org PDF LaTeX Output*")
|
(log-buf-name "*Org PDF LaTeX Output*")
|
||||||
(log-buf (and (not snippet) (get-buffer-create log-buf-name)))
|
(log-buf (and (not snippet) (get-buffer-create log-buf-name)))
|
||||||
outfile)
|
(outfile (expand-file-name (concat (file-name-base texfile) ".pdf")
|
||||||
;; Erase compile buffer at the start.
|
(file-name-directory texfile))))
|
||||||
(with-current-buffer log-buf
|
(with-current-buffer log-buf
|
||||||
(erase-buffer))
|
(erase-buffer))
|
||||||
(setq outfile
|
(if (or noninteractive (functionp process))
|
||||||
(org-compile-file
|
(progn
|
||||||
texfile process "pdf"
|
(org-compile-file texfile process "pdf"
|
||||||
(format "See %S for details" log-buf-name)
|
(format "See %S for details" log-buf-name)
|
||||||
log-buf spec))
|
log-buf spec)
|
||||||
(org-latex-compile--postprocess outfile log-buf snippet)
|
(and open-pdf (org-open-file outfile))
|
||||||
|
(org-latex-compile--postprocess outfile log-buf snippet))
|
||||||
|
(let ((failure-msg (format "File %S wasn't produced (exit code %%d). See %%s for details."
|
||||||
|
outfile))
|
||||||
|
async-call-spec)
|
||||||
|
(dolist (cmd (reverse (org-compile-file-commands
|
||||||
|
texfile process "pdf" spec)))
|
||||||
|
(setq async-call-spec
|
||||||
|
(list cmd
|
||||||
|
:buffer log-buf
|
||||||
|
:success
|
||||||
|
(or async-call-spec
|
||||||
|
(list (and open-pdf (lambda (_ _ _) (org-open-file outfile)))
|
||||||
|
(lambda (_ buf _)
|
||||||
|
(org-latex-compile--postprocess outfile buf snippet))))
|
||||||
|
:failure
|
||||||
|
failure-msg)))
|
||||||
|
(message "Compiling %s..." texfile)
|
||||||
|
(apply #'org-async-call async-call-spec)))
|
||||||
;; Return output file name.
|
;; Return output file name.
|
||||||
outfile))
|
outfile))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue