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: Fri, 06 Jun 2014 19:57:15 +0200 Message-ID: <871tv1gbus.fsf@yahoo.fr> References: <87k38zipmh.fsf@geodiff-mac3.ulb.ac.be> <87k38xhrqr.fsf@yahoo.fr> <87zjhsg4g8.fsf@geodiff-mac3.ulb.ac.be> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1402077515 21346 80.91.229.3 (6 Jun 2014 17:58:35 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 6 Jun 2014 17:58:35 +0000 (UTC) Cc: Nicolas Richard , 13948@debbugs.gnu.org, Brian Malehorn To: Stefan Monnier Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Fri Jun 06 19:58:26 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 1WsyPC-0007WS-7I for geb-bug-gnu-emacs@m.gmane.org; Fri, 06 Jun 2014 19:58:18 +0200 Original-Received: from localhost ([::1]:48779 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WsyPB-0006us-Tz for geb-bug-gnu-emacs@m.gmane.org; Fri, 06 Jun 2014 13:58:17 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:48613) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WsyP3-0006fS-8U for bug-gnu-emacs@gnu.org; Fri, 06 Jun 2014 13:58:15 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WsyOx-0008WB-3t for bug-gnu-emacs@gnu.org; Fri, 06 Jun 2014 13:58:09 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:48680) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WsyOw-0008W7-WD for bug-gnu-emacs@gnu.org; Fri, 06 Jun 2014 13:58:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1WsyOw-00046h-Go for bug-gnu-emacs@gnu.org; Fri, 06 Jun 2014 13:58:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Nicolas Richard Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 06 Jun 2014 17:58:02 +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.140207744615737 (code B ref 13948); Fri, 06 Jun 2014 17:58:02 +0000 Original-Received: (at 13948) by debbugs.gnu.org; 6 Jun 2014 17:57:26 +0000 Original-Received: from localhost ([127.0.0.1]:39830 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1WsyOL-00045l-Gh for submit@debbugs.gnu.org; Fri, 06 Jun 2014 13:57:25 -0400 Original-Received: from mailrelay004.isp.belgacom.be ([195.238.6.170]:54020) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1WsyOI-00045I-FC for 13948@debbugs.gnu.org; Fri, 06 Jun 2014 13:57:23 -0400 X-Belgacom-Dynamic: yes Original-Received: from 8.159-178-91.adsl-dyn.isp.belgacom.be (HELO LDLC-portable) ([91.178.159.8]) by relay.skynet.be with ESMTP; 06 Jun 2014 19:57:15 +0200 In-Reply-To: (Stefan Monnier's message of "Wed, 04 Jun 2014 10:20:37 -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:90148 Archived-At: Stefan Monnier writes: >> to be honest, I did it because (eq widget-global-map global-map) => >> t and I didn't want to see these two results everytime. > > Ah, good point. I think a more general solution would be preferable, > where we provide a list of "advertized vars" and if the keymap is found > in this list, don't look via mapatoms. > > This list of advertized vars could be built dynamically mimicking > current-active-maps. I don't know how to do that. My problem is that when a minor or major mode is defined, the symbol that holds the keymap is not stored afaics. Thus when current-active-maps is run, the information is no more accessible, and mimicking it doesn't bring me much. I could make a list of (intern (format "%s-map" major-mode)) and (intern (format "%s-map" minor-mode)) for currently active minor-modes and check in those. But that will not solve the global map problem, so it still needs some special casing. >>> Could you turn it into a self-contained patch (e.g. move the yf/* >>> functions to help*.el and rename it accordingly)? My current suggestion is as follows. --- a/lisp/help.el +++ b/lisp/help.el @@ -647,6 +647,48 @@ temporarily enables it to allow getting help on disabled items and buttons." (princ (format "%s%s is undefined" key-desc mouse-msg)) (princ (format "%s%s runs the command %S" key-desc mouse-msg defn))))) +(defun key-binding-keymap (key &optional accept-default no-remap _position) + "Determine in which keymap KEY is defined. +When the key was found, return an active keymap in which it was +found." + (let ((active-maps (current-active-maps t)) + map found) + ;; we loop over active maps like key-binding does. + (while (and + (not found) + (setq map (pop active-maps))) + (setq found (lookup-key + map + key + accept-default)) + (when (integerp found) + ;; prefix was found but not the whole sequence + (setq found nil))) + (when found + (if (and (symbolp found) + (not no-remap) + (command-remapping found)) + (key-binding-keymap (vector 'remap found)) + map)))) + +(defun describe-key--binding-locus (key) + "Describe in which keymap KEY is defined. +Return the description (a string) or nil." + (let ((map (key-binding-keymap key t))) + (if (eq map (current-global-map)) + " (found in global map)" + (let ((symbols)) + (mapatoms + (lambda (x) + (when (and (boundp x) + ;; Avoid let-bound symbols + (special-variable-p x) + (eq (symbol-value x) map)) + (push x symbols)))) + (when symbols + (format " (found in %s)" + (mapconcat #'symbol-name symbols ", "))))))) + (defun describe-key (&optional key untranslated up-event) "Display documentation of the function invoked by KEY. KEY can be any kind of a key sequence; it can include keyboard events, @@ -753,9 +795,8 @@ temporarily enables it to allow getting help on disabled items and buttons." (setq defn-up-tricky (key-binding sequence nil nil (event-start up-event)))))) (with-help-window (help-buffer) (princ (help-key-description key untranslated)) - (princ (format "\ -%s runs the command %S, which is " - mouse-msg defn)) + (princ (format "%s runs the command %S%s, which is " + mouse-msg defn (describe-key--binding-locus key))) (describe-function-1 defn) (when up-event (unless (or (null defn-up) -- Nico.