[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Single-use keybindings?
From: |
Eric Abrahamsen |
Subject: |
Re: Single-use keybindings? |
Date: |
Sun, 23 Jul 2017 15:09:25 -0700 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux) |
Emanuel Berg <moasen@zoho.com> writes:
> Eric Abrahamsen wrote:
>
>> Actually, it wasn't! The transient map
>> disappears the first time any key is hit that
>> isn't in the map itself. What I wanted was to
>> rewire "q", and nothing but "q", until the
>> first time that "q" is hit. I can probably
>> still get what I want by fooling with the
>> KEEP-PRED argument to `set-transient-map',
>> but it's not the no-brainer I thought it was.
>
> Here is the minor-mode-that-shuts-off-itself
> idea. It has served me well. I wrote it in 2014
> but it feels like 10 years ago. Man...
>
> http://user.it.uu.se/~embe8573/emacs-init/caps-back.el
I got this working, and it seems to do the right thing. It did end up
being a lot of code, though. Note the second argument to
`set-transient-map', that's pretty much what makes it all work.
I'm kind of ambivalent about this now, but I guess it's still the best
solution.
(let* ((buf (get-buffer (ebdb-make-buffer-name)))
(w-conf (current-window-configuration))
(w-win (selected-window))
(w-point (window-point))
(e-win (if (window-live-p (get-buffer-window buf))
(get-buffer-window buf)
(ebdb-pop-up-window buf t (ebdb-popup-window))))
(key-m (make-sparse-keymap)))
(define-key key-m (kbd "q")
(lambda ()
(interactive)
(when (window-live-p w-win)
(set-window-configuration w-conf)
(goto-char w-point))))
(select-window e-win t)
(set-transient-map
key-m
(lambda ()
;; Keep the transient map active until the user hits "q".
(null
(equal (this-command-keys-vector)
[?q])))))
Re: Single-use keybindings?, Michael Heerdegen, 2017/07/23