Function: tex-compile-default
tex-compile-default is a byte-compiled function defined in
tex-mode.el.gz.
Signature
(tex-compile-default FSPEC)
Documentation
Guess a default command given the format-spec FSPEC.
Source Code
;; Defined in /usr/src/emacs/lisp/textmodes/tex-mode.el.gz
(defun tex-compile-default (fspec)
"Guess a default command given the `format-spec' FSPEC."
;; TODO: Learn to do latex+dvips!
(let ((cmds nil)
(unchanged-in nil))
;; Only consider active commands.
(dolist (cmd tex-compile-commands)
(when (tex-executable-exists-p (tex-command-executable cmd))
(if (tex-command-active-p cmd fspec)
(push cmd cmds)
(push (nth 1 cmd) unchanged-in))))
;; If no command seems to be applicable, arbitrarily pick the first one.
(setq cmds (if cmds (nreverse cmds) (list (car tex-compile-commands))))
;; Remove those commands whose input was considered stable for
;; some other command (typically if (t . "%.pdf") is inactive
;; then we're using pdflatex and the fact that the dvi file
;; is nonexistent doesn't matter).
(let ((tmp nil))
(dolist (cmd cmds)
(unless (member (nth 1 cmd) unchanged-in)
(push cmd tmp)))
;; Only remove if there's something left.
(if tmp (setq cmds (nreverse tmp))))
;; Remove commands whose input is not up-to-date either.
(let ((outs (delq nil (mapcar (lambda (x) (nth 2 x)) cmds)))
(tmp nil))
(dolist (cmd cmds)
(unless (member (nth 1 cmd) outs)
(push cmd tmp)))
;; Only remove if there's something left.
(if tmp (setq cmds (nreverse tmp))))
;; Select which file we're going to operate on (the latest).
(let ((latest (nth 1 (car cmds))))
(dolist (cmd (prog1 (cdr cmds) (setq cmds (list (car cmds)))))
(if (equal latest (nth 1 cmd))
(push cmd cmds)
(unless (eq latest t) ;Can't beat that!
(if (or (not (stringp latest))
(eq (nth 1 cmd) t)
(and (stringp (nth 1 cmd))
(file-newer-than-file-p
(format-spec (nth 1 cmd) fspec)
(format-spec latest fspec))))
(setq latest (nth 1 cmd) cmds (list cmd)))))))
;; Expand the command spec into the actual text.
(dolist (cmd (prog1 cmds (setq cmds nil)))
(push (cons (eval (car cmd) t) (cdr cmd)) cmds))
;; Select the favorite command from the history.
(let ((hist tex-compile-history)
re hist-cmd)
(while hist
(setq hist-cmd (pop hist))
(setq re (concat "\\`"
(regexp-quote (tex-command-executable hist-cmd))
"\\([ \t]\\|\\'\\)"))
(dolist (cmd cmds)
;; If the hist entry uses the same command and applies to a file
;; of the same type (e.g. `gv %r.pdf' vs `gv %r.ps'), select cmd.
(and (string-match re (car cmd))
(or (not (string-match "%[fr]\\([-._[:alnum:]]+\\)" (car cmd)))
(string-match (regexp-quote (match-string 1 (car cmd)))
hist-cmd))
(setq hist nil cmds (list cmd)))))
;; Substitute and return.
(if (and hist-cmd
(string-match (concat "[' \t\"]" (format-spec "%r" fspec)
"\\([;&' \t\"]\\|\\'\\)")
hist-cmd))
;; The history command was already applied to the same file,
;; so just reuse it.
hist-cmd
(if cmds (tex-format-cmd (caar cmds) fspec))))))