1

I'm trying to bind S-mouse-1 which doesn't seem to be as easy as I thought. So far I'm using:

(define-derived-mode foobar-mode nil "foobar")

(define-key foobar-mode-map [S-down-mouse-1]
  (lambda () (interactive)))

(define-key foobar-mode-map [S-mouse-1]
  (lambda () (interactive) (message "S-mouse-1")))

This seems to work but looks really clumsy. Is there a better way to do this? Without this clumsy binding of S-down-mouse-1 I do not get rid of its original binding to 'mouse-appearance-menu.

Note: Eventually I want to put this keymap into a text-property. This is why I want to override this key-binding and not remove it globally.

2
  • I suspect an 'X - Y' problem here. If you want some text to have a mouse action, you should look into make-text-button or make-button – rpluim Apr 16 '20 at 13:27
  • FWIW, I don't think it's an X-Y problem. – Drew Apr 16 '20 at 16:56
0

Yes, I think what you did is what most of us do in such a context. A mouse click involves a down (press) and an up (release) event. If you bind a command to the up event then you typically need to disable any command that might be bound to the down event.

See the Elisp manual, node Click Events.

But you can use this, instead; it's a bit simpler:

(define-key foobar-mode-map [S-down-mouse-1] 'ignore)
2
  • Yes, this is much better. (I didn't know that a function ignore existed.) One more question: Why is mouse-appearance-menu bound to S-down-mouse-1 at all? Would S-mouse-1 not be sufficient? – Andreas Matthias Apr 16 '20 at 18:30
  • A mouse click involves a down (press) and an up (release) event. If you bind a command to the up event then you typically need to disable any command that might be bound to the down event. Displaying a menu with a mouse click for example: some like to bind it to the down event, and some like to bind it to the up event; and sometimes the particular platform can influence the choice. – Drew Apr 16 '20 at 18:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.