emacs-devel
[Top][All Lists]
Advanced

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

Re: A simple implementation of context-sensitive keys


From: Tassilo Horn
Subject: Re: A simple implementation of context-sensitive keys
Date: Fri, 12 Sep 2008 08:58:02 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux)

"Lennart Borgman (gmail)" <address@hidden> writes:

Hi Lennart,

>> So I guess a first step into the right direction would be to enhance
>> `describe-key' that it doesn't stop if KEY is found, but to list the
>> shadowed commands, too.  Something like
>
> If you say that this is the first step so, yes ... ;-)
>
>> ,----
>> | TAB (translated from <tab>) runs the command message-tab, which is an
>> | interactive compiled Lisp function in
>> | `/usr/share/emacs/23.0.60/lisp/gnus/message.el'.
>> | 
>> | It is bound to TAB in `message-mode-map'.  <== This is new
>
> There is currently no function in Emacs to find the keymap variable
> name.

I think you could reimplement the key lookup procedure you referenced
and don't stop searching when KEY is found.  Then you know the name of
the map.

> However I wrote the command `describe-key-and-map-briefly' that tries
> to find the keymap variable name. This is a bit tricky and I am sure
> that you can construct cases where it does not work. However so far I
> have not found any example where it does not work.

Hey cool.  Here's a function to find all commands bound to key.  The car
is the command which is executed, the cdr is the list of shadowed
commands.

--8<---------------cut here---------------start------------->8---
(defun lookup-key-bindings (key)
  (let (list)
    (dolist (map (current-active-maps))
      (let ((cmd (lookup-key map key)))
        (when (and cmd
                   (not (numberp cmd)))
          (add-to-list 'list cmd t))))
    list))

(lookup-key-bindings (kbd "C-f"))
;; ==C-j==> (paredit-forward forward-char)
--8<---------------cut here---------------end--------------->8---

So we have to combine those functions and are done. ;-)

Bye,
Tassilo




reply via email to

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