Function: locate-file
locate-file is a byte-compiled function defined in files.el.gz.
Signature
(locate-file FILENAME PATH &optional SUFFIXES PREDICATE)
Documentation
Search for FILENAME through PATH.
If found, return the absolute file name of FILENAME; otherwise
return nil.
PATH should be a list of directories to look in, like the lists in
exec-path(var)/exec-path(fun) or load-path.
If SUFFIXES is non-nil, it should be a list of suffixes to append to
file name when searching. If SUFFIXES is nil, it is equivalent to ("").
Use ("/") to disable PATH search, but still try the suffixes in SUFFIXES.
If non-nil, PREDICATE is used instead of file-readable-p.
This function will normally skip directories, so if you want it to find
directories, make sure the PREDICATE function returns dir-ok for them.
PREDICATE can also be an integer to pass to the access system call,
in which case file name handlers are ignored. This usage is deprecated.
For compatibility, PREDICATE can also be one of the symbols
executable, readable, writable, or exists, or a list of
one or more of those symbols.
Other relevant functions are documented in the file group.
Probably introduced at or before Emacs version 22.1.
Shortdoc
;; file
(locate-file "syslog" '("/var/log" "/usr/bin"))
e.g. => "/var/log/syslog"
Source Code
;; Defined in /usr/src/emacs/lisp/files.el.gz
(defun locate-file (filename path &optional suffixes predicate)
"Search for FILENAME through PATH.
If found, return the absolute file name of FILENAME; otherwise
return nil.
PATH should be a list of directories to look in, like the lists in
`exec-path' or `load-path'.
If SUFFIXES is non-nil, it should be a list of suffixes to append to
file name when searching. If SUFFIXES is nil, it is equivalent to (\"\").
Use (\"/\") to disable PATH search, but still try the suffixes in SUFFIXES.
If non-nil, PREDICATE is used instead of `file-readable-p'.
This function will normally skip directories, so if you want it to find
directories, make sure the PREDICATE function returns `dir-ok' for them.
PREDICATE can also be an integer to pass to the `access' system call,
in which case file name handlers are ignored. This usage is deprecated.
For compatibility, PREDICATE can also be one of the symbols
`executable', `readable', `writable', or `exists', or a list of
one or more of those symbols."
(if (and predicate (symbolp predicate) (not (functionp predicate)))
(setq predicate (list predicate)))
(when (and (consp predicate) (not (functionp predicate)))
(setq predicate
(logior (if (memq 'executable predicate) 1 0)
(if (memq 'writable predicate) 2 0)
(if (memq 'readable predicate) 4 0))))
(let ((file (locate-file-internal filename path suffixes predicate)))
(if (and file (string-match "\\.eln\\'" file))
(gethash (file-name-nondirectory file) comp-eln-to-el-h)
file)))