I am working on optimizing my emacs config where I can dynamically create interactive functions for all themes I have in a list.
Below is a simplified version of the construct I am trying to make work.
;; List containing names of functions that I want to create (setq my/defun-list '(zz-abc zz-def zz-ghi)) ;; Elisp macro to create an interactive defun whose name ;; is passed as the macro argument (defmacro my/create-defun (defun-name) `(defun ,defun-name () (interactive) (let ((fn-name (symbol-name ',defun-name))) (message "Testing creation of function %s" fn-name)))) ;; Loop to call the above macro for each element in the list ;; DOES *NOT* WORK (dolist (name my/defun-list) (my/create-defun name))
But if I unroll the loop manually, it works:
;; WORKS (my/create-defun zz-abc) (my/create-defun zz-def) (my/create-defun zz-ghi)
But the below does not work where I pass in the symbol names (which is probably what's happening when the loop unrolls by itself). Note the quotes before the macro arguments.
;; DOES *NOT* WORK (my/create-defun 'zz-abc) (my/create-defun 'zz-def) (my/create-defun 'zz-ghi)
Thanks to @wvxvw's help, I finally got this working!
As @wvxvw suggests, I will not be batch-generating defuns for any and every use case. This was a special use case where for a theme named
XYZ, I want to generate a defun called
load-theme/XYZ that does the job of
- Disabling all other themes that might be active
- Doing some more custom stuff related to that theme; I pass in the custom settings for each theme through the