all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@iro.umontreal.ca>
To: help-gnu-emacs@gnu.org
Subject: Re: Short-circuiting keybindings?
Date: Wed, 10 Nov 2010 13:19:41 -0500	[thread overview]
Message-ID: <jwvy691oxjl.fsf-monnier+gnu.emacs.help@gnu.org> (raw)
In-Reply-To: 614cd66c-4814-4f58-89b7-cfdc067cc620@d8g2000yqf.googlegroups.com

> is there a generic way to create "short-circuiting" keybindings?  I
> mean: let's say I want "C-b" to issue a command only whenever a
> condition is met, otherwise if "C-b" is a prefix key then Emacs should
> continue listening for keystrokes and execute commands when
> appropriate.

You can create conditional key bindings:

  (define-key map [?\C-b] '(menu-item "dummy" <command>
                            :filter (lambda (binding)
                                      (if <condition> binding))))
                                      
The filter function will receive <command> as argument (this is so that
the same filter function can be used for several bindings) and can opt
to return it or not or to return anything else (so you can create
dynamic bindings, which is typically used to construct dynamic menus,
such as the Buffers menu).
The <command> you put as the "static binding" that gets passed to the
filter is only used in cases such as where-is.


        Stefan


      parent reply	other threads:[~2010-11-10 18:19 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-11-09 21:06 Short-circuiting keybindings? Elena
     [not found] ` <87k4kmf3at.fsf@kuiper.lan.informatimago.com>
2010-11-10 11:15   ` Elena
2010-11-10 18:19 ` Stefan Monnier [this message]

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

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

  git send-email \
    --in-reply-to=jwvy691oxjl.fsf-monnier+gnu.emacs.help@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --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.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.