From b53df20dd544c57b90b47b1420f3d4fae3292b68 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Sun, 3 Jun 2018 23:56:25 +0200 Subject: [PATCH] Minor refactor of associate! macro --- core/core-lib.el | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/core/core-lib.el b/core/core-lib.el index 30a2f07fd..4849f8cc3 100644 --- a/core/core-lib.el +++ b/core/core-lib.el @@ -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 - (if (stringp (car files)) (cons 'and files) files) - '(doom-project-root)) - t) - ,(or pred-form t)) - (,mode 1))) + ,(or (not files) + (doom--resolve-path-forms + (if (stringp (car files)) (cons 'and files) files) + '(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))