From: Tassilo Horn <tassilo@member.fsf.org>
To: "Lennart Borgman" <lennart.borgman@gmail.com>
Cc: Stefan Monnier <monnier@iro.umontreal.ca>, emacs-devel@gnu.org
Subject: Re: A simple implementation of context-sensitive keys
Date: Fri, 12 Sep 2008 18:13:44 +0200 [thread overview]
Message-ID: <87wshhpcjr.fsf@thinkpad.tsdh.de> (raw)
In-Reply-To: <e01d8a50809120400y2acb2d02u944bec474a755448@mail.gmail.com> (Lennart Borgman's message of "Fri, 12 Sep 2008 13:00:38 +0200")
"Lennart Borgman" <lennart.borgman@gmail.com> 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
next prev parent reply other threads:[~2008-09-12 16:13 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-09-10 7:17 A simple implementation of context-sensitive keys Tassilo Horn
2008-09-10 10:36 ` Lennart Borgman (gmail)
2008-09-10 10:57 ` Tassilo Horn
2008-09-10 16:43 ` Ted Zlatanov
2008-09-10 14:14 ` Sean O'Rourke
2008-09-10 14:48 ` Miles Bader
2008-09-10 14:53 ` Juanma Barranquero
2008-09-10 15:17 ` Sean O'Rourke
2008-09-10 15:32 ` Juanma Barranquero
2008-09-11 7:35 ` Tassilo Horn
2008-09-11 8:17 ` Miles Bader
2008-09-11 8:48 ` Tassilo Horn
2008-09-10 17:49 ` Stefan Monnier
2008-09-10 19:21 ` Tassilo Horn
2008-09-11 1:41 ` Stefan Monnier
2008-09-11 7:17 ` Tassilo Horn
2008-09-11 14:40 ` Ted Zlatanov
2008-09-11 15:53 ` Tassilo Horn
2008-09-11 13:41 ` Lennart Borgman (gmail)
2008-09-11 13:48 ` Lennart Borgman (gmail)
2008-09-11 14:22 ` Tassilo Horn
2008-09-11 20:38 ` Lennart Borgman (gmail)
2008-09-12 6:58 ` Tassilo Horn
2008-09-12 8:34 ` Lennart Borgman (gmail)
2008-09-12 9:47 ` Tassilo Horn
2008-09-12 11:00 ` Lennart Borgman
2008-09-12 16:13 ` Tassilo Horn [this message]
2008-09-12 23:46 ` Lennart Borgman (gmail)
2008-09-13 7:28 ` Tassilo Horn
2008-09-13 9:32 ` Lennart Borgman (gmail)
2008-09-15 7:26 ` Tassilo Horn
2008-09-15 22:39 ` Lennart Borgman (gmail)
2008-09-11 20:44 ` Stefan Monnier
2008-09-11 21:14 ` Lennart Borgman (gmail)
2008-09-12 1:33 ` Stefan Monnier
2008-09-12 8:29 ` Lennart Borgman (gmail)
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=87wshhpcjr.fsf@thinkpad.tsdh.de \
--to=tassilo@member.fsf.org \
--cc=emacs-devel@gnu.org \
--cc=lennart.borgman@gmail.com \
--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.