I have the following function, which does what it says on the tin -- swaps the values of the ns-alternate-modifier
and ns-right-alternate-modifier
variables.
(defun swap-left-and-right-alt ()
"Swap left and right alt keys"
(setq ns-alternate-modifier
(prog1 ns-right-alternate-modifier
(setq ns-right-alternate-modifier
ns-alternate-modifier))))
When I put this in my init.el
, I don't get any errors, but I also don't get a M-x
autocomplete for swap-left-and-right-alt
, and if I type it out I get [No match]
.
I've read the manual section on defun and the section following it on installing function definitions, and it seems reasonable to think my problem is that the function isn't installed. However, when I try to install it by hand (following the manual) by opening the init.el
, placing the cursor at the end of the function definition, and hitting C-x C-e
, though this does do something (I see swap-left-and-right-alt
in the minibuffer), it still doesn't do what I want, i.e. M-x swap-left-and-right-alt
still gets me [No match]
.
(There is one difference: after the C-x C-e
experiment, if I try to evaluate swap-left-and-right-alt
, I get Symbol's value as variable is void
, whereas just having it in the init file I get the debugger, with Lisp error: (void-variable swap-left-and-right-alt)
. Also, evaluating (swap-left-and-right-alt)
, with parentheses, does appear to run the function, i.e., the keys get swapped.)
Clearly there's a conceptual piece that I'm missing, but I haven't been able to hit on the right combination of Emacs-speak search terms to find the answer.
What do I need to put in my init file to
- install the function, and
- be able to autocomplete and run the function as a command?
interactive
declaration. Check here. – Juancho Oct 15 '18 at 19:27interactive
(explainingcommandp
). That will cover many, perhaps most, of the duplicates. (Others are problems of a command being removed from a library etc.) And you can mention the most common case where users run into this: trying to bind a key to a non-command. But the question and answer are not necessarily about key bindings. If you do that then we can point to that Q&A instead, and close others. – Drew Oct 16 '18 at 01:47interactive
spec - it could be that you lack the function altogether. But the error msg always means that something expected a command (commandp
) and didn't get one. – Drew Oct 16 '18 at 04:19[No match]
? – David Moles Oct 16 '18 at 20:46Wrong type argument: commandp, XXXXX
, whereXXXXX
is a lambda form or the name of a function. – Drew Oct 16 '18 at 22:39