Change file-exists-p! to return file if it exists

This commit is contained in:
Henrik Lissner 2019-03-06 17:39:46 -05:00
parent d94aa9b57c
commit 2d353b849c
No known key found for this signature in database
GPG Key ID: 5F6C0EA160557395

View File

@ -23,23 +23,27 @@
For example
(doom--resolve-path-forms
'(or \"some-file\" (and path-var \"/an/absolute/path\"))
'(or A (and B C))
\"~\")
Returns
Returns (approximately):
'(let ((_directory \"~\"))
(or (file-exists-p (expand-file-name \"some-file\" _directory))
(and (file-exists-p (expand-file-name path-var _directory))
(file-exists-p \"/an/absolute/path\"))))
'(let* ((_directory \"~\")
(A (expand-file-name A _directory))
(B (expand-file-name B _directory))
(C (expand-file-name C _directory)))
(or (and (file-exists-p A) A)
(and (if (file-exists-p B) B)
(if (file-exists-p C) C))))
This is used by `associate!', `file-exists-p!' and `project-file-exists-p!'."
(declare (pure t) (side-effect-free t))
(cond ((stringp spec)
`(file-exists-p
,(if (file-name-absolute-p spec)
`(let ((--file-- ,(if (file-name-absolute-p spec)
spec
`(expand-file-name ,spec ,directory))))
(and (file-exists-p --file--)
--file--)))
((and (listp spec)
(memq (car spec) '(or and)))
`(,(car spec)
@ -47,12 +51,14 @@ This is used by `associate!', `file-exists-p!' and `project-file-exists-p!'."
collect (doom--resolve-path-forms i directory))))
((or (symbolp spec)
(listp spec))
`(file-exists-p ,(if (and directory
`(let ((--file-- ,(if (and directory
(or (not (stringp directory))
(file-name-absolute-p directory)))
`(expand-file-name ,spec ,directory)
spec)))
(t spec)))
(and (file-exists-p --file--)
--file--)))
(spec)))
(defun doom--resolve-hook-forms (hooks)
(declare (pure t) (side-effect-free t))
@ -400,16 +406,15 @@ The available conditions are:
mode modes match files when)))))
(defmacro file-exists-p! (spec &optional directory)
"Returns t if the files in SPEC all exist.
"Returns non-nil if the files in SPEC all exist.
SPEC can be a single file or a list of forms/files. It understands nested (and
...) and (or ...), as well.
Returns the last file found to meet the rules set by SPEC. SPEC can be a single
file or a list of forms/files. It understands nested (and ...) and (or ...), as
well.
DIRECTORY is where to look for the files in SPEC if they aren't absolute. This
doesn't apply to variables, however.
DIRECTORY is where to look for the files in SPEC if they aren't absolute.
For example:
(file-exists-p! (or doom-core-dir \"~/.config\" \"some-file\") \"~\")"
(if directory
`(let ((--directory-- ,directory))