From 52a04fd8c66a8a95de0f30efbb279392f3b65f3b Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Mon, 4 Jun 2018 13:57:18 +0200 Subject: [PATCH] Optimize file-exists-p! & project-file-exists-p! --- core/core-lib.el | 18 ++++++++++++------ core/core-projects.el | 2 +- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/core/core-lib.el b/core/core-lib.el index 4849f8cc3..2f758f42b 100644 --- a/core/core-lib.el +++ b/core/core-lib.el @@ -30,9 +30,10 @@ For example Returns - '(or (file-exists-p (expand-file-name \"some-file\" \"~\")) - (and (file-exists-p (expand-file-name path-var \"~\")) - (file-exists-p \"/an/absolute/path\"))) + '(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\")))) This is used by `associate!', `file-exists-p!' and `project-file-exists-p!'." (cond ((stringp spec) @@ -41,7 +42,9 @@ This is used by `associate!', `file-exists-p!' and `project-file-exists-p!'." spec `(expand-file-name ,spec ,directory)))) ((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) path))) ((and (listp spec) @@ -385,8 +388,11 @@ doesn't apply to variables, however. For example: - (file-exists-p (or doom-core-dir \"~/.config\" \"some-file\") \"~\")" - (doom--resolve-path-forms spec directory)) + (file-exists-p! (or doom-core-dir \"~/.config\" \"some-file\") \"~\")" + (if directory + `(let ((_directory ,directory)) + ,(doom--resolve-path-forms spec '_directory)) + (doom--resolve-path-forms spec))) (defmacro define-key! (keymaps key def &rest rest) "Like `define-key', but accepts a variable number of KEYMAPS and/or KEY+DEFs. diff --git a/core/core-projects.el b/core/core-projects.el index 5ad28773b..509b7c244 100644 --- a/core/core-projects.el +++ b/core/core-projects.el @@ -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 which case they're relative to `default-directory'). If they start with a slash, they are absolute." - (doom--resolve-path-forms files '(doom-project-root))) + `(file-exists-p! ,files (doom-project-root))) (defun doom-project-find-file (dir) "Fuzzy-find a file under DIR."