unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* find-aliases, where-did-you-go-little-command
@ 2002-10-21 11:50 Juanma Barranquero
  2002-10-22  3:13 ` Richard Stallman
  0 siblings, 1 reply; 13+ messages in thread
From: Juanma Barranquero @ 2002-10-21 11:50 UTC (permalink / raw)


I'm thinking that it'd be nice to have a find-aliases function, more or
less like:

 (eval-when-compile
  (require 'cl))

 (defun find-aliases (function &optional ob-array)
   (let ((func (indirect-function function))
         (list nil))
     (mapatoms #'(lambda (symbol)
                   (when (eq func (ignore-errors (indirect-function symbol)))
                     (push symbol list)))
               ob-array)
     list))

(with a suitable docstring, of course) that would help find all aliases
for a function (please don't tell me there's already an easier way :)

I think it could be useful in itself, but the main reason is that I'd
like to extend where-is, or perhaps supply an alternative where-*
command, to show the keybindings for a function, *even* if I'm searching
it through an unbound alias.

After all, knowing that `hi-lock-face-buffer' is not bound to any key
does not help me find the *very same* functionality, bound to [C-x w h]
with the name `highlight-regexp'...

Any comments?


                                                           /L/e/k/t/u

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: find-aliases, where-did-you-go-little-command
  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-11-06 17:44   ` Juanma Barranquero
  0 siblings, 2 replies; 13+ messages in thread
From: Richard Stallman @ 2002-10-22  3:13 UTC (permalink / raw)
  Cc: emacs-devel

    I think it could be useful in itself, but the main reason is that I'd
    like to extend where-is, or perhaps supply an alternative where-*
    command, to show the keybindings for a function, *even* if I'm searching
    it through an unbound alias.

This seems like a useful feature for where-is.  The function itself
is so simple that I see no need for it as a subroutine.  (That would
make extra trouble, such as that people would want to put it in the
Lisp manual.)

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: find-aliases, where-did-you-go-little-command
  2002-10-22  3:13 ` Richard Stallman
@ 2002-10-22  8:46   ` Juanma Barranquero
  2002-10-22 14:28     ` Stefan Monnier
  2002-11-06 17:44   ` Juanma Barranquero
  1 sibling, 1 reply; 13+ messages in thread
From: Juanma Barranquero @ 2002-10-22  8:46 UTC (permalink / raw)
  Cc: emacs-devel

On Mon, 21 Oct 2002 23:13:38 -0400, Richard Stallman <rms@gnu.org> wrote:

> This seems like a useful feature for where-is.

OK, I'll work on it.

> The function itself is so simple that I see no need for it as a subroutine.

OK. We can add it later if it happens to be useful in more places.

                                                           /L/e/k/t/u

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: find-aliases, where-did-you-go-little-command
  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
  0 siblings, 2 replies; 13+ messages in thread
From: Stefan Monnier @ 2002-10-22 14:28 UTC (permalink / raw)
  Cc: rms, emacs-devel

> > The function itself is so simple that I see no need for it as a subroutine.
> OK. We can add it later if it happens to be useful in more places.

I think there's a misunderstanding here.  A `subroutine' is not just
any random function, but it's a function that's implemented in C
(hence `subrp' and `subr-arity').
Kind of like the difference between `function' and `command'.


	Stefan

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: find-aliases, where-did-you-go-little-command
  2002-10-22 14:28     ` Stefan Monnier
@ 2002-10-22 14:41       ` Juanma Barranquero
  2002-10-23  7:12       ` Richard Stallman
  1 sibling, 0 replies; 13+ messages in thread
From: Juanma Barranquero @ 2002-10-22 14:41 UTC (permalink / raw)
  Cc: rms, emacs-devel

On Tue, 22 Oct 2002 10:28:33 -0400, "Stefan Monnier" <monnier+gnu/emacs@rum.cs.yale.edu> wrote:

> I think there's a misunderstanding here.  A `subroutine' is not just
> any random function, but it's a function that's implemented in C
> (hence `subrp' and `subr-arity').

Well, you're right. I think we just weren't using the language in such a
precise way :)

I interpreted Richard's comment as saying that not every tiny piece of
code has to be a routine (be that a C soubrutine or an elisp function).

                                                           /L/e/k/t/u

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: find-aliases, where-did-you-go-little-command
  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
  1 sibling, 1 reply; 13+ messages in thread
From: Richard Stallman @ 2002-10-23  7:12 UTC (permalink / raw)
  Cc: lektu, emacs-devel

    I think there's a misunderstanding here.

I think he understood me correctly.

					      A `subroutine' is not just
    any random function, but it's a function that's implemented in C
    (hence `subrp' and `subr-arity').

