From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Eric Abrahamsen Newsgroups: gmane.emacs.help Subject: Re: Single-use keybindings? Date: Sat, 22 Jul 2017 18:22:20 -0700 Message-ID: <871sp8ne0j.fsf@ericabrahamsen.net> References: <87y3rgq8iy.fsf@ericabrahamsen.net> <1336c859-9a4f-48d2-a838-81eab9dd0e59@default> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1500773066 16889 195.159.176.226 (23 Jul 2017 01:24:26 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 23 Jul 2017 01:24:26 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sun Jul 23 03:24:18 2017 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dZ5cy-0003eD-Tc for geh-help-gnu-emacs@m.gmane.org; Sun, 23 Jul 2017 03:24:13 +0200 Original-Received: from localhost ([::1]:48862 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dZ5d4-0006th-H0 for geh-help-gnu-emacs@m.gmane.org; Sat, 22 Jul 2017 21:24:18 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:51071) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dZ5cP-0006pq-JF for help-gnu-emacs@gnu.org; Sat, 22 Jul 2017 21:23:38 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dZ5cM-0000eH-Gf for help-gnu-emacs@gnu.org; Sat, 22 Jul 2017 21:23:37 -0400 Original-Received: from [195.159.176.226] (port=39750 helo=blaine.gmane.org) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dZ5cM-0000e4-9j for help-gnu-emacs@gnu.org; Sat, 22 Jul 2017 21:23:34 -0400 Original-Received: from list by blaine.gmane.org with local (Exim 4.84_2) (envelope-from ) id 1dZ5cB-0001K3-RM for help-gnu-emacs@gnu.org; Sun, 23 Jul 2017 03:23:23 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 38 Original-X-Complaints-To: usenet@blaine.gmane.org Cancel-Lock: sha1:4qpYiR8b5zLhlwpIIEuWbitqVvU= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 195.159.176.226 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.org gmane.emacs.help:113833 Archived-At: Drew Adams writes: >> 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... > > See `set-transient-map'. From (elisp) `Controlling Active Maps': There's the new version, which I'm feeling much better about. Thanks again. (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 (window-live-p (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)))