unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Single-use keybindings?
@ 2017-07-23  0:52 Eric Abrahamsen
  2017-07-23  1:00 ` Drew Adams
                   ` (2 more replies)
  0 siblings, 3 replies; 12+ messages in thread
From: Eric Abrahamsen @ 2017-07-23  0:52 UTC (permalink / raw)
  To: help-gnu-emacs

A few times I've found myself wanting the ability to set a single-use
keybinding: the next time the user hits "q" (or what have you), run this
command, then reset "q" to whatever it was before.

This feels hacky, obviously, but more importantly it feels like I'm
not using the right tools, or misusing what I've got. Has anyone else
wanted to do this? Any better solutions? Maybe I should be using a minor
mode that turns itself off after use, or...

Anyway, any thoughts would be much appreciation. Here's the function I
just wrote -- it pops to a certain buffer from wherever you are, and
when it gets there it rebinds "q" to pop back where you came from,
resetting "q" to it's original binding as it goes. It works, but I still
feel bad about it.

Eric

(defun ebdb-mua-in-ebdb-buffer ()
  "From an MUA, temporarily move point to the corresponding EBDB buffer.

All further operations will take place within the EBDB buffer as
per normal, with the exception that \"q\" will return point to
where it was in the MUA, rather than quitting the EBDB buffer."
  (interactive)
  (let* ((buf (get-buffer (ebdb-make-buffer-name)))
	 (w-conf (current-window-configuration))
	 (w-win (selected-window))
	 (w-point (window-point))
	 (e-win (or (get-buffer-window buf)
		    (ebdb-pop-up-window buf t (ebdb-make-buffer-name))))
	 q-bind)
    (select-window e-win t)
    (setq q-bind (key-binding "q"))
    (local-set-key
     "q"
     (lambda ()
       (interactive)
       (local-set-key (kbd "q") q-bind)
       (when (window-live-p w-win)
	 (set-window-configuration w-conf)
	 (goto-char w-point))))))




^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2017-07-23 22:18 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-07-23  0:52 Single-use keybindings? Eric Abrahamsen
2017-07-23  1:00 ` Drew Adams
2017-07-23  1:04   ` Eric Abrahamsen
2017-07-23  1:22   ` Eric Abrahamsen
2017-07-23  5:51 ` Emanuel Berg
2017-07-23 18:04   ` Eric Abrahamsen
2017-07-23 21:28     ` Eric Abrahamsen
2017-07-23 21:45       ` Emanuel Berg
2017-07-23 22:09         ` Eric Abrahamsen
2017-07-23 22:04 ` Michael Heerdegen
2017-07-23 22:11   ` Emanuel Berg
2017-07-23 22:18   ` Eric Abrahamsen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).