That is not our normal usage.  A subroutine can be written in any
language.  The subroutine I was talking about was the separate Lisp
function find-aliases that he proposed.  There is no need for it as a
separate function and that would be more trouble than it is worth.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: find-aliases, where-did-you-go-little-command
  2002-10-23  7:12       ` Richard Stallman
@ 2002-10-23  7:35         ` Stefan Monnier
  0 siblings, 0 replies; 13+ messages in thread
From: Stefan Monnier @ 2002-10-23  7:35 UTC (permalink / raw)
  Cc: monnier+gnu/emacs, lektu, emacs-devel

>     I think there's a misunderstanding here.
> 
> I think he understood me correctly.
> 
> 					      A `subroutine' is not just
>     any random function, but it's a function that's implemented in C
>     (hence `subrp' and `subr-arity').
> 
> That is not our normal usage.  A subroutine can be written in any
> language.  The subroutine I was talking about was the separate Lisp
> function find-aliases that he proposed.  There is no need for it as a
> separate function and that would be more trouble than it is worth.

So the misunderstanding was only on my side.


	Stefan "who likes small reusable functions"

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: find-aliases, where-did-you-go-little-command
  2002-10-22  3:13 ` Richard Stallman
  2002-10-22  8:46   ` Juanma Barranquero
@ 2002-11-06 17:44   ` Juanma Barranquero
  2002-11-06 19:27     ` Stefan Monnier
  2002-11-07 15:08     ` Richard Stallman
  1 sibling, 2 replies; 13+ messages in thread
From: Juanma Barranquero @ 2002-11-06 17:44 UTC (permalink / raw)
  Cc: emacs-devel

On Mon, 21 Oct 2002 23:13:38 -0400, Richard Stallman <rms@gnu.org> wrote:

> This seems like a useful feature for where-is.

Here's a first cut at an implementation.

Points to take into account:

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.

2.- The output format is not very elaborated. Better suggestions very
welcome.

3.- Same, and more so, for the "insert" behavior of `where-is'.

Comments?

Thanks,

                                                           /L/e/k/t/u




(eval-when-compile
 (require 'cl))

(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 `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)
	 val)
     (setq val (completing-read (if fn
				    (format "Where is command (default %s): " fn)
				  "Where is command: ")
				obarray 'commandp t))
     (list (if (equal val "")
	       fn (intern val))
	   current-prefix-arg)))
  (let ((func (indirect-function definition))
        (map nil)
        (standard-output (if insert (current-buffer) t)))
    (when where-is-show-aliases
      (mapatoms #'(lambda (symbol)
                    (when (and (not (eq symbol definition))
                               (eq func (ignore-errors (indirect-function symbol))))
                      (setq map (cons symbol map))))))
    (princ (mapconcat #'(lambda (symbol)
                          (let* ((remapped (remap-command symbol))
                                 (keys (mapconcat 'key-description
                                                  (where-is-internal symbol overriding-local-map nil nil remapped)
                                                  ", ")))
                            (if insert
                                (if (> (length keys) 0)
                                    (if remapped
                                        (format "%s (%s) (remapped from %s)" keys remapped symbol)
                                      (format "%s (%s)" keys symbol))
                                  (format "M-x %s RET" symbol))
                              (if (> (length keys) 0)
                                  (if remapped
                                      (format "%s is remapped to %s which is on %s" definition symbol keys)
                                    (format "%s is on %s" symbol keys))
                                (format "%s is not on any key" symbol)))))
                      (cons definition map)
                      ";\nand "))))

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: find-aliases, where-did-you-go-little-command
  2002-11-06 17:44   ` Juanma Barranquero
@ 2002-11-06 19:27     ` Stefan Monnier
  2002-11-06 21:49       ` Juanma Barranquero
  2002-11-07 15:08     ` Richard Stallman
  1 sibling, 1 reply; 13+ messages in thread
From: Stefan Monnier @ 2002-11-06 19:27 UTC (permalink / raw)
  Cc: rms, emacs-devel

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

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: find-aliases, where-did-you-go-little-command
  2002-11-06 19:27     ` Stefan Monnier
@ 2002-11-06 21:49       ` Juanma Barranquero
  2002-11-07  7:23         ` Kai Großjohann
  0 siblings, 1 reply; 13+ messages in thread
From: Juanma Barranquero @ 2002-11-06 21:49 UTC (permalink / raw)
  Cc: rms, emacs-devel


On Wed, 06 Nov 2002 14:27:04 -0500
"Stefan Monnier" <monnier+gnu/emacs@rum.cs.yale.edu> wrote:

> Some people (such as yours truly) like to read patches ;-)

I generally send patches, but I felt it'd be easier this way. Sorry.

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

Good idea, I'll try it as you suggest.

> I would hardcode it to t and not even bother with a customization.

That's what I'd rather do, but as it is a change wrt previous behavior,
I didn't want to impose my style. Anyway, there aren't that many aliased
commands, so even as default people won't see much difference.

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

Me neither. Let's hear more opinions about that.

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

OK.

Thanks for your input,

-- 
Juanma Barranquero <lektu@terra.es>

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: find-aliases, where-did-you-go-little-command
  2002-11-06 21:49       ` Juanma Barranquero
@ 2002-11-07  7:23         ` Kai Großjohann
  0 siblings, 0 replies; 13+ messages in thread
From: Kai Großjohann @ 2002-11-07  7:23 UTC (permalink / raw)


Juanma Barranquero <lektu@terra.es> writes:

> Me neither. Let's hear more opinions about that.

May I suggest you commit it and turn it on by default?  Then lazy
people like me will sooner or later stumble across the new behavior
and form an opinion :-)

kai
-- 
~/.signature is: umop ap!sdn    (Frank Nobis)

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: find-aliases, where-did-you-go-little-command
  2002-11-06 17:44   ` Juanma Barranquero
  2002-11-06 19:27     ` Stefan Monnier
@ 2002-11-07 15:08     ` Richard Stallman
  2002-11-07 16:52       ` Juanma Barranquero
  1 sibling, 1 reply; 13+ messages in thread
From: Richard Stallman @ 2002-11-07 15:08 UTC (permalink / raw)
  Cc: emacs-devel

    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.

Few people will try it if it is not on by default.
It is harmless, right?  So turn it on by default.

    3.- Same, and more so, for the "insert" behavior of `where-is'.

In the current code, this feature inserts the same text that would
otherwise be displayed in another buffer.  It looks like that is true
in your version also.  So why say "and more so"?

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: find-aliases, where-did-you-go-little-command
  2002-11-07 15:08     ` Richard Stallman
@ 2002-11-07 16:52       ` Juanma Barranquero
  0 siblings, 0 replies; 13+ messages in thread
From: Juanma Barranquero @ 2002-11-07 16:52 UTC (permalink / raw)
  Cc: emacs-devel

On Thu, 07 Nov 2002 10:08:52 -0500, Richard Stallman <rms@gnu.org> wrote:

> Few people will try it if it is not on by default.
> It is harmless, right?  So turn it on by default.

I've followed Stefan's suggestion and hardcoded it to be on by default.
If later it is decided to make it customizable is just a matter of
adding a variable and a two-lines change to `where-is'.

Then I've followed Kai's suggestion and commited it ;)

> In the current code, this feature inserts the same text that would
> otherwise be displayed in another buffer.  It looks like that is true
> in your version also.  So why say "and more so"?

In both the code before and after my patch, C-u C-h w does not insert
the exact same text that C-h w shows. Consider:

 C-h w hi-lock-face-buffer =>

  hi-lock-face-buffer is not on any key;
  and highlight-regexp is on C-x w h, <menu-bar> <edit> <hi-lock> <highlight-regexp>

 C-u C-h w hi-lock-face-buffer =>

  M-x hi-lock-face-buffer RET;
  and C-x w h, <menu-bar> <edit> <hi-lock> <highlight-regexp> (highlight-regexp)

The first format is more descriptive, so adding "and " seems more natural.

                                                           /L/e/k/t/u

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2002-11-07 16:52 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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

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