tags:

views:

88

answers:

2

Hi,

I am trying to make a simple keybinding to the "na" function. When I execute (na) it inserts "å" in the current buffer, which it is supposed to, but the when I try the keybinding as described in the first line I get the error: "Wrong argument: commandp, na". I am not sure if it matters, but I have also put the (local-set-key) command at the end of the code, but it produces the same error.

Now, I'm sure there is an easy solution to this. I just cannot see it =/

(local-set-key (kbd "C-c C-t") 'na)

(defun na ()
       "Liten å"
       (setq varlol "å")
       (insert varlol))
+7  A: 

What you're missing is a call to interactive:

(defun na ()
  "Liten å"
  (interactive)
  (setq varlol "å")
  (insert varlol))

From the documentation for it:

This special form declares that a function is a command, and that it may therefore be called interactively (via M-x or by entering a key sequence bound to it). The argument arg-descriptor declares how to compute the arguments to the command when the command is called interactively.

Trey Jackson
Thanks! That did the trick. I was reading the Elisp Introduction Article on GNU and the (interactive) symbol had "p" included so I automatically put that into the parantheses but got an error. I should have thought that the "p" means that it expects to recieve data. Thanks anyway!
bleakgadfly
@DreamCodeR Check out the docs for `interactive` to see the various arguments. The `"p"` indicates the prefix argument (`C-u`) is converted to a number. But, the error you got was that the function `na` *doesn't* have any arguments, so the error was most likely that you specified (via `interactive`) the function should have one argument, but the actual definition had none.
Trey Jackson
+2  A: 

"interactive" is missing

(defun na ()
  (interactive)
       "Liten å"
       (setq varlol "å")
       (insert varlol))