unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: "Stefan Monnier" <monnier+gnu/emacs@rum.cs.yale.edu>
Cc: rms@gnu.org, emacs-devel@gnu.org
Subject: Re: find-aliases, where-did-you-go-little-command
Date: Wed, 06 Nov 2002 14:27:04 -0500	[thread overview]
Message-ID: <200211061927.gA6JR4M04002@rum.cs.yale.edu> (raw)
In-Reply-To: 20021106184041.66CB.LEKTU@terra.es

> > 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.

  reply	other threads:[~2002-11-06 19:27 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-10-21 11:50 find-aliases, where-did-you-go-little-command Juanma Barranquero
2002-10-22  3:13 ` Richard Stallman
2002-10-22  8:46   ` Juanma Barranquero
2002-10-22 14:28     ` Stefan Monnier
2002-10-22 14:41       ` Juanma Barranquero
2002-10-23  7:12       ` Richard Stallman
2002-10-23  7:35         ` Stefan Monnier
2002-11-06 17:44   ` Juanma Barranquero
2002-11-06 19:27     ` Stefan Monnier [this message]
2002-11-06 21:49       ` Juanma Barranquero
2002-11-07  7:23         ` Kai Großjohann
2002-11-07 15:08     ` Richard Stallman
2002-11-07 16:52       ` Juanma Barranquero

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

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200211061927.gA6JR4M04002@rum.cs.yale.edu \
    --to=monnier+gnu/emacs@rum.cs.yale.edu \
    --cc=emacs-devel@gnu.org \
    --cc=rms@gnu.org \
    /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 public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).