From 701f51c3d617b728b4d6d42adcd3c42c66c2813e Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Mon, 12 Sep 2022 17:35:44 +0200 Subject: [PATCH] refactor(lib): use uninterned symbols for transient/chained hooks The debugger appears to display uninterned symbols properly, and since these symbols should never be touched/referenced by users, there's no reason to pollute the obarray with these transient symbols. --- lisp/doom-lib.el | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/lisp/doom-lib.el b/lisp/doom-lib.el index e2113a66c..0c4130bf8 100644 --- a/lisp/doom-lib.el +++ b/lisp/doom-lib.el @@ -214,7 +214,7 @@ HOOK-VAR is triggered, it is reset to nil. HOOK-VAR is a quoted hook. TRIGGER-HOOK is a list of quoted hooks and/or sharp-quoted functions." (dolist (hook trigger-hooks) - (let ((fn (intern (format "%s-init-on-%s-h" hook-var hook)))) + (let ((fn (make-symbol (format "chain-%s-to-%s-h" hook-var hook)))) (fset fn (lambda (&rest _) ;; Only trigger this after Emacs has initialized. @@ -709,13 +709,8 @@ again. HOOK-OR-FUNCTION can be a quoted hook or a sharp-quoted function (which will be advised)." (declare (indent 1)) - (let ((append (if (eq (car forms) :after) (pop forms))) - ;; Avoid `make-symbol' and `gensym' here because an interned symbol is - ;; easier to debug in backtraces (and is visible to `describe-function') - (fn (intern (format "doom--transient-%d-h" - (put 'add-transient-hook! 'counter - (1+ (or (get 'add-transient-hook! 'counter) - 0))))))) + (let ((append? (if (eq (car forms) :after) (pop forms))) + (fn (gensym "doom-transient-hook"))) `(let ((sym ,hook-or-function)) (defun ,fn (&rest _) ,(format "Transient hook for %S" (doom-unquote hook-or-function)) @@ -725,10 +720,10 @@ advised)." ((symbolp sym) (remove-hook sym #',fn)))) (unintern ',fn nil)) (cond ((functionp sym) - (advice-add ,hook-or-function ,(if append :after :before) #',fn)) + (advice-add ,hook-or-function ,(if append? :after :before) #',fn)) ((symbolp sym) (put ',fn 'permanent-local-hook t) - (add-hook sym #',fn ,append)))))) + (add-hook sym #',fn ,append?)))))) (defmacro add-hook! (hooks &rest rest) "A convenience macro for adding N functions to M hooks. @@ -807,8 +802,7 @@ If N and M = 1, there's no benefit to using this macro over `remove-hook'. collect `(defun ,fn (&rest _) ,(format "%s = %s" var (pp-to-string val)) (setq-local ,var ,val)) - collect `(remove-hook ',hook #',fn) ; ensure set order - collect `(add-hook ',hook #',fn)))) + collect `(add-hook ',hook #',fn -90)))) (defmacro unsetq-hook! (hooks &rest vars) "Unbind setq hooks on HOOKS for VARS.