I'm using spacemacs and setting a binding with spacemacs/set-leader-keys. The documentation for this states that it uses define-key:

spacemacs/set-leader-keys is a Lisp function in ‘core-keybindings.el’.

(spacemacs/set-leader-keys KEY DEF &rest BINDINGS)

Add KEY and DEF as key bindings under ‘dotspacemacs-leader-key’ and ‘dotspacemacs-emacs-leader-key’. KEY should be a string suitable for passing to ‘kbd’, and it should not include the leaders. DEF is most likely a quoted command. See ‘define-key’ for more information about the possible choices for DEF. This function simply uses ‘define-key’ to add the bindings.

For convenience, this function will accept additional KEY DEF pairs. For example,

(spacemacs/set-leader-keys "a" ’command1 "C-c" ’command2 "bb" ’command3)

spacemacs/set-leader-keys sets the name of the binding in the minibuffer to whatever function it's bound to. Right now I have:

(spacemacs/set-leader-keys "ic" (kbd "o { RET } <escape> O"))

so the binding name is the literal keystrokes. I'd like to be able to put the kbd statement in a function so the function name can be used:

(defun insert-code-block ()
  (kbd "o { RET } <escape> O"))
(spacemacs/set-leader-keys "ic" #'insert-code-block)

When doing so I get this error:

command-execute: Wrong type argument: commandp, insert-code-block

How do I make this work?

If you need to know the point of this binding, the binding adds a "code block". So if I type:

void this()

and issue the mnemonic SPC i c, I get a code block with the cursor (|) properly positioned:

void this()

1 Answer 1


Try this instead:

(spacemacs/set-leader-keys "ic" (insert-code-block))

It apparently expects, as argument, the result of invoking your function, not your function itself.

  • While this does work, it doesn't solve the naming issue. It still shows the keystrokes which makes sense because that's the result. I will mark as solved if that is out of scope.
    – mcp
    Feb 27, 2022 at 21:12
  • 1
    Using fset works for the naming as I figured out here, but since you actually solved the error I was facing, and since I have linked the alternative, I will mark this as the solution.
    – mcp
    Feb 28, 2022 at 1:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.