Change file-exists-p! to return file if it exists
This commit is contained in:
parent
d94aa9b57c
commit
2d353b849c
|
@ -23,23 +23,27 @@
|
||||||
For example
|
For example
|
||||||
|
|
||||||
(doom--resolve-path-forms
|
(doom--resolve-path-forms
|
||||||
'(or \"some-file\" (and path-var \"/an/absolute/path\"))
|
'(or A (and B C))
|
||||||
\"~\")
|
\"~\")
|
||||||
|
|
||||||
Returns
|
Returns (approximately):
|
||||||
|
|
||||||
'(let ((_directory \"~\"))
|
'(let* ((_directory \"~\")
|
||||||
(or (file-exists-p (expand-file-name \"some-file\" _directory))
|
(A (expand-file-name A _directory))
|
||||||
(and (file-exists-p (expand-file-name path-var _directory))
|
(B (expand-file-name B _directory))
|
||||||
(file-exists-p \"/an/absolute/path\"))))
|
(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!'."
|
This is used by `associate!', `file-exists-p!' and `project-file-exists-p!'."
|
||||||
(declare (pure t) (side-effect-free t))
|
(declare (pure t) (side-effect-free t))
|
||||||
(cond ((stringp spec)
|
(cond ((stringp spec)
|
||||||
`(file-exists-p
|
`(let ((--file-- ,(if (file-name-absolute-p spec)
|
||||||
,(if (file-name-absolute-p spec)
|
|
||||||
spec
|
spec
|
||||||
`(expand-file-name ,spec ,directory))))
|
`(expand-file-name ,spec ,directory))))
|
||||||
|
(and (file-exists-p --file--)
|
||||||
|
--file--)))
|
||||||
((and (listp spec)
|
((and (listp spec)
|
||||||
(memq (car spec) '(or and)))
|
(memq (car spec) '(or and)))
|
||||||
`(,(car spec)
|
`(,(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))))
|
collect (doom--resolve-path-forms i directory))))
|
||||||
((or (symbolp spec)
|
((or (symbolp spec)
|
||||||
(listp spec))
|
(listp spec))
|
||||||
`(file-exists-p ,(if (and directory
|
`(let ((--file-- ,(if (and directory
|
||||||
(or (not (stringp directory))
|
(or (not (stringp directory))
|
||||||
(file-name-absolute-p directory)))
|
(file-name-absolute-p directory)))
|
||||||
`(expand-file-name ,spec ,directory)
|
`(expand-file-name ,spec ,directory)
|
||||||
spec)))
|
spec)))
|
||||||
(t spec)))
|
(and (file-exists-p --file--)
|
||||||
|
--file--)))
|
||||||
|
(spec)))
|
||||||
|
|
||||||
(defun doom--resolve-hook-forms (hooks)
|
(defun doom--resolve-hook-forms (hooks)
|
||||||
(declare (pure t) (side-effect-free t))
|
(declare (pure t) (side-effect-free t))
|
||||||
|
@ -400,16 +406,15 @@ The available conditions are:
|
||||||
mode modes match files when)))))
|
mode modes match files when)))))
|
||||||
|
|
||||||
(defmacro file-exists-p! (spec &optional directory)
|
(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
|
Returns the last file found to meet the rules set by SPEC. SPEC can be a single
|
||||||
...) and (or ...), as well.
|
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
|
DIRECTORY is where to look for the files in SPEC if they aren't absolute.
|
||||||
doesn't apply to variables, however.
|
|
||||||
|
|
||||||
For example:
|
For example:
|
||||||
|
|
||||||
(file-exists-p! (or doom-core-dir \"~/.config\" \"some-file\") \"~\")"
|
(file-exists-p! (or doom-core-dir \"~/.config\" \"some-file\") \"~\")"
|
||||||
(if directory
|
(if directory
|
||||||
`(let ((--directory-- ,directory))
|
`(let ((--directory-- ,directory))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user