Function: ffap-file-exists-string
ffap-file-exists-string is a byte-compiled function defined in
ffap.el.gz.
Signature
(ffap-file-exists-string FILE &optional NOMODIFY REMOTE-PREFIX)
Documentation
Return FILE (maybe modified) if the file exists, else nil.
When using jka-compr (a.k.a. auto-compression-mode(var)/auto-compression-mode(fun)), the returned
name may have a suffix added from ffap-compression-suffixes.
The optional NOMODIFY argument suppresses the extra search.
If the caller ensures that FILE is not remote, this function can accept
an optional argument, REMOTE-PREFIX. When REMOTE-PREFIX is non-nil (a
string typically returned by file-remote-p) and FILE is absolute,
check whether FILE exists on the remote system. If the file is present,
the returned name uses REMOTE-PREFIX as the prefix.
Source Code
;; Defined in /usr/src/emacs/lisp/ffap.el.gz
(defun ffap-file-exists-string (file &optional nomodify remote-prefix)
;; Early jka-compr versions modified file-exists-p to return the
;; filename, maybe modified by adding a suffix like ".gz". That
;; broke the interface of file-exists-p, so it was later dropped.
;; Here we document and simulate the old behavior.
"Return FILE (maybe modified) if the file exists, else nil.
When using jka-compr (a.k.a. `auto-compression-mode'), the returned
name may have a suffix added from `ffap-compression-suffixes'.
The optional NOMODIFY argument suppresses the extra search.
If the caller ensures that FILE is not remote, this function can accept
an optional argument, REMOTE-PREFIX. When REMOTE-PREFIX is non-nil (a
string typically returned by `file-remote-p') and FILE is absolute,
check whether FILE exists on the remote system. If the file is present,
the returned name uses REMOTE-PREFIX as the prefix."
(let ((non-essential t))
(cond
((zerop (length file)) nil) ; quietly reject nil and ""
((and remote-prefix ; prepend remote prefix to file
(file-name-absolute-p file)
(setq file (concat remote-prefix file))
nil))
((file-exists-p file) file)
;; three reasons to suppress search:
(nomodify nil)
((not (rassq 'jka-compr-handler file-name-handler-alist)) nil)
((member (file-name-extension file t) ffap-compression-suffixes) nil)
(t ; ok, do the search
(let ((list ffap-compression-suffixes) try ret)
(while list
(if (file-exists-p (setq try (concat file (car list))))
(setq ret try list nil)
(setq list (cdr list))))
ret)))))