about summary refs log tree commit diff stats
path: root/lisp
diff options
context:
space:
mode:
authorCase Duckworth2021-03-12 17:29:26 -0600
committerCase Duckworth2021-03-12 17:29:26 -0600
commitea9fad47ece69cba9b30be8ec57a51f4f9421851 (patch)
treecb579808689645768424d020a51f0eef4ba7ec18 /lisp
parentMove `acdw/modeline' functions into `acdw/pkg' forms (diff)
downloademacs-ea9fad47ece69cba9b30be8ec57a51f4f9421851.tar.gz
emacs-ea9fad47ece69cba9b30be8ec57a51f4f9421851.zip
Change `acdw/hooks' form
Instead of only allowing (list-of-hooks) (list-of-functions), `acdw/hooks' now
accepts a (list-of-hook-specs), each of which is of the above form, allowing the
user to set multiple unrelated hooks at once.
Diffstat (limited to 'lisp')
-rw-r--r--lisp/acdw.el55
1 files changed, 27 insertions, 28 deletions
diff --git a/lisp/acdw.el b/lisp/acdw.el index 201db1f..6641e9b 100644 --- a/lisp/acdw.el +++ b/lisp/acdw.el
@@ -101,35 +101,34 @@ SPEC is as for `defface'."
101 ,@face-list))) 101 ,@face-list)))
102 102
103;;; Hooks 103;;; Hooks
104(defmacro acdw/hooks (hook-specs &rest args)
105 "Add functions to hooks, according to HOOK-SPECS.
104 106
105(defmacro acdw/hooks (hooks funcs &optional depth local) 107Each HOOK-SPEC is of the following format: (HOOKS FUNCS [DEPTH] [LOCAL]).
106 "Add FUNCS to HOOKS. 108Either HOOKS or FUNCS can also be a list, in which case `add-hook' is called
107 109over the Cartesian product of HOOKS and FUNCS. In each HOOK-SPEC, DEPTH and
108Either HOOKS or FUNCS can be a list, in which case they're mapped 110LOCAL apply to all hooks defined; if finer control is needed, either pass the
109over to add all FUNCS to all HOOKS. They can also be singletons, 111same hooks and functions in different HOOK-SPECs, or just use `add-hook'.
110in which case `acdw/hooks' acts pretty much like `add-hook'. 112
111 113ARGS accept the following keywords:
112DEPTH and LOCAL apply to all HOOKS defined here. If you need 114
113more fine-grained control, just use `add-hook'." 115:after FEATURE .. `autoload' all functions after FEATURE."
114 (let ((hooks (if (listp hooks) hooks (list hooks))) 116 (let ((after (plist-get args :after))
115 (funcs (if (listp funcs) funcs (list funcs))) 117 (command-list))
116 (depth (if depth depth 0)) 118 (dolist (spec hook-specs)
117 (hook-list)) 119 (let* ((hooks (car spec))
118 (dolist (hook hooks) 120 (funcs (cadr spec))
119 (dolist (func funcs) 121 (depth (or (caddr spec) 0))
120 (push `(add-hook ',hook #',func ,depth ,local) hook-list))) 122 (local (cadddr spec)))
121 `(progn 123 (when (not (listp hooks)) (setq hooks (list hooks)))
122 ,@hook-list))) 124 (when (not (listp funcs)) (setq funcs (list funcs)))
123 125 (dolist (hook hooks)
124(defmacro acdw/hooks-after (file hooks funcs &optional depth local) 126 (dolist (func funcs)
125 "Add FUNCS, from FILE, to HOOKS." 127 (push `(add-hook ',hook #',func ,depth ,local) command-list)
126 (let ((funcs (if (listp funcs) funcs (list funcs))) 128 (when after
127 (autoload-list)) 129 (push `(autoload #',func ,after) command-list))))))
128 (dolist (func funcs)
129 (add-to-list 'autoload-list `(autoload #',func ,file)))
130 `(progn 130 `(progn
131 ,@autoload-list 131 ,@command-list)))
132 (acdw/hooks ,hooks ,funcs ,depth ,local))))
133 132
134;;; Keybindings 133;;; Keybindings
135 134
@@ -209,7 +208,7 @@ ARGS can include the following keywords:
209 (when then-forms 208 (when then-forms
210 (push `(with-eval-after-load ',requirement ,@then-forms) final-form)) 209 (push `(with-eval-after-load ',requirement ,@then-forms) final-form))
211 (when hooks 210 (when hooks
212 (push `(acdw/hooks-after ,(symbol-name requirement) ,@hooks) final-form)) 211 (push `(acdw/hooks ,hooks :after ,(symbol-name requirement)) final-form))
213 (when binds 212 (when binds
214 (push `(acdw/bind-after-map ,(symbol-name requirement) nil ,binds) 213 (push `(acdw/bind-after-map ,(symbol-name requirement) nil ,binds)
215 final-form)) 214 final-form))