'"wrong type of argument: commandp, my/function" when setting a keybinding in elisp

This might look as a duplicate, but I have tried all the other solutions without success.

I have a function in my init file starting like this:

(defun my/function ()
  "Comment or uncomment the current line or text selection."
  (interactive)
  (let (p1 p2)
    (if (use-region-p)

When I set a key binding:

(global-set-key (kbd "C-x C-.") 'my/function)

I get the following error:

wrong type of argument: commandp, my/function

When I turn debug-on-error, this is what I get:

 call-interactively(my/function nil nil)
  command-execute(my/function)

What am I doing wrong?



Solution 1:[1]

The function you bind must be a command, that is: it must have (interactive) in it. Running (commandp 'my/function) should tell you whether it does.

(In your question you indeed have the (interactive) in the definition, but something must have gone wrong, perhaps re-evaluating the function's definition will fix it)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Cigarette Smoking Man