- (when (null extensions)
- (setq extensions TeX-file-extensions))
- (when (null directories)
- (setq directories (cons "./" (append TeX-macro-private TeX-macro-global))))
- (let (match
- (TeX-file-recurse (cond ((symbolp TeX-file-recurse)
- TeX-file-recurse)
- ((zerop TeX-file-recurse)
- nil)
- ((1- TeX-file-recurse)))))
- (while directories
- (let* ((directory (car directories))
- (content (and directory
- (file-readable-p directory)
- (file-directory-p directory)
- (directory-files directory))))
- (setq directories (cdr directories))
- (while content
- (let ((file (concat directory (car content))))
- (setq content (cdr content))
- (cond ((string-match TeX-ignore-file file))
- ((not (file-readable-p file)))
- ((file-directory-p file)
- (if TeX-file-recurse
- (setq match
- (append match
- (TeX-search-files
- (list (file-name-as-directory file))
- extensions nodir strip)))))
- ((TeX-match-extension file extensions)
- (setq match (cons (TeX-strip-extension
- file extensions nodir (not strip))
- match))))))))
- match))
-
-;; The variables `TeX-macro-private' and `TeX-macro-global' are not
-;; used for specifying the directories because the number of
-;; directories to be searched should be limited as much as possible
-;; and the TeX-macro-* variables are just too broad for this.
-(defvar TeX-search-files-type-alist
- '((texinputs "${TEXINPUTS}" ("tex/") TeX-file-extensions)
- (docs "${TEXDOCS}" ("doc/") TeX-doc-extensions)
- (graphics "${TEXINPUTS}" ("tex/") LaTeX-includegraphics-extensions)
- (bibinputs "${BIBINPUTS}" ("bibtex/bib/") BibTeX-file-extensions)
- (bstinputs "${BSTINPUTS}" ("bibtex/bst/") BibTeX-style-extensions))
- "Alist of filetypes with locations and file extensions.
-Each element of the alist consists of a symbol expressing the
-filetype, a variable which can be expanded on kpathsea-based
-systems into the directories where files of the given type
-reside, a list of absolute directories, relative directories
-below the root of a TDS-compliant TeX tree or a list of variables
-with either type of directories as an alternative for
-non-kpathsea-based systems and a list of extensions to be matched
-upon a file search. Note that the directories have to end with a
-directory separator.
-
-Each AUCTeX mode should set the variable buffer-locally with a
-more specific value. See `LateX-search-files-type-alist' for an
-example.")
-
-(defun TeX-search-files-by-type (filetype &optional scope nodir strip)
- "Return a list of files in TeX's search path with type FILETYPE.
-FILETYPE is a symbol used to choose the search paths and
-extensions. See `TeX-search-file-type-alist' for supported
-symbols.
-
-The optional argument SCOPE sets the scope for the search.
-Besides nil the symbols `local' and `global' are accepted.
-`local' means to search in the current directory only, `global'
-in the global directories only and nil in both.
-
-If optional argument NODIR is non-nil, remove directory part.
-
-If optional argument STRIP is non-nil, remove file extension."
- (let* ((spec (assq filetype TeX-search-files-type-alist))
- (kpse-var (nth 1 spec))
- (rawdirs (nth 2 spec))
- (exts (nth 3 spec))
- expdirs dirs local-files)
- (setq exts (if (symbolp exts) (eval exts) exts))
- (or (TeX-search-files-kpathsea kpse-var exts scope nodir strip)
- (progn
- (unless (eq scope 'global)
- (setq local-files
- (let ((TeX-file-recurse nil))
- (TeX-search-files '("./") exts nodir strip))))
- (if (eq scope 'local)
- local-files
- (if (null TeX-tree-roots)
- (error "No TeX trees available; configure `TeX-tree-roots'")
- ;; Expand variables.
- (dolist (rawdir rawdirs)
- (if (symbolp rawdir)
- (setq expdirs (append expdirs (eval rawdir)))
- (add-to-list 'expdirs rawdir t)))
- (delete-dups expdirs)
- ;; Assumption: Either all paths are absolute or all are relative.
- (if (file-name-absolute-p (car expdirs))
- (setq dirs expdirs)
- ;; Append relative TDS subdirs to all TeX tree roots.
- (dolist (root TeX-tree-roots)
- (dolist (dir expdirs)
- (add-to-list 'dirs (concat (file-name-as-directory root)
- dir) t)))))
- (append local-files (TeX-search-files dirs exts nodir strip)))))))
-
-
-;;; Utilities
-;;
-;; Some of these functions has little to do with TeX, but nonetheless we
-;; should use the "TeX-" prefix to avoid name clashes.
+ (if (null extensions)
+ (setq extensions TeX-file-extensions))
+ (or (TeX-search-files-kpathsea extensions nodir strip)
+ (progn
+ (if (null directories)
+ (setq directories
+ (cons "./" (append TeX-macro-private TeX-macro-global))))
+ (let (match
+ (TeX-file-recurse (cond ((symbolp TeX-file-recurse)
+ TeX-file-recurse)
+ ((zerop TeX-file-recurse)
+ nil)
+ ((1- TeX-file-recurse)))))
+ (while directories
+ (let* ((directory (car directories))
+ (content (and directory
+ (file-readable-p directory)
+ (file-directory-p directory)
+ (directory-files directory))))
+ (setq directories (cdr directories))
+ (while content
+ (let ((file (concat directory (car content))))
+ (setq content (cdr content))
+ (cond ((string-match TeX-ignore-file file))
+ ((not (file-readable-p file)))
+ ((file-directory-p file)
+ (if TeX-file-recurse
+ (setq match
+ (append match
+ (TeX-search-files
+ (list (file-name-as-directory file))
+ extensions
+ nodir strip)))))
+ ((TeX-match-extension file extensions)
+ (setq match (cons (TeX-strip-extension file
+ extensions
+ nodir
+ (not strip))
+ match))))))))
+ match))))