--- tex-buf.el +++ tex-buf.el 2019-06-21 13:02:03.572805297 +0000 @@ -555,7 +555,6 @@ without further expansion." pos ;;FIXME: Should this be dynamically scoped? entry TeX-command-text TeX-command-pos (orig-file file) - (file #'TeX--master-or-region-file-with-extra-quotes) expansion-res case-fold-search string expansion arguments) (setq list (cons (list "%%" (lambda nil @@ -563,6 +562,17 @@ without further expansion." "%")) (or list (TeX-expand-list))) pat (regexp-opt (mapcar #'car list))) + ;; `TeX-command-expand' is called with `file' argument being one + ;; of `TeX-master-file', `TeX-region-file' and + ;; `TeX-active-master'. The return value of these functions + ;; sometimes needs suitable "decorations" for an argument for + ;; underlying shell or latex executable, or both, when the + ;; relavant file name involves some special characters such as + ;; space and multibyte characters. Hence embed that function in a + ;; template prepared for that purpose. + (setq file (apply-partially + #'TeX--master-or-region-file-with-extra-quotes + file)) (while (setq pos (string-match pat command pos)) (setq string (match-string 0 command) entry (assoc string list) @@ -594,24 +604,29 @@ without further expansion." command) (defun TeX--master-or-region-file-with-extra-quotes - (&optional extension nondirectory ask extra) + (file-fn &optional extension nondirectory ask extra) "Return file name with quote for shell. -Wrapper for `TeX-master-file' or `TeX-region-file' to be used in -`TeX-command-expand'. -It is assumed that `orig-file' has dynamic binding of the value of -`TeX-master-file' or `TeX-region-file'. Pass EXTENSION, NONDIRECTORY -and ASK to that function as-is, and arrange the returned file name for -use with command shell. -Enclose the file name with space within quotes `\"' first when -\" \\input\" is supplemented (indicated by dynamically binded -variable `TeX-command-text' having string value.) -Enclose the file name within \\detokenize{} when the following three +Helper function of `TeX-command-expand'. + +This is a kind of template. How to use: +Fix, by `apply-partially', the first argument FILE-FN as one of +the three functions `TeX-master-file', `TeX-region-file' or +`TeX-active-master'. Then the result is just a wrapper for that +function suitable in `TeX-command-expand'. + +As a wrapper described above, it passes EXTENSION, NONDIRECTORY +and ASK to the \"bare\" function as-is, and arranges the returned +file name for use with command shell. I.e. it encloses the file +name with space within quotes `\"' first when \" \\input\" is +supplemented (indicated by dynamically binded variable +`TeX-command-text' having string value.) It also encloses the +file name within \\detokenize{} when the following three conditions are met: 1. compiling with standard (pdf)LaTeX or upLaTeX 2. \" \\input\" is supplemented 3. EXTRA is non-nil. (default when expanding \"%T\")" (shell-quote-argument - (let* ((raw (funcall orig-file extension nondirectory ask)) + (let* ((raw (funcall file-fn extension nondirectory ask)) ;; String `TeX-command-text' means that the file name is ;; given through \input command. (quote-for-space (if (and (stringp TeX-command-text) @@ -2031,14 +2046,22 @@ command." (with-current-buffer TeX-command-buffer (TeX-process-buffer (TeX-active-master))))) -(defun TeX-active-master (&optional extension nondirectory) +(defun TeX-active-master (&optional extension nondirectory _ignore) "The master file currently being compiled. If optional argument EXTENSION is non-nil, add that file extension to the name. Special value t means use `TeX-default-extension'. If optional second argument NONDIRECTORY is non-nil, do not include -the directory." +the directory. + +The compatibility argument IGNORE is ignored." + ;; The third argument `_ignore' is kept for symmetry with + ;; `TeX-master-file's third argument `ask'. For example, it's used + ;; in `TeX--master-or-region-file-with-extra-quotes', where we don't + ;; know which function has to be called. Keep this in mind should + ;; you want to use another argument here. + ;; See also the similar comment in `TeX-region-file'. (if TeX-current-process-region-p (TeX-region-file extension nondirectory) (TeX-master-file extension nondirectory))) --- tex.el +++ tex.el 2019-06-21 12:58:20.442057420 +0000 @@ -545,7 +545,11 @@ string." (setq pos (+ pos (length TeX-command-text) 9)) (concat TeX-command-text " \"\\input\"")) ""))) - ("%T" TeX--master-or-region-file-with-extra-quotes t t nil t) + ;; The fourth argument of t is actually for wrapper function + ;; provided by `TeX--master-or-region-file-with-extra-quotes'. + ;; See its doc string as well as the comments in + ;; `TeX-command-expand'. + ("%T" file t t nil t) ("%n" TeX-current-line) ("%d" file "dvi" t) ("%f" file "ps" t)