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