From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: "Stefan Monnier" Newsgroups: gmane.emacs.devel Subject: Re: find-aliases, where-did-you-go-little-command Date: Wed, 06 Nov 2002 14:27:04 -0500 Sender: emacs-devel-admin@gnu.org Message-ID: <200211061927.gA6JR4M04002@rum.cs.yale.edu> References: <20021021134029.2852.LEKTU@terra.es> <20021106184041.66CB.LEKTU@terra.es> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: main.gmane.org 1036611847 32615 80.91.224.249 (6 Nov 2002 19:44:07 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Wed, 6 Nov 2002 19:44:07 +0000 (UTC) Cc: rms@gnu.org, emacs-devel@gnu.org Return-path: Original-Received: from quimby.gnus.org ([80.91.224.244]) by main.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 189W5F-0008RC-00 for ; Wed, 06 Nov 2002 20:43:25 +0100 Original-Received: from monty-python.gnu.org ([199.232.76.173]) by quimby.gnus.org with esmtp (Exim 3.12 #1 (Debian)) id 189WDs-0001tg-00 for ; Wed, 06 Nov 2002 20:52:21 +0100 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.10) id 189W2z-0005rg-00; Wed, 06 Nov 2002 14:41:05 -0500 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.10) id 189Vpm-0002OX-00 for emacs-devel@gnu.org; Wed, 06 Nov 2002 14:27:26 -0500 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.10) id 189Vpi-0002O7-00 for emacs-devel@gnu.org; Wed, 06 Nov 2002 14:27:24 -0500 Original-Received: from rum.cs.yale.edu ([128.36.229.169]) by monty-python.gnu.org with esmtp (Exim 4.10) id 189Vpd-0002MT-00; Wed, 06 Nov 2002 14:27:17 -0500 Original-Received: (from monnier@localhost) by rum.cs.yale.edu (8.11.6/8.11.6) id gA6JR4M04002; Wed, 6 Nov 2002 14:27:04 -0500 X-Mailer: exmh version 2.4 06/23/2000 with nmh-1.0.4 Original-To: Juanma Barranquero Errors-To: emacs-devel-admin@gnu.org X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.0.11 Precedence: bulk List-Help: List-Post: List-Subscribe: , List-Id: Emacs development discussions. List-Unsubscribe: , List-Archive: Xref: main.gmane.org gmane.emacs.devel:9199 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:9199 > > This seems like a useful feature for where-is. > Here's a first cut at an implementation. Some people (such as yours truly) like to read patches ;-) So after reformatting your code to bring it closer to the original, and use C-x v = to see the corresponding patch, I think it looks fine. I'd use `fboundp' before calling indirect-function, so that ignore-errors shouldn't be necessary (and it also makes the loop significantly faster since you don't need to setup an error handler for each and every symbol). > 1.- I've put a variable `where-is-show-aliases' to activate the new > behavior. In the code below it is set to t, but perhaps nil would be a > better default. I would hardcode it to t and not even bother with a customization. > 2.- The output format is not very elaborated. Better suggestions very > welcome. My minibuffer can't grow and can only show a single line, so I'm a bit annoyed by the ";\nand" part. I understand that for the "normal" case it's better. I'm not sure how to get the best of both worlds. Please try to stay within 80 columns. I know the original source doesn't, but that's just a good reason to try and fix it, rather than make it worse. Stefan --- help.el.~1.252.~ Tue Jul 16 12:06:18 2002 +++ help.el Wed Nov 6 14:03:54 2002 @@ -405,10 +405,18 @@ (with-current-buffer standard-output (describe-buffer-bindings buf prefix menus))))) +(defcustom where-is-show-aliases t + "*Whether `where-is' must also show keybindings for aliases." + :type 'boolean + :group 'help + :version "21.4") + (defun where-is (definition &optional insert) "Print message listing key sequences that invoke the command DEFINITION. Argument is a command definition, usually a symbol with a function definition. -If INSERT (the prefix arg) is non-nil, insert the message in the buffer." +If INSERT (the prefix arg) is non-nil, insert the message in the buffer. +If `where-is-show-aliases is non-nil, show also keybindings for aliases +of DEFINITION." (interactive (let ((fn (function-called-at-point)) (enable-recursive-minibuffers t) @@ -420,6 +428,18 @@ (list (if (equal val "") fn (intern val)) current-prefix-arg))) + (let ((func (indirect-function definition)) + (defs nil) + (def definition) + (standard-output (if insert (current-buffer) t))) + (when where-is-show-aliases + (mapatoms #'(lambda (symbol) + (and (fboundp symbol) + (eq func (indirect-function symbol)) + (not (eq symbol definition)) + (push symbol defs))))) + (princ (mapconcat + (lambda (definition) (let* ((remapped (remap-command definition)) (keys (where-is-internal definition overriding-local-map nil nil remapped)) (keys1 (mapconcat 'key-description keys ", ")) @@ -427,15 +447,16 @@ (if insert (if (> (length keys1) 0) (if remapped - (princ (format "%s (%s) (remapped from %s)" keys1 remapped definition)) - (princ (format "%s (%s)" keys1 definition))) - (princ (format "M-x %s RET" definition))) + (format "%s (%s) (remapped from %s)" keys1 remapped definition) + (format "%s (%s)" keys1 definition)) + (format "M-x %s RET" definition)) (if (> (length keys1) 0) (if remapped - (princ (format "%s is remapped to %s which is on %s" definition remapped keys1)) - (princ (format "%s is on %s" definition keys1))) - (princ (format "%s is not on any key" definition))))) - nil) + (format "%s is remapped to %s which is on %s" def definition keys1) + (format "%s is on %s" definition keys1)) + (format "%s is not on any key" definition))))) + (cons def defs) + "; and ")))) (defun string-key-binding (key) "Value is the binding of KEY in a string.