New macros file-exists-p! & project-file-exists-p!
The latter replaces the doom-project-has! macro
This commit is contained in:
parent
b2186745b7
commit
4ee0b5ba6d
6 changed files with 28 additions and 14 deletions
|
@ -348,5 +348,19 @@ Body forms can access the hook's arguments through the let-bound variable
|
|||
(t (user-error "associate! invalid rules for mode [%s] (modes %s) (match %s) (files %s)"
|
||||
mode modes match files))))))
|
||||
|
||||
(defmacro file-exists-p! (spec &optional directory)
|
||||
"Returns t 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.
|
||||
|
||||
DIRECTORY is where to look for the files in SPEC if they aren't absolute. This
|
||||
doesn't apply to variables, however.
|
||||
|
||||
For example:
|
||||
|
||||
(file-exists-p (or doom-core-dir \"~/.config\" \"some-file\") \"~\")"
|
||||
(doom--resolve-path-forms spec directory))
|
||||
|
||||
(provide 'core-lib)
|
||||
;;; core-lib.el ends here
|
||||
|
|
|
@ -94,12 +94,12 @@ If NOCACHE, don't fetch a cached answer."
|
|||
|
||||
(defalias 'doom-project-expand #'projectile-expand-root)
|
||||
|
||||
(defmacro doom-project-has! (files)
|
||||
(defmacro project-file-exists-p! (files)
|
||||
"Checks if the project has the specified FILES.
|
||||
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)))
|
||||
(doom--resolve-path-forms files '(doom-project-root)))
|
||||
|
||||
(defun doom-project-find-file (dir)
|
||||
"Fuzzy-find a file under DIR."
|
||||
|
|
|
@ -7,8 +7,8 @@
|
|||
(def-test! resolve-path-forms
|
||||
(should
|
||||
(equal (doom--resolve-path-forms '(and "fileA" "fileB"))
|
||||
'(and (file-exists-p (expand-file-name "fileA" (doom-project-root)))
|
||||
(file-exists-p (expand-file-name "fileB" (doom-project-root)))))))
|
||||
'(and (file-exists-p (expand-file-name "fileA" nil))
|
||||
(file-exists-p (expand-file-name "fileB" nil))))))
|
||||
|
||||
;; `doom--resolve-hook-forms'
|
||||
(def-test! resolve-hook-forms
|
||||
|
|
|
@ -33,15 +33,15 @@
|
|||
(should (equal (doom-project-expand "init.el")
|
||||
(expand-file-name "init.el" (doom-project-root))))))
|
||||
|
||||
;; `doom-project-has!'
|
||||
;; `project-file-exists-p!'
|
||||
(def-test! project-has!
|
||||
:minor-mode projectile-mode
|
||||
(let ((default-directory doom-core-dir))
|
||||
;; Resolve from project root
|
||||
(should (doom-project-has! "init.el"))
|
||||
(should (project-file-exists-p! "init.el"))
|
||||
;; Chained file checks
|
||||
(should (doom-project-has! (and "init.el" "LICENSE")))
|
||||
(should (doom-project-has! (or "init.el" "does-not-exist")))
|
||||
(should (doom-project-has! (and "init.el" (or "LICENSE" "does-not-exist"))))
|
||||
(should (project-file-exists-p! (and "init.el" "LICENSE")))
|
||||
(should (project-file-exists-p! (or "init.el" "does-not-exist")))
|
||||
(should (project-file-exists-p! (and "init.el" (or "LICENSE" "does-not-exist"))))
|
||||
;; Should resolve relative paths from `default-directory'
|
||||
(should (doom-project-has! (and "./core.el" "../init.el")))))
|
||||
(should (project-file-exists-p! (and "core/core.el" "./init.el")))))
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
(interactive)
|
||||
(unless (memq major-mode '(c-mode c++-mode objc-mode))
|
||||
(user-error "Not a C/C++/ObjC buffer"))
|
||||
(unless (doom-project-has! "compile_commands.json")
|
||||
(unless (project-file-exists-p! "compile_commands.json")
|
||||
(user-error "No compile_commands.json file"))
|
||||
;; first rtag
|
||||
(when (and (featurep 'rtags)
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
|
||||
;;;###autoload
|
||||
(defun +java|android-mode-maybe ()
|
||||
(when (doom-project-has! (or "local.properties"
|
||||
(when (project-file-exists-p! (or "local.properties"
|
||||
"AndroidManifest.xml"
|
||||
"src/main/AndroidManifest.xml"))
|
||||
(android-mode +1)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue