1

I want to change the name of the function key <mouse-1> like so:
(define-key input-decode-map (kbd "<mouse-1>") (kbd "<jd:m1>"))

And thus bind the new name to an arbitrary function like so:
(define-key global-map (kbd "<jd:m1>") 'mouse-set-point)

But when testing the changes I get this error:

Debugger entered--Lisp error: (error "mouse-set-point must be bound to an event with parameters")
  call-interactively(mouse-set-point nil nil)
  command-execute(mouse-set-point)

Why does this functionality work for all other key functions but not the mouse key functions?

For example this works just fine:

(define-key input-decode-map (kbd "<tab>") (kbd "<jd:tab>"))
(define-key global-map (kbd "<jd:tab>") 'indent-for-tab-command)
4

The issue is the following:

(define-key input-decode-map [mouse-1] [jd:m1])

will convert any incoming "event with name mouse-1" into the event jd:m1, whereas you want to convert it to a similar "event with name jd:m1". More specifically, mouse events are not just symbols but have the form:

(NAME . METADATA)

where NAME may be equal to things like mouse-1 and METADATA holds info such as the location where the user pressed this mouse button.

IOW, your remapping turns (mouse-1 . METADATA) into a "dumb" jd:m1 losing the METADATA along the way.

Doing the kind of remapping you propose is actually tricky for all kinds of arbitrary reasons. I suggest you look at the source code of mouse--click-1-maybe-follows-link to see what it might involve.

Basically, you'll need something like:

(define-key input-decode-map [mouse-1]
  (lambda (&optional _prompt)
    (let ((newname 'jd:m1))
      ;; Copy the `event-kind` at the first occasion.
      (unless (get newname 'event-kind)
        (put newname 'event-kind
             (get (car last-input-event) 'event-kind)))
      ;; Modify the event in-place, otherwise we can get a prefix
      ;; added again, so a click on the header-line turns
      ;; into a [header-line header-line <newname>] :-(.
      ;; See fake_prefixed_keys in src/keyboard.c's.
      (setf (car last-input-event) newname)
      (vector last-input-event))))

Yuck!

  • 1
    So I'm assuming that the events <vertical-line> and <mode-line> both have metadata associated with them as well? When events like, <escape>, <return>, and <tab>, etc. are dummy events with only a key press that's associated with them..? Or I guess a better follow up question would be how in the world you found out that the <mouse-1> event has the form (NAME . METADATA)?? I can't M-x describe that or anything, and I wouldn't know where to start to find information like that. – John DeBord Sep 14 '18 at 22:02
  • 1
    @JohnDeBord: Actually, I think that those pseudo events like mode-line and vertical-line don't carry any metadata. You can figure it out by looking at the shape of the value of last-input-event during the remapping, but for that you need to use a function like I did (IOW, you already need to know more than you originally did). – Stefan Sep 14 '18 at 22:50
  • Ok. Well it just dawned on me...How in the heck do I just rename this fricken symbol (or symbols) without going through all the hassle of converting the events. I don't care if I have to modify the source code or anything. I've gone down this rabbit hole for far too long and I just need something to show for it. – John DeBord Sep 14 '18 at 22:58
  • Really would appreciate a quick response. This is going to be my project for the night. But I understand if you're busy. – John DeBord Sep 15 '18 at 1:43
  • @JohnDeBord: response to what question? – Stefan Sep 15 '18 at 2:07

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.