I want to register a click event and do actions based on the position
, window
..etc.
This site, http://www.gnu.org/software/emacs/manual/html_node/elisp/Click-Events.html
, shows the layout of the event variables, but how do I actually attach a handler to the click events.
So, basically I am looking for a function that behaves like attach-handler
would in the below senario.
(attach-handler [mouse-1]
`(lambda (e) (foo e))
You may use the code letter `e' of the interactive
declaration to access the event; e.g., the following will make left click insert the event data at the point clicked:
(define-key global-map (kbd "<down-mouse-1>")
(lambda (event)
(interactive "e")
(message "%s" event)
(let ((posn (elt event 1)))
(with-selected-window (posn-window posn)
(goto-char (posn-point posn))
(insert (format "%s" event))))))
They are all keys. Try C-h c
( or C-h k
) and click a mouse button to see what it is currently bound to. Then use M-x global-set-key
to set it to whatever you want to. Your function will have to be interactive
to bind it to a key.
print
? You might want to create named function instead of a lambda
and edebug
it to see if event has any interesting properties. Also look at last-input-event
and last-command-event
. Oh and there is also mouse-event-p
and others - Miserable Variable 2012-04-04 21:00
event
information in the following statement?(global-set-key [mouse-1] \
(lambda() (interactive) (print event)) - Doboy 2012-04-04 20:49