Function: TeX-tree-expand

TeX-tree-expand is a byte-compiled function defined in tex.el.

Signature

(TeX-tree-expand VARS PROGRAM &optional SUBDIRS)

Documentation

Return directories corresponding to the kpathsea variables VARS.

This is done calling kpsewhich --expand-path for the variables. PROGRAM if non-nil is passed as the parameter for --progname. Optional argument SUBDIRS are subdirectories which are appended to the directories of the TeX trees. Only existing directories are returned.

Source Code

;; Defined in ~/.emacs.d/elpa/auctex-14.1.2/tex.el
(defun TeX-tree-expand (vars program &optional subdirs)
  "Return directories corresponding to the kpathsea variables VARS.
This is done calling `kpsewhich --expand-path' for the variables.
PROGRAM if non-nil is passed as the parameter for --progname.
Optional argument SUBDIRS are subdirectories which are appended
to the directories of the TeX trees.  Only existing directories
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"
                   ,(mapconcat #'identity vars
                               TeX-kpathsea-path-delimiter)))
           (path-list (ignore-errors
                        (with-output-to-string
                          (setq exit-status
                                (apply #'call-process
                                       "kpsewhich" nil
                                       (list standard-output nil) nil
                                       args))))))
      (if (not (zerop exit-status))
          ;; kpsewhich is not available.  Disable subsequent usage.
          (setq TeX-kpathsea-path-delimiter nil)
        (let ((separators (format "[\n\r%s]" TeX-kpathsea-path-delimiter))
              path input-dir-list)
          (dolist (item (split-string path-list separators t))
            (if subdirs
                (dolist (subdir subdirs)
                  (setq path (file-name-as-directory (concat item subdir)))
                  (when (file-exists-p path)
                    (cl-pushnew path input-dir-list :test #'equal)))
              (setq path (file-name-as-directory item))
              (when (file-exists-p path)
                (cl-pushnew path input-dir-list :test #'equal))))
          ;; No duplication in result is assured since `cl-pushnew' is
          ;; used above.  Should we introduce an option for speed just
          ;; to accumulate all the results without care for
          ;; duplicates?
          (nreverse input-dir-list))))))