[Top][All Lists]
[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 18:13:44 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux) |
"Lennart Borgman" <address@hidden> writes:
Hi Lennart,
>> Sorry, no time to write the code now. What I mean is that in
>>
>> (info "(elisp)Searching Keymaps")
>>
>> there's the pseudocode how emacs finds the command for a key. Now
>> you can surrogate "FIND-IN" with lookup-key and see if the key is
>> bound in the map. In that code you know the map or at least the
>> mode, cause you either have the variable directly (like
>> overriding-local-map) or you walk an alist of the form ((mode-name
>> . keymap)...) in the case of FIND-IN-ANY.
>
> It would be good if that where true, but it is not. You have to take a
> closer look to understand how this works. I think a good start might
> be the code I sent before.
Here's a q&d implementation of what I thought should do the trick. It
works for me, although only very briefly tested.
--8<---------------cut here---------------start------------->8---
(defun find-key-commands (key)
(let (list)
(when overriding-terminal-local-map
(let ((c (lookup-key overriding-terminal-local-map key)))
(when (and c
(not (numberp c)))
(add-to-list 'list (cons 'overriding-terminal-local-map c) t))))
(when overriding-local-map
(let ((c (lookup-key overriding-local-map key)))
(when (and c
(not (numberp c)))
(add-to-list 'list (cons 'overriding-local-map c) t))))
(let ((prop-map (get-char-property (point) 'keymap)))
(when prop-map
(let ((c (lookup-key prop-map key)))
(when (and c
(not (numberp c)))
(add-to-list 'list (cons 'char-property-keymap c) t)))))
(dolist (alist '(emulation-mode-map-alists
minor-mode-overriding-map-alist
minor-mode-map-alist))
(dolist (x (symbol-value alist))
(let ((mapname (car x))
(map (cdr x)))
(when map
(let ((c (lookup-key map key)))
(when (and c
(not (numberp c)))
(add-to-list 'list (cons mapname c) t)))))))
(when (get-text-property (point) 'local-map)
(let ((prop-map (get-char-property (point) 'local-map)))
(when prop-map
(let ((c (lookup-key prop-map key)))
(when (and c
(not (numberp c)))
(add-to-list 'list (cons 'char-property-local-map c) t))))))
(when (current-local-map)
(let ((c (lookup-key (current-local-map) key)))
(when (and c
(not (numberp c)))
(add-to-list 'list (cons 'current-local-map c) t))))
(let ((c (lookup-key (current-global-map) key)))
(when (and c
(not (numberp c)))
(add-to-list 'list (cons 'current-global-map c) t)))
list))
(find-key-commands (kbd "M-1"))
;; ==> ((window-number-mode lambda nil (interactive) (window-number-select 1))
(current-global-map . digit-argument))
(find-key-commands (kbd "C-f"))
;; ==> ((paredit-mode . paredit-forward) (current-global-map . forward-char))
--8<---------------cut here---------------end--------------->8---
Bye,
Tassilo
- Re: A simple implementation of context-sensitive keys, (continued)
- Re: A simple implementation of context-sensitive keys, Lennart Borgman (gmail), 2008/09/11
- Re: A simple implementation of context-sensitive keys, Lennart Borgman (gmail), 2008/09/11
- Re: A simple implementation of context-sensitive keys, Tassilo Horn, 2008/09/11
- Re: A simple implementation of context-sensitive keys, Lennart Borgman (gmail), 2008/09/11
- Re: A simple implementation of context-sensitive keys, Tassilo Horn, 2008/09/12
- Re: A simple implementation of context-sensitive keys, Lennart Borgman (gmail), 2008/09/12
- Re: A simple implementation of context-sensitive keys, Tassilo Horn, 2008/09/12
- Re: A simple implementation of context-sensitive keys, Lennart Borgman, 2008/09/12
- Re: A simple implementation of context-sensitive keys,
Tassilo Horn <=
- Re: A simple implementation of context-sensitive keys, Lennart Borgman (gmail), 2008/09/12
- Re: A simple implementation of context-sensitive keys, Tassilo Horn, 2008/09/13
- Re: A simple implementation of context-sensitive keys, Lennart Borgman (gmail), 2008/09/13
- Re: A simple implementation of context-sensitive keys, Tassilo Horn, 2008/09/15
- Re: A simple implementation of context-sensitive keys, Lennart Borgman (gmail), 2008/09/15
- Re: A simple implementation of context-sensitive keys, Stefan Monnier, 2008/09/11
- Re: A simple implementation of context-sensitive keys, Lennart Borgman (gmail), 2008/09/11
- Re: A simple implementation of context-sensitive keys, Stefan Monnier, 2008/09/11
- Re: A simple implementation of context-sensitive keys, Lennart Borgman (gmail), 2008/09/12