Minor refactor of associate! macro

This commit is contained in:
Henrik Lissner 2018-06-03 23:56:25 +02:00
parent 796af69c28
commit b53df20dd5
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395

View file

@ -353,17 +353,18 @@ The available conditions are:
(user-error "associate! :files expects a string or list of strings"))
(let ((hook-name (intern (format "doom--init-mode-%s" mode))))
`(progn
(defun ,hook-name ()
(when (and (fboundp ',mode)
(fset ',hook-name
(lambda ()
(and (fboundp ',mode)
(not (bound-and-true-p ,mode))
(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 files (doom--resolve-path-forms
,(or (not files)
(doom--resolve-path-forms
(if (stringp (car files)) (cons 'and files) files)
'(doom-project-root))
t)
,(or pred-form t))
(,mode 1)))
'(doom-project-root)))
,(or pred-form t)
(,mode 1))))
,@(if (and modes (listp modes))
(cl-loop for hook in (doom--resolve-hook-forms modes)
collect `(add-hook ',hook #',hook-name))