From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Drew Adams Newsgroups: gmane.emacs.help Subject: RE: Single-use keybindings? Date: Sat, 22 Jul 2017 18:00:42 -0700 (PDT) Message-ID: <1336c859-9a4f-48d2-a838-81eab9dd0e59@default> References: <87y3rgq8iy.fsf@ericabrahamsen.net> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: blaine.gmane.org 1500771705 14669 195.159.176.226 (23 Jul 2017 01:01:45 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 23 Jul 2017 01:01:45 +0000 (UTC) To: Eric Abrahamsen , 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:01:38 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 1dZ5H3-0003Bf-Nl for geh-help-gnu-emacs@m.gmane.org; Sun, 23 Jul 2017 03:01:33 +0200 Original-Received: from localhost ([::1]:48828 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dZ5H9-0003pC-E7 for geh-help-gnu-emacs@m.gmane.org; Sat, 22 Jul 2017 21:01:39 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:49101) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dZ5GT-0003oS-TO for help-gnu-emacs@gnu.org; Sat, 22 Jul 2017 21:00:59 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dZ5GQ-0001G3-QK for help-gnu-emacs@gnu.org; Sat, 22 Jul 2017 21:00:58 -0400 Original-Received: from aserp1040.oracle.com ([141.146.126.69]:30470) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dZ5GQ-0001FW-Gh for help-gnu-emacs@gnu.org; Sat, 22 Jul 2017 21:00:54 -0400 Original-Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by aserp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id v6N10iqv022166 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sun, 23 Jul 2017 01:00:44 GMT Original-Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserv0021.oracle.com (8.14.4/8.14.4) with ESMTP id v6N10ijO021071 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sun, 23 Jul 2017 01:00:44 GMT Original-Received: from abhmp0015.oracle.com (abhmp0015.oracle.com [141.146.116.21]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id v6N10hKK026145; Sun, 23 Jul 2017 01:00:44 GMT In-Reply-To: <87y3rgq8iy.fsf@ericabrahamsen.net> X-Priority: 3 X-Mailer: Oracle Beehive Extensions for Outlook 2.0.1.9.1 (1003210) [OL 12.0.6770.5000 (x86)] X-Source-IP: aserv0021.oracle.com [141.146.126.233] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] [fuzzy] X-Received-From: 141.146.126.69 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:113831 Archived-At: > 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. >=20 > 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': This function adds KEYMAP as a =E2=80=9Ctransient=E2=80=9D keymap, which = takes precedence over other keymaps for one (or more) subsequent keys. Normally, KEYMAP is used just once, to look up the very next key. If the optional argument KEEP-PRED is =E2=80=98t=E2=80=99, the map stays = active as long as the user types keys defined in KEYMAP; when the user types a key that is not in KEYMAP, the transient keymap is deactivated and normal key lookup continues for that key. The KEEP-PRED argument can also be a function. In that case, the function is called with no arguments, prior to running each command, while KEYMAP is active; it should return non-=E2=80=98nil=E2=80= =99 if KEYMAP should stay active. The optional argument ON-EXIT, if non-nil, specifies a function that is called, with no arguments, after KEYMAP is deactivated. This function works by adding and removing KEYMAP from the variable =E2=80=98overriding-terminal-local-map=E2=80=99, which takes precedence o= ver all other active keymaps (see Searching Keymaps).