help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: Single-use keybindings?


From: Drew Adams
Subject: RE: Single-use keybindings?
Date: Sat, 22 Jul 2017 18:00:42 -0700 (PDT)

> 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 via email to

[Prev in Thread] Current Thread [Next in Thread]