[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/org b29f772416 10/14: org-macs: Split org-compile-file
From: |
ELPA Syncer |
Subject: |
[elpa] externals/org b29f772416 10/14: org-macs: Split org-compile-file into two funs |
Date: |
Sun, 22 Jan 2023 10:58:11 -0500 (EST) |
branch: externals/org
commit b29f77241681abd6fb12de3b7e26c009cb28c63d
Author: TEC <git@tecosaur.net>
Commit: Ihor Radchenko <yantar92@posteo.net>
org-macs: Split org-compile-file into two funs
* lisp/org-macs.el (org-compile-file, org-compile-file-commands):
Pull out the logic transforming process descriptions to commands to be
executed into a new function, `org-compile-file-commands'.
`org-compile-file' is now solely concerned with running the commands and
reporting the result.
---
lisp/org-macs.el | 74 ++++++++++++++++++++++++++++++++------------------------
1 file changed, 42 insertions(+), 32 deletions(-)
diff --git a/lisp/org-macs.el b/lisp/org-macs.el
index 07c668a807..cda9c5e034 100644
--- a/lisp/org-macs.el
+++ b/lisp/org-macs.el
@@ -345,31 +345,56 @@ in target-prerequisite files relation."
(defun org-compile-file (source process ext &optional err-msg log-buf spec)
"Compile a SOURCE file using PROCESS.
-PROCESS is either a function or a list of shell commands, as
-strings. EXT is a file extension, without the leading dot, as
-a string. It is used to check if the process actually succeeded.
+See `org-compile-file-commands' for information on PROCESS, EXT, and SPEC.
+If PROCESS fails, an error will be raised. The error message can
+then be refined by providing string ERR-MSG, which is appended to
+the standard message.
PROCESS must create a file with the same base name and directory
as SOURCE, but ending with EXT. The function then returns its
-filename. Otherwise, it raises an error. The error message can
-then be refined by providing string ERR-MSG, which is appended to
-the standard message.
+filename. Otherwise, it raises an error.
+
+When PROCESS is a list of commands, optional argument LOG-BUF can
+be set to a buffer or a buffer name. `shell-command' then uses
+it for output."
+ (let* ((commands (org-compile-file-commands source process ext spec err-msg))
+ (output (expand-file-name (concat (file-name-base source) "." ext)
+ (file-name-directory source)))
+ (log-buf (and log-buf (get-buffer-create log-buf)))
+ (time (file-attribute-modification-time (file-attributes output))))
+ (save-window-excursion
+ (dolist (command commands)
+ (cond
+ ((functionp command)
+ (funcall command (shell-quote-argument (file-relative-name source))))
+ ((stringp command) (shell-command command log-buf)))))
+ ;; Check for process failure. Output file is expected to be
+ ;; located in the same directory as SOURCE.
+ (unless (org-file-newer-than-p output time)
+ (error (format "File %S wasn't produced%s" output err-msg)))
+ output))
+
+(defun org-compile-file-commands (source process ext &optional spec err-msg)
+ "Create commands to compile SOURCE.
+
+The commands are formed from PROCESS, which is either a function or
+a list of shell commands, as strings. EXT is a file extension, without
+the leading dot, as a string. After PROCESS has been executed,
+a file with the same basename and directory as SOURCE but with the
+file extension EXT is expected to be produced.
+Failure to produce this file will be interpreted as PROCESS failing.
If PROCESS is a function, it is called with a single argument:
the SOURCE file.
-If it is a list of commands, each of them is called using
+If PROCESS is a list of commands, each of them is called using
`shell-command'. By default, in each command, %b, %f, %F, %o and
%O are replaced with, respectively, SOURCE base name, name, full
name, directory and absolute output file name. It is possible,
however, to use more place-holders by specifying them in optional
argument SPEC, as an alist following the pattern
- (CHARACTER . REPLACEMENT-STRING).
-
-When PROCESS is a list of commands, optional argument LOG-BUF can
-be set to a buffer or a buffer name. `shell-command' then uses
-it for output."
+ (CHARACTER . REPLACEMENT-STRING)."
(let* ((base-name (file-name-base source))
(full-name (file-truename source))
(relative-name (file-relative-name source))
@@ -378,34 +403,19 @@ it for output."
;; in the shell command call.
(file-name-directory full-name)
"./"))
- (output (expand-file-name (concat base-name "." ext) out-dir))
- (time (file-attribute-modification-time (file-attributes output)))
+ (output (expand-file-name (concat (file-name-base source) "." ext)
out-dir))
(err-msg (if (stringp err-msg) (concat ". " err-msg) "")))
- (save-window-excursion
(pcase process
- ((pred functionp) (funcall process (shell-quote-argument
relative-name)))
+ ((pred functionp) process)
((pred consp)
- (let ((log-buf (and log-buf (get-buffer-create log-buf)))
- (spec (append spec
+ (let ((spec (append spec
`((?b . ,(shell-quote-argument base-name))
(?f . ,(shell-quote-argument relative-name))
(?F . ,(shell-quote-argument full-name))
(?o . ,(shell-quote-argument out-dir))
(?O . ,(shell-quote-argument output))))))
- ;; Combine output of all commands in PROCESS.
- (with-current-buffer log-buf
- (let (buffer-read-only)
- (erase-buffer)))
- (let ((shell-command-dont-erase-buffer t))
- (dolist (command process)
- (shell-command (format-spec command spec) log-buf)))
- (when log-buf (with-current-buffer log-buf (compilation-mode)))))
- (_ (error "No valid command to process %S%s" source err-msg))))
- ;; Check for process failure. Output file is expected to be
- ;; located in the same directory as SOURCE.
- (unless (org-file-newer-than-p output time)
- (error (format "File %S wasn't produced%s" output err-msg)))
- output))
+ (mapcar (lambda (command) (format-spec command spec)) process)))
+ (_ (error "No valid command to process %S%s" source err-msg)))))
- [elpa] externals/org updated (b34bdc8719 -> f0dfbf0c39), ELPA Syncer, 2023/01/22
- [elpa] externals/org ddca762329 01/14: org-element--cache-verify-element: Format all the elements in warning, ELPA Syncer, 2023/01/22
- [elpa] externals/org 0af74d33a7 03/14: org-manual: Fix typos in print_bibliography kwd, ELPA Syncer, 2023/01/22
- [elpa] externals/org ffd832d5d6 06/14: org-manual: Update #+include block parsing, ELPA Syncer, 2023/01/22
- [elpa] externals/org e9c0696f79 08/14: org-persist: Inhibit fsync when writing cachefiles, ELPA Syncer, 2023/01/22
- [elpa] externals/org 4b546e04af 02/14: org-element--cache-submit-request: Ensure correct cache synchronization, ELPA Syncer, 2023/01/22
- [elpa] externals/org 7e649050c7 05/14: ox: Pass through unparsed #+include content, ELPA Syncer, 2023/01/22
- [elpa] externals/org c8f88589cb 09/14: org-persist: Set utf-8 coding when reading/writing, ELPA Syncer, 2023/01/22
- [elpa] externals/org b29f772416 10/14: org-macs: Split org-compile-file into two funs,
ELPA Syncer <=
- [elpa] externals/org f0dfbf0c39 14/14: ox-latex: Erase compile buffer at the start, ELPA Syncer, 2023/01/22
- [elpa] externals/org 5cde90e3c8 04/14: ox: Refactor org-export-expand-include-keyword, ELPA Syncer, 2023/01/22
- [elpa] externals/org 506989bed5 07/14: ox: Improve #+include parsing docstring, ELPA Syncer, 2023/01/22
- [elpa] externals/org b84018633e 13/14: ox-latex: Split org-latex-compile into two funs, ELPA Syncer, 2023/01/22
- [elpa] externals/org d0c87c762a 11/14: ox-latex: Do not hardcode fallback compiler, ELPA Syncer, 2023/01/22
- [elpa] externals/org 18d2f871c2 12/14: org: Split org-format-latex into two functions, ELPA Syncer, 2023/01/22