Refactor doom--resolve-path-forms
This commit is contained in:
parent
47ccbb5d41
commit
b2186745b7
1 changed files with 34 additions and 12 deletions
|
@ -15,18 +15,40 @@
|
||||||
;; Helpers
|
;; Helpers
|
||||||
;;
|
;;
|
||||||
|
|
||||||
(defun doom--resolve-path-forms (paths &optional root)
|
(defun doom--resolve-path-forms (spec &optional directory)
|
||||||
(cond ((stringp paths)
|
"Converts a simple nested series of or/and forms into a series of
|
||||||
|
`file-exists-p' checks.
|
||||||
|
|
||||||
|
For example
|
||||||
|
|
||||||
|
(doom--resolve-path-forms
|
||||||
|
'(or \"some-file\" (and path-var \"/an/absolute/path\"))
|
||||||
|
\"~\")
|
||||||
|
|
||||||
|
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\")))
|
||||||
|
|
||||||
|
This is used by `associate!', `file-exists-p!' and `project-file-exists-p!'."
|
||||||
|
(cond ((stringp spec)
|
||||||
`(file-exists-p
|
`(file-exists-p
|
||||||
(expand-file-name
|
,(if (file-name-absolute-p spec)
|
||||||
,paths ,(if (or (string-prefix-p "./" paths)
|
spec
|
||||||
(string-prefix-p "../" paths))
|
`(expand-file-name ,spec ,directory))))
|
||||||
'default-directory
|
((symbolp spec)
|
||||||
(or root `(doom-project-root))))))
|
`(file-exists-p ,(if directory
|
||||||
((listp paths)
|
`(expand-file-name ,spec ,directory)
|
||||||
(cl-loop for i in paths
|
path)))
|
||||||
collect (doom--resolve-path-forms i root)))
|
((and (listp spec)
|
||||||
(t paths)))
|
(memq (car spec) '(or and)))
|
||||||
|
`(,(car spec)
|
||||||
|
,@(cl-loop for i in (cdr spec)
|
||||||
|
collect (doom--resolve-path-forms i directory))))
|
||||||
|
((listp spec)
|
||||||
|
(doom--resolve-path-forms (eval spec t) directory))
|
||||||
|
(t spec)))
|
||||||
|
|
||||||
(defun doom--resolve-hook-forms (hooks)
|
(defun doom--resolve-hook-forms (hooks)
|
||||||
(cl-loop with quoted-p = (eq (car-safe hooks) 'quote)
|
(cl-loop with quoted-p = (eq (car-safe hooks) 'quote)
|
||||||
|
@ -314,7 +336,7 @@ Body forms can access the hook's arguments through the let-bound variable
|
||||||
(not ,mode)
|
(not ,mode)
|
||||||
(and buffer-file-name (not (file-remote-p buffer-file-name)))
|
(and buffer-file-name (not (file-remote-p buffer-file-name)))
|
||||||
,(if match `(if buffer-file-name (string-match-p ,match buffer-file-name)) t)
|
,(if match `(if buffer-file-name (string-match-p ,match buffer-file-name)) t)
|
||||||
,(if files (doom--resolve-path-forms files) t)
|
,(if files (doom--resolve-path-forms files '(doom-project-root)) t)
|
||||||
,(or pred-form t))
|
,(or pred-form t))
|
||||||
(,mode 1)))
|
(,mode 1)))
|
||||||
,@(if (and modes (listp modes))
|
,@(if (and modes (listp modes))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue