Function: org-compile-file-commands

org-compile-file-commands is a byte-compiled function defined in org-macs.el.

Signature

(org-compile-file-commands SOURCE PROCESS EXT &optional SPEC ERR-MSG)

Documentation

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, relative
file name, absolute file name, relative 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.

Source Code

;; Defined in ~/.emacs.d/elpa/org-9.8.2/org-macs.el
(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, relative
file name, absolute file name, relative 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* ((basename (file-name-base source))
         ;; Resolve symlinks in default-directory to correctly handle
         ;; absolute source paths or relative paths with ..
         (pwd (file-truename default-directory))
         (absname (expand-file-name source pwd))
         (relname (if (file-name-absolute-p source)
                        (file-relative-name source pwd)
                      source))
	 (relpath (or (file-name-directory relname) "./"))
	 (output (concat (file-name-sans-extension absname) "." ext))
	 (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 basename))
			     (?f . ,(shell-quote-argument relname))
			     (?F . ,(shell-quote-argument absname))
			     (?o . ,(shell-quote-argument relpath))
			     (?O . ,(shell-quote-argument output))))))
         (mapcar (lambda (command) (format-spec command spec)) process)))
      (_ (error "No valid command to process %S%s" source err-msg)))))