From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Nicolas Richard Newsgroups: gmane.emacs.bugs Subject: bug#13948: no key-binding-locus Date: Mon, 02 Jun 2014 12:15:34 +0200 Message-ID: <87k38zipmh.fsf@geodiff-mac3.ulb.ac.be> References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1401704139 10829 80.91.229.3 (2 Jun 2014 10:15:39 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 2 Jun 2014 10:15:39 +0000 (UTC) Cc: 13948@debbugs.gnu.org To: Brian Malehorn Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Mon Jun 02 12:15:30 2014 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1WrPH1-0007ub-SQ for geb-bug-gnu-emacs@m.gmane.org; Mon, 02 Jun 2014 12:15:24 +0200 Original-Received: from localhost ([::1]:43972 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WrPH0-0000ew-VM for geb-bug-gnu-emacs@m.gmane.org; Mon, 02 Jun 2014 06:15:22 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:45922) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WrPGr-0000eY-Cp for bug-gnu-emacs@gnu.org; Mon, 02 Jun 2014 06:15:20 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WrPGi-0003xL-Pl for bug-gnu-emacs@gnu.org; Mon, 02 Jun 2014 06:15:13 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:41430) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WrPGi-0003vH-NB for bug-gnu-emacs@gnu.org; Mon, 02 Jun 2014 06:15:04 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1WrPGh-0001r8-KP for bug-gnu-emacs@gnu.org; Mon, 02 Jun 2014 06:15:03 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Nicolas Richard Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 02 Jun 2014 10:15:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 13948 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 13948-submit@debbugs.gnu.org id=B13948.14017040697063 (code B ref 13948); Mon, 02 Jun 2014 10:15:03 +0000 Original-Received: (at 13948) by debbugs.gnu.org; 2 Jun 2014 10:14:29 +0000 Original-Received: from localhost ([127.0.0.1]:40307 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1WrPG9-0001pr-6Z for submit@debbugs.gnu.org; Mon, 02 Jun 2014 06:14:29 -0400 Original-Received: from mxin.ulb.ac.be ([164.15.128.112]:48788) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1WrPG6-0001ph-VU for 13948@debbugs.gnu.org; Mon, 02 Jun 2014 06:14:28 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AhQKAABOjFOkD4Xx/2dsb2JhbABYrmMGmBsBgSh0giUBAQQBeQULCw4TJQ8BBA08E4gtAQMJCLFWm3ABSg2GBBeFVYIDhGSCFgeEQASYCIhOhmSFc4M6Ow Original-Received: from mathsrv4.ulb.ac.be (HELO geodiff-mac3.ulb.ac.be) ([164.15.133.241]) by smtp.ulb.ac.be with ESMTP; 02 Jun 2014 12:14:21 +0200 In-Reply-To: (Brian Malehorn's message of "Wed, 13 Mar 2013 16:34:48 -0400") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.91 (gnu/linux) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:89878 Archived-At: Brian Malehorn writes: > Why isn't there a key equivalent to variable-binding-locus? As > in, a way to figure out where a particular keybinding is coming > from. For example, > So implementing key-binding-locus would only be a small tweak of > the key lookup code: the first time you find the key, just return > the map you found it in, rather than the command it's supposed to > call. IIUC, it's slightly more complicated than just modifying the return value of a function. One reason is that "finding active keymaps" and "looking up keys in keymaps" are done by different bits of the code. By the time keys are being looked up, we don't know where they keymaps came from anymore. Another reason is that some keymaps might not even be stored in any variable (symbol's value cell) at all. Anyway, here's some code that seems to work in some cases (but not when the command was remapped, and not for finding where a mouse event is bound). First is a helper function, then the actual function. Not the cleanest code, but good enough for my .emacs. (defun yf/find-object-in-variables (object &optional pred) "Find all symbols (variables) whose content is the same as OBJECT. PRED defaults to `eq'" (unless pred (setq pred #'eq)) (let ((result)) (mapatoms (lambda (x) (when (and (boundp x) (funcall pred (symbol-value x) object)) (push x result)))) result)) (defun yf/key-binding-locus (key) "Return a list of symbols whose value is the active keymap which holds a binding for the given KEY." (interactive "KKey seq: ") (let ((active-maps (current-active-maps t)) map found) ;; we loop over active-maps like key-binding does. (while (not (setq found (lookup-key (setq map (pop active-maps)) key t))) ;; do nothing ) (if (not found) (message "Key not found (which is weird, if you want my opinion).") (if (and (symbolp found) (command-remapping found)) ;; fixme. We should mimic command-remapping ? (message "Found key but it got remapped and I don't know how to search that.") (let ((res (yf/find-object-in-variables map))) (if res (message "Found key (bound to %s) in a keymap bound to: %S" found res) (message "Found key (bound to %s) in a keymap which isn't in any variable." found))))))) -- Nico.