unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Drew Adams <drew.adams@oracle.com>
To: Eric Abrahamsen <eric@ericabrahamsen.net>, help-gnu-emacs@gnu.org
Subject: RE: Single-use keybindings?
Date: Sat, 22 Jul 2017 18:00:42 -0700 (PDT)	[thread overview]
Message-ID: <1336c859-9a4f-48d2-a838-81eab9dd0e59@default> (raw)
In-Reply-To: <87y3rgq8iy.fsf@ericabrahamsen.net>

> 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':

  This function adds KEYMAP as a “transient” 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 ‘t’, 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-‘nil’ 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
  ‘overriding-terminal-local-map’, which takes precedence over all
  other active keymaps (see Searching Keymaps).



  reply	other threads:[~2017-07-23  1:00 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-23  0:52 Single-use keybindings? Eric Abrahamsen
2017-07-23  1:00 ` Drew Adams [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1336c859-9a4f-48d2-a838-81eab9dd0e59@default \
    --to=drew.adams@oracle.com \
    --cc=eric@ericabrahamsen.net \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).