diff -r afe6c433867e tex.el --- a/tex.el Thu Nov 30 23:21:22 2017 +0100 +++ b/tex.el Sun Dec 03 15:21:38 2017 +0900 @@ -2696,8 +2696,26 @@ (setq answers (cons entry answers)))) answers)) +(defun TeX-kpathsea-detect-path-delimiter () + "Auto detect the path delimiter for kpsewhich command. +Usually return \":\" or \";\". If auto detect fails for some reason, +return nil." + (let ((res (ignore-errors + (with-output-to-string + (call-process "kpsewhich" nil + (list standard-output nil) nil + "--expand-path" "{.,..}"))))) + ;; Kpsewhich expands "{.,..}" to ".:SOMEDIR" or ".;SOMEDIR" + ;; depending on its environment. + (and (stringp res) + ;; Check whether ; is contained. This should work even if + ;; some implemantation of kpsewhich considers it sane to + ;; insert drive letters or directory separators or whatever + ;; else to the current directory. + (if (string-match ";" res) ";" ":")))) + (defcustom TeX-kpathsea-path-delimiter - (if (memq system-type '(windows-nt cygwin)) t path-separator) + (TeX-kpathsea-detect-path-delimiter) "Path delimiter for kpathsea output. t means autodetect, nil means kpathsea is disabled." :group 'TeX-file @@ -2716,17 +2734,15 @@ ;; FIXME: The GNU convention only uses "path" to mean "list of directories" ;; and uses "filename" for the name of a file even if it contains possibly ;; several elements separated by "/". + (if (eq TeX-kpathsea-path-delimiter t) + (setq TeX-kpathsea-path-delimiter + (TeX-kpathsea-detect-path-delimiter))) (when TeX-kpathsea-path-delimiter (let* ((exit-status 1) (args `(,@(if program `("--progname" ,program)) "--expand-path" - ;; It seems that kpsewhich accepts semicolon as - ;; path delimiter even on non-w32 platform and - ;; converts it to colon if necessary. - ;; Quote from texmf.cnf of TeXLive 2017: - ;; "In this file, either ; or : can be used to - ;; separate path components." - ,(mapconcat #'identity vars ";"))) + ,(mapconcat #'identity vars + TeX-kpathsea-path-delimiter))) (path-list (ignore-errors (with-output-to-string (setq exit-status @@ -2737,34 +2753,8 @@ (if (not (zerop exit-status)) ;; kpsewhich is not available. Disable subsequent usage. (setq TeX-kpathsea-path-delimiter nil) - (let* ((delim - (cond - ;; If `TeX-kpathsea-path-delimiter' isn't t, use it - ;; for path delimiter. - ((not (eq TeX-kpathsea-path-delimiter t)) - TeX-kpathsea-path-delimiter) - ;; Otherwise, if the output begins with DOS drive - ;; letter or contains semicolon, we can set - ;; `TeX-kpathsea-path-delimiter' to ";" and use it - ;; for path delimiter. - ((string-match "^[A-Za-z]:\\|;" path-list) - (setq TeX-kpathsea-path-delimiter ";")) - ;; Otherwise, if the output contains colon, we can set - ;; `TeX-kpathsea-path-delimiter' to ":" and use it - ;; for path delimiter. - ((string-match ":" path-list) - (setq TeX-kpathsea-path-delimiter ":")) - ;; Otherwise, the output of this particular run - ;; happens to contain just one component (without any - ;; delimiter) of relative path (without DOS drive - ;; letter). - ;; It is safe to use ":" as delimiter for this case, - ;; but we cannot determine the value of - ;; `TeX-kpathsea-path-delimiter' now. - (t - ":"))) - (separators (format "[\n\r%s]" delim)) - path input-dir-list) + (let ((separators (format "[\n\r%s]" TeX-kpathsea-path-delimiter)) + path input-dir-list) (dolist (item (condition-case nil (split-string path-list separators t) ;; COMPATIBILITY for XEmacs <= 21.4.15