core-lib: use projectile cache in file-exists-p!

If available.
This commit is contained in:
Henrik Lissner 2019-07-21 14:38:12 +02:00
parent f05aa3a0b1
commit 0f98b5b3c2
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395

View file

@ -38,29 +38,32 @@ Returns (approximately):
(and (if (file-exists-p B) B) (and (if (file-exists-p B) B)
(if (file-exists-p C) C)))) (if (file-exists-p C) C))))
This is used by `associate!', `file-exists-p!' and `project-file-exists-p!'." This is used by `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) (let ((exists-fn (if (fboundp 'projectile-file-exists-p)
`(let ((--file-- ,(if (file-name-absolute-p spec) #'projectile-file-exists-p
spec #'file-exists-p)))
`(expand-file-name ,spec ,directory)))) (cond ((stringp spec)
(and (file-exists-p --file--) `(let ((--file-- ,(if (file-name-absolute-p spec)
--file--))) spec
((and (listp spec) `(expand-file-name ,spec ,directory))))
(memq (car spec) '(or and))) (and (,exists-fn --file--)
`(,(car spec) --file--)))
,@(cl-loop for i in (cdr spec) ((and (listp spec)
collect (doom--resolve-path-forms i directory)))) (memq (car spec) '(or and)))
((or (symbolp spec) `(,(car spec)
(listp spec)) ,@(cl-loop for i in (cdr spec)
`(let ((--file-- ,(if (and directory collect (doom--resolve-path-forms i directory))))
(or (not (stringp directory)) ((or (symbolp spec)
(file-name-absolute-p directory))) (listp spec))
`(expand-file-name ,spec ,directory) `(let ((--file-- ,(if (and directory
spec))) (or (not (stringp directory))
(and (file-exists-p --file--) (file-name-absolute-p directory)))
--file--))) `(expand-file-name ,spec ,directory)
(spec))) spec)))
(and (,exists-fn --file--)
--file--)))
(spec))))
(defun doom--resolve-hook-forms (hooks) (defun doom--resolve-hook-forms (hooks)
"Converts a list of modes into a list of hook symbols. "Converts a list of modes into a list of hook symbols.