How can I write a mapping (e.g. a mapcar
expression) to build the list for a use-package :hook
clause?
I'm attempting to build the list in this :hook
expression:
(use-package eglot
:hook (
(lorem-mode . eglot-ensure)
(ipsum-mode . eglot-ensure)
(dolor-mode . eglot-ensure)
)
)
by replacing the literal list with a mapcar
expression:
(use-package eglot
:hook
(mapcar
(lambda (lang-mode)
(cons lang-mode '(. eglot-ensure)))
'(
lorem-mode
ipsum-mode
dolor-mode
))
)
When I try evaluating the mapcar
expression, it returns the list as expected.
((lorem-mode . eglot-ensure) (ipsum-mode . eglot-ensure) (dolor-mode . eglot-ensure))
When I try evaluating the entire use-package
expression, it throws a Lisp error:
(wrong-type-argument listp lambda) […]
(If it's useful to show the entire traceback here I can; though hopefully the mistake I've made is obvious without that?)
How can I map (using mapcar
or something more appropriate) a literal list of only the mode names, to generate the list-of-lists needed in :hook
?
(cons lang-mode '(. eglot-ensure))
is exactly equivalent to(cons lang-mode 'eglot-ensure)