From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Tassilo Horn Newsgroups: gmane.emacs.devel Subject: Re: A simple implementation of context-sensitive keys Date: Fri, 12 Sep 2008 18:13:44 +0200 Message-ID: <87wshhpcjr.fsf@thinkpad.tsdh.de> References: <87y72079mg.fsf@thinkpad.tsdh.de> <87d4jbg62j.fsf@thinkpad.tsdh.de> <48C92024.6080804@gmail.com> <48C921CB.3010700@gmail.com> <87hc8miwy0.fsf@thinkpad.tsdh.de> <48C981C6.9030201@gmail.com> <87abed97gl.fsf@thinkpad.tsdh.de> <48CA29A7.1040501@gmail.com> <87d4j9r90k.fsf@thinkpad.tsdh.de> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1221236170 12828 80.91.229.12 (12 Sep 2008 16:16:10 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 12 Sep 2008 16:16:10 +0000 (UTC) Cc: Stefan Monnier , emacs-devel@gnu.org To: "Lennart Borgman" Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Fri Sep 12 18:17:05 2008 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1KeBKT-0007QB-2F for ged-emacs-devel@m.gmane.org; Fri, 12 Sep 2008 18:17:05 +0200 Original-Received: from localhost ([127.0.0.1]:47907 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KeBJS-00025t-Gl for ged-emacs-devel@m.gmane.org; Fri, 12 Sep 2008 12:16:02 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KeBJO-000255-GY for emacs-devel@gnu.org; Fri, 12 Sep 2008 12:15:58 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KeBJJ-00022m-Ro for emacs-devel@gnu.org; Fri, 12 Sep 2008 12:15:58 -0400 Original-Received: from [199.232.76.173] (port=33327 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KeBJJ-00022j-N4 for emacs-devel@gnu.org; Fri, 12 Sep 2008 12:15:53 -0400 Original-Received: from out1.smtp.messagingengine.com ([66.111.4.25]:46427) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1KeBJJ-0001HO-TW for emacs-devel@gnu.org; Fri, 12 Sep 2008 12:15:54 -0400 Original-Received: from compute1.internal (compute1.internal [10.202.2.41]) by out1.messagingengine.com (Postfix) with ESMTP id E23B6160958; Fri, 12 Sep 2008 12:15:52 -0400 (EDT) Original-Received: from heartbeat1.messagingengine.com ([10.202.2.160]) by compute1.internal (MEProxy); Fri, 12 Sep 2008 12:15:52 -0400 X-Sasl-enc: 03W2ifC4Rmb+ci7w1AafyA4zbsyjUpv7bOU1F7CE2sFD 1221236152 Original-Received: from thinkpad.tsdh.de (p54AF2367.dip0.t-ipconnect.de [84.175.35.103]) by mail.messagingengine.com (Postfix) with ESMTPA id 3693913ACD; Fri, 12 Sep 2008 12:15:50 -0400 (EDT) Mail-Copies-To: never Mail-Followup-To: "Lennart Borgman" , "Stefan Monnier" , emacs-devel@gnu.org In-Reply-To: (Lennart Borgman's message of "Fri, 12 Sep 2008 13:00:38 +0200") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux) X-detected-kernel: by monty-python.gnu.org: Genre and OS details not recognized. X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:103849 Archived-At: "Lennart Borgman" 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