I'm trying to create a transient keymap that calls calls quick-peek-hide on any key except mouse scrolling, which should function normally.
I've got the following:
(let ((map (make-sparse-keymap)))
(define-key map [mouse-4] #'mwheel-scroll)
(define-key map [mouse-5] #'mwheel-scroll)
(define-key map [t] #'quick-peek-hide)
(set-transient-map map <keep-pred> <on-exit>))
And don't know what should be the values of <keep-pred> and <on-exit> should be.
If keep-pred is t, wouldn't the transient map remain active forever because we define the default key [t]? If on-exit is #'quick-peek-hide, scrolling would invoke quick-peek-hide instead of simply doing mwheel-scroll.
Update:
A few observations:
- The default keybinding
[t]does not keep the transient map active.
(let ((map (make-sparse-keymap)))
(define-key map [t] (lambda ()
(interactive)
(message "default!")))
(set-transient-map map t))
Activating the above transient map causes the next key to message default!, but exits the transient map thereafter.
- Mouse events are preceded by
down-mouse events, so it is not sufficient to bind[mouse-4],[mouse-5], etc.
For example, describe-key for a mouse scroll down gives:
<mouse-5>(translated from<down-mouse-5> <mouse-5>) at that spot runs the commandmwheel-scroll
So scrolling down with the following:
(let ((map (make-sparse-keymap)))
(dolist (scroll-key (where-is-internal #'mwheel-scroll))
(define-key map scroll-key (lambda ()
(interactive)
(message "scroll-key!"))))
(define-key map [t] (lambda ()
(interactive)
(message "default!")))
(set-transient-map map t))
Does not message scroll-key!, but default!.
- Hacking the following together:
(let ((map (make-sparse-keymap)))
(dolist (scroll-key (where-is-internal #'mwheel-scroll))
(define-key map scroll-key (lambda ()
(interactive)
(message "scroll-key!"))))
(define-key map [t] (lambda ()
(interactive)
(message "default!")))
(define-key map (kbd "<down-mouse-5>") (lambda ()
(interactive)
(message "down-mouse-5!")))
(set-transient-map map t))
The first scroll down message down-mouse-5! and scroll-key!, but the next one messages default and exits the transient map.
So the question is: what keys/events need to be bound to prevent scrolling from exiting the transient map?.
set-transient-mapwas invented specifically to avoid the need to use[t]bindings (since these are always problematic: they preventinput-decode-mapand friends from doing their job and there is no 100% reliable way to unread an event). – Stefan May 15 '17 at 04:13[t]bindings allow a keypress toquick-peek-hide, but not the execute the key's usual function. I want every key (except scrolling) afterquick-peek-showtoquick-peek-hide, not do what they'd normally do (insert char, etc.). Is there a way to achieve that without binding[t]? – Tianxiang Xiong May 15 '17 at 06:36on-exitargument where you can setthis-commandtoignorein order to cause the exiting key to "do nothing". – Stefan May 15 '17 at 12:09[t]. Is the issue w/ binding[t]that the specific key is not recorded? – Tianxiang Xiong May 15 '17 at 16:25