0

I defined this keymap:

(defvar my-custom-keymap
  (let ((map (make-sparse-keymap)))
    (define-key map [mouse-1] #'my-function1)
    (define-key map [mouse-3] #'my-function2)
    map)
  "Custom Keymap")

Then I use:

(overlay-put this-overlay 'keymap my-custom-keymap)

to set the key-binding on some overlays.

Both my-function1 and my-function2 works on overlays using the (thing-at-point) function, but only the first one works like I aspected because mouse-1 event runs (mouse-set-point) and than my-function1.

mouse-3 event doesn't move the "point" so it doesn't see the "thing-at-point" where the mouse has been clicked.

Can I make mouse-3 event behave like mouse-1 event only for overlays?

2 Answers 2

1

Yes, have function2 call mouse-set-point before calling thing-at-point.

1
  • Thanks, I made that (mouse-set-point) is called by a lamda function in the keymap.
    – Gabriele
    Commented May 28, 2022 at 7:49
0

This code works for me:

(defvar my-custom-keymap
  (let ((map (make-sparse-keymap)))
    (define-key map [mouse-1] #'my-function1)
    (define-key map [mouse-3] '(lambda ()
                                 (interactive)
                                 (mouse-set-point last-input-event)
                                 (my-function2)))
    map)
  "Custom Keymap")

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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