A function for which commandp
returns t
is an interactive
functioninteractive
function, i.e. one which calls (interactive ...)
as the first thing in its body. So
you can write a function like this:
(defun insert-vertbar ()
(interactive)
(insert "|"))
and bind it to the mouse click:
(global-set-key [S-mouse-2] #'insert-vertbar)
interactive
has a lot of wrinkles (which are not necessary in this case, but they can be valuable when you need to write a more complicated function): you can find out more by using your emacs's help facility: C-h f interactive
, and/or looking it up in the
the emacs lisp manual.
N.B. In my case, [S-mouse-1]
was intercepted by the window manager before emacs could get to it, so I was not able to bind it to that. I had to use [S-mouse-2]
instead.