I'm trying to write a helper macro to conveniently define keybindings in my configuration file.
The idea is to replace the following configuration entry:
(use-package org-roam
:config
(define-key evil-normal-state-map (kbd "SPC n g") #'org-roam-graph)
(define-key evil-insert-state-map (kbd "C-c n g") #'org-roam-graph)
(define-key evil-visual-state-map (kbd "C-c n g") #'org-roam-graph))
With that one:
(use-package org-roam
:config
(define-evil-key "n g" #'org-roam-graph))
Here's how I'm trying to write such a macro:
(defmacro define-evil-key (k fn)
(define-key evil-normal-state-map (kbd (concat "SPC " k)) fn)
(define-key evil-insert-state-map (kbd (concat "C-c " k)) fn)
(define-key evil-visual-state-map (kbd (concat "C-c " k)) fn))
But when I press the defined keybinding SPC n g
, I get the following error: Wrong type argument: commandp, #'org-roam-graph
.
I'm not really sure, what is going wrong. It seems to me, that the macros should be expanded on the sequence of define-key
calls, but it doesn't work that way.
Could someone please explain how to properly define this macros and how to debug similar errors in the future?
defun
) rather than a macro?