emacs-devel
[Top][All Lists]
Advanced

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

Get a command by its keybinding and also respecting key translation


From: Tassilo Horn
Subject: Get a command by its keybinding and also respecting key translation
Date: Mon, 13 Dec 2010 19:57:45 +0100
User-agent: Gnus/5.110011 (No Gnus v0.11) Emacs/24.0.50 (gnu/linux)

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



reply via email to

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