all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Tassilo Horn <tassilo@member.fsf.org>
To: emacs-devel@gnu.org
Cc: Stefan Monnier <monnier@iro.umontreal.ca>
Subject: Re: Get a command by its keybinding and also respecting key translation
Date: Wed, 15 Dec 2010 09:21:21 +0100	[thread overview]
Message-ID: <201012150921.22238.tassilo@member.fsf.org> (raw)
In-Reply-To: <jwvvd2wdtm1.fsf-monnier+emacs@gnu.org>

On Tuesday 14 December 2010 20:50:43 Stefan Monnier wrote:
> > (define-context-key outline-minor-mode-map
> >   (kbd "<tab>")
> >   th-outline-context-p
> >   org-cycle)
> 
> You can do it this way:
> 
>   (define-key outline-minor-mode-map
>     (kdb "<tab>")
>     `(menu-item "dummy" org-cycle
>       :filter ,(lambda (cmd)
>                  (if (th-outline-context-p) cmd))))

This is cool, but sadly not equivalent, because I cannot add multiple
binding for one key in the same keymap.  That was the whole intention of
my macro: I hit TAB (or whatever), and it'll execute some command
depending on the context.

In my approach with multiple TAB bindings in one keymap, the last one
defined was the real binding, but if its predicate didn't match, it
delegated to the former binding of TAB (which it had stolen), and if all
predicates of all context keys failed, it would call the original
command.

So do I go to implement that behavior in a more standard way?

The docs state, that the :filter may also switch the REAL-BINDING to
some other command, so I could write a macro that expands according to
your definition with a (cond ((PRED1) (CMD1)) ((PRED2) (CMD2))) instead
of the if.

And is this approach not pretty slow?  I mean, my approach did the
predicate checks only when that key was typed, but I think that your
approach does the checks on any redisplay, right?

Bye,
Tassilo



  parent reply	other threads:[~2010-12-15  8:21 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-12-13 18:57 Get a command by its keybinding and also respecting key translation Tassilo Horn
2010-12-14 19:50 ` Stefan Monnier
2010-12-14 22:51   ` Tassilo Horn
2010-12-18 16:16     ` Stefan Monnier
2010-12-20  8:19       ` Tassilo Horn
2010-12-20 10:09         ` Andreas Schwab
2010-12-20 10:19           ` Tassilo Horn
2010-12-20 10:35             ` David Kastrup
2010-12-20 11:10               ` Tassilo Horn
2010-12-20 11:30                 ` Andreas Schwab
2010-12-15  8:21   ` Tassilo Horn [this message]
2010-12-15 15:27     ` Tassilo Horn
2010-12-15 15:30       ` Davis Herring
2010-12-15 21:20         ` Tassilo Horn
2010-12-15 22:03       ` Get a command by its keybinding and also respecting keytranslation Drew Adams
2010-12-15 22:17         ` Tassilo Horn
2010-12-15 22:39           ` Drew Adams
2010-12-18 16:27           ` Stefan Monnier
2010-12-18 16:23     ` Get a command by its keybinding and also respecting key translation Stefan Monnier

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=201012150921.22238.tassilo@member.fsf.org \
    --to=tassilo@member.fsf.org \
    --cc=emacs-devel@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /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.