Optimize file-exists-p! & project-file-exists-p!
This commit is contained in:
parent
e13ccf3e08
commit
52a04fd8c6
2 changed files with 13 additions and 7 deletions
|
@ -30,9 +30,10 @@ For example
|
||||||
|
|
||||||
Returns
|
Returns
|
||||||
|
|
||||||
'(or (file-exists-p (expand-file-name \"some-file\" \"~\"))
|
'(let ((_directory \"~\"))
|
||||||
(and (file-exists-p (expand-file-name path-var \"~\"))
|
(or (file-exists-p (expand-file-name \"some-file\" _directory))
|
||||||
(file-exists-p \"/an/absolute/path\")))
|
(and (file-exists-p (expand-file-name path-var _directory))
|
||||||
|
(file-exists-p \"/an/absolute/path\"))))
|
||||||
|
|
||||||
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!'."
|
||||||
(cond ((stringp spec)
|
(cond ((stringp spec)
|
||||||
|
@ -41,7 +42,9 @@ This is used by `associate!', `file-exists-p!' and `project-file-exists-p!'."
|
||||||
spec
|
spec
|
||||||
`(expand-file-name ,spec ,directory))))
|
`(expand-file-name ,spec ,directory))))
|
||||||
((symbolp spec)
|
((symbolp spec)
|
||||||
`(file-exists-p ,(if directory
|
`(file-exists-p ,(if (and directory
|
||||||
|
(or (not (stringp directory))
|
||||||
|
(file-name-absolute-p directory)))
|
||||||
`(expand-file-name ,spec ,directory)
|
`(expand-file-name ,spec ,directory)
|
||||||
path)))
|
path)))
|
||||||
((and (listp spec)
|
((and (listp spec)
|
||||||
|
@ -385,8 +388,11 @@ 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\") \"~\")"
|
||||||
(doom--resolve-path-forms spec directory))
|
(if directory
|
||||||
|
`(let ((_directory ,directory))
|
||||||
|
,(doom--resolve-path-forms spec '_directory))
|
||||||
|
(doom--resolve-path-forms spec)))
|
||||||
|
|
||||||
(defmacro define-key! (keymaps key def &rest rest)
|
(defmacro define-key! (keymaps key def &rest rest)
|
||||||
"Like `define-key', but accepts a variable number of KEYMAPS and/or KEY+DEFs.
|
"Like `define-key', but accepts a variable number of KEYMAPS and/or KEY+DEFs.
|
||||||
|
|
|
@ -99,7 +99,7 @@ If NOCACHE, don't fetch a cached answer."
|
||||||
Paths are relative to the project root, unless they start with ./ or ../ (in
|
Paths are relative to the project root, unless they start with ./ or ../ (in
|
||||||
which case they're relative to `default-directory'). If they start with a slash,
|
which case they're relative to `default-directory'). If they start with a slash,
|
||||||
they are absolute."
|
they are absolute."
|
||||||
(doom--resolve-path-forms files '(doom-project-root)))
|
`(file-exists-p! ,files (doom-project-root)))
|
||||||
|
|
||||||
(defun doom-project-find-file (dir)
|
(defun doom-project-find-file (dir)
|
||||||
"Fuzzy-find a file under DIR."
|
"Fuzzy-find a file under DIR."
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue