[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: find-aliases, where-did-you-go-little-command

From: Stefan Monnier
Subject: Re: find-aliases, where-did-you-go-little-command
Date: Wed, 06 Nov 2002 14:27:04 -0500

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


--- 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
    (let ((fn (function-called-at-point))
         (enable-recursive-minibuffers t)
@@ -420,6 +428,18 @@
      (list (if (equal val "")
               fn (intern val))
+  (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 
         (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 
-             (princ (format "%s (%s)" keys1 definition)))
-         (princ (format "M-x %s RET" definition)))
+                           (format "%s (%s) (remapped from %s)" keys1 remapped 
+                         (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 via email to

[Prev in Thread] Current Thread [Next in Thread]