emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/auctex c27f60f 09/15: Fix auto detect of kpathsea delim


From: Tassilo Horn
Subject: [elpa] externals/auctex c27f60f 09/15: Fix auto detect of kpathsea delimeter
Date: Wed, 6 Dec 2017 09:48:34 -0500 (EST)

branch: externals/auctex
commit c27f60f4c69452bfc2752b47539938c9f1fea7b0
Author: Ikumi Keita <address@hidden>
Commit: Ikumi Keita <address@hidden>

    Fix auto detect of kpathsea delimeter
    
    * tex.el (TeX-kpathsea-detect-path-delimiter): New function.
    (TeX-kpathsea-path-delimiter): Use it to obtain the default value.
    (TeX-tree-expand): Use it to simplify auto detection method.
    Use `TeX-kpathsea-path-delimiter' for argument given to kpsewhich
    command.  Using constant ";" is completely wrong for most kpsewhich
    implementation.
---
 tex.el | 64 ++++++++++++++++++++++++++++------------------------------------
 1 file changed, 28 insertions(+), 36 deletions(-)

diff --git a/tex.el b/tex.el
index f4f1b2e..5ee02b4 100644
--- a/tex.el
+++ b/tex.el
@@ -2696,8 +2696,28 @@ If REGEXP is nil, or \"\", an error will occur."
          (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"
+    ;; according to its environment.
+    ;; Don't use "{.,.}" instead because kpsewhich of MiKTeX 2.9
+    ;; simplifies it to just a ".", not ".;.".
+    (and (stringp res) (> (length res) 0)
+        ;; Check whether ; is contained.  This should work even if
+        ;; some implementation 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 +2736,15 @@ are returned."
   ;; 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 +2755,8 @@ are returned."
       (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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]