mirror of
https://git.savannah.gnu.org/git/emacs/org-mode.git
synced 2024-12-13 09:32:19 +00:00
lisp/org-macs.el: Restructure file outline, fixing compiler warning
Add new section "Misc", moving all the functions that do not belong to other sections below. This also fixes defun order for `org-compile-file' that needs `org-trim' to be defined.
This commit is contained in:
parent
5ed3e1dfc3
commit
a04e16bd11
181
lisp/org-macs.el
181
lisp/org-macs.el
@ -371,96 +371,6 @@ in target-prerequisite files relation."
|
||||
(let ((mtime (file-attribute-modification-time (file-attributes file))))
|
||||
(and mtime (or (not time) (time-less-p time mtime)))))
|
||||
|
||||
(defun org-compile-file (source process ext &optional err-msg log-buf spec)
|
||||
"Compile a SOURCE file using PROCESS.
|
||||
|
||||
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.
|
||||
|
||||
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)
|
||||
(ignore (defvar org-batch-test))
|
||||
;; Display logs when running tests.
|
||||
(when (bound-and-true-p org-batch-test)
|
||||
(message "org-compile-file log ::\n-----\n%s\n-----\n"
|
||||
(with-current-buffer log-buf (buffer-string))))
|
||||
(error
|
||||
(format
|
||||
"File %S wasn't produced%s"
|
||||
output
|
||||
(if (org-string-nw-p err-msg)
|
||||
(concat " " (org-trim err-msg))
|
||||
err-msg))))
|
||||
output))
|
||||
|
||||
(defun org-compile-file-commands (source process ext &optional spec err-msg)
|
||||
"Return list of commands used to compile SOURCE file.
|
||||
|
||||
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 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).
|
||||
|
||||
Throw an error if PROCESS does not satisfy the described patterns.
|
||||
The error string will be appended with ERR-MSG, when it is a string."
|
||||
(let* ((base-name (file-name-base source))
|
||||
(full-name (file-truename source))
|
||||
(relative-name (file-relative-name source))
|
||||
(out-dir (if (file-name-directory source)
|
||||
;; Expand "~". Shell expansion will be disabled
|
||||
;; in the shell command call.
|
||||
(file-name-directory full-name)
|
||||
"./"))
|
||||
(output (expand-file-name (concat (file-name-base source) "." ext) out-dir))
|
||||
(err-msg (if (stringp err-msg) (concat ". " err-msg) "")))
|
||||
(pcase process
|
||||
((pred functionp) (list process))
|
||||
((pred consp)
|
||||
(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))))))
|
||||
(mapcar (lambda (command) (format-spec command spec)) process)))
|
||||
(_ (error "No valid command to process %S%s" source err-msg)))))
|
||||
|
||||
|
||||
|
||||
;;; Indentation
|
||||
|
||||
@ -1648,6 +1558,9 @@ Return 0. if S is not recognized as a valid value."
|
||||
((string-match org-ts-regexp0 s) (org-2ft s))
|
||||
(t 0.)))))
|
||||
|
||||
|
||||
;;; Misc
|
||||
|
||||
(defun org-scroll (key &optional additional-keys)
|
||||
"Receive KEY and scroll the current window accordingly.
|
||||
When ADDITIONAL-KEYS is not nil, also include SPC and DEL in the
|
||||
@ -1701,6 +1614,94 @@ When COUNTER is non-nil, return safe hash for (COUNTER . OBJ)."
|
||||
(puthash hash obj org-sxhash-objects)
|
||||
(puthash obj hash org-sxhash-hashes)))))
|
||||
|
||||
(defun org-compile-file (source process ext &optional err-msg log-buf spec)
|
||||
"Compile a SOURCE file using PROCESS.
|
||||
|
||||
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.
|
||||
|
||||
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)
|
||||
(ignore (defvar org-batch-test))
|
||||
;; Display logs when running tests.
|
||||
(when (bound-and-true-p org-batch-test)
|
||||
(message "org-compile-file log ::\n-----\n%s\n-----\n"
|
||||
(with-current-buffer log-buf (buffer-string))))
|
||||
(error
|
||||
(format
|
||||
"File %S wasn't produced%s"
|
||||
output
|
||||
(if (org-string-nw-p err-msg)
|
||||
(concat " " (org-trim err-msg))
|
||||
err-msg))))
|
||||
output))
|
||||
|
||||
(defun org-compile-file-commands (source process ext &optional spec err-msg)
|
||||
"Return list of commands used to compile SOURCE file.
|
||||
|
||||
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 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).
|
||||
|
||||
Throw an error if PROCESS does not satisfy the described patterns.
|
||||
The error string will be appended with ERR-MSG, when it is a string."
|
||||
(let* ((base-name (file-name-base source))
|
||||
(full-name (file-truename source))
|
||||
(relative-name (file-relative-name source))
|
||||
(out-dir (if (file-name-directory source)
|
||||
;; Expand "~". Shell expansion will be disabled
|
||||
;; in the shell command call.
|
||||
(file-name-directory full-name)
|
||||
"./"))
|
||||
(output (expand-file-name (concat (file-name-base source) "." ext) out-dir))
|
||||
(err-msg (if (stringp err-msg) (concat ". " err-msg) "")))
|
||||
(pcase process
|
||||
((pred functionp) (list process))
|
||||
((pred consp)
|
||||
(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))))))
|
||||
(mapcar (lambda (command) (format-spec command spec)) process)))
|
||||
(_ (error "No valid command to process %S%s" source err-msg)))))
|
||||
|
||||
(provide 'org-macs)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user