unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Get a command by its keybinding and also respecting key translation
@ 2010-12-13 18:57 Tassilo Horn
  2010-12-14 19:50 ` Stefan Monnier
  0 siblings, 1 reply; 19+ messages in thread
From: Tassilo Horn @ 2010-12-13 18:57 UTC (permalink / raw)
  To: emacs-devel

Hi all,

is there a way to get a command by its keybinding that also respects key
translation?  Or more precise: Is there a way to get the binding of KEY,
and if there's none, get the binding of some other key that happens to
translate to KEY (and if there are more than one, then check them in the
order the that would be used when really looking up a key a user typed)?

The reason for that question is a home-brewn macro that enables me to
define a key for some keymap just like define-key, but with an
additional predicate that is tested before executing the given command.
If the predicate does not match, then the binding should execute the
command that would have been executed normally.

Now the problem is getting the command that would have been executed
before.  The problem with `lookup-key' and `key-binding' which I
currently use is that they don't handle key translation.

Here's an example:

(define-context-key outline-minor-mode-map
  (kbd "<tab>")
  th-outline-context-p
  org-cycle)

This will first use `lookup-key' to check if there's already a <tab>
binding in `outline-minor-mode-map', and if not, the expandsion will
let-bind the given map's mode variable (e.g. `outline-minor-mode') and
then check the `key-binding' of <tab> and execute that function.

Ok, now to the problem: I use `outline-minor-mode' in most programming
modes, and those usually define TAB to `indent-according-to-mode'.  But
since TAB is only translated to <tab>, (key-binding (kbd "<tab>")) will
return nil.

Bye,
Tassilo



^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2010-12-20 11:30 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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

Code repositories for project(s) associated with this public inbox

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

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).