unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* IDE features:  M-x find-grep
@ 2008-04-27 20:36 Davi Leal
  2008-04-27 21:12 ` Phil Jackson
  2008-04-27 21:48 ` Kim F. Storm
  0 siblings, 2 replies; 19+ messages in thread
From: Davi Leal @ 2008-04-27 20:36 UTC (permalink / raw)
  To: emacs-devel

"find-grep" lists the matches too under the CVS, .svn, .git, ... directories.

Other IDEs avoid to list matches on repository specific files. They only list 
matches in source code files.


find-grep could detect it is going to process a CVS, SVN or Git repository and 
so prune such directories:  -path '*/.svn' -prune

So, instead of the current find-grep default command [1], emacs could offer 
one which prune the repository control directories [2], [3], ...

 [1] find . -type f -print0 | xargs -0 -e grep -nH -e 

 [2] find . -path '*/CVS' -prune -o -type f -print |  xargs -e grep -I -n -e
 [3] find . -path '*/.svn' -prune -o -type f -print |  xargs -e grep -I -n -e

Can such behavior be got just configuring .emacs?


--
gnuherds.org   The democratic FS job site.




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

* Re: IDE features:  M-x find-grep
  2008-04-27 20:36 IDE features: M-x find-grep Davi Leal
@ 2008-04-27 21:12 ` Phil Jackson
  2008-04-27 22:10   ` Davi Leal
  2008-04-27 21:48 ` Kim F. Storm
  1 sibling, 1 reply; 19+ messages in thread
From: Phil Jackson @ 2008-04-27 21:12 UTC (permalink / raw)
  To: Davi Leal; +Cc: emacs-devel

Davi Leal <davi@leals.com> writes:

> So, instead of the current find-grep default command [1], emacs could
> offer one which prune the repository control directories [2], [3], ...
>
>  [1] find . -type f -print0 | xargs -0 -e grep -nH -e 
>
>  [2] find . -path '*/CVS' -prune -o -type f -print | xargs -e grep -I
>  -n -e [3] find . -path '*/.svn' -prune -o -type f -print | xargs -e
>  grep -I -n -e
>
> Can such behavior be got just configuring .emacs?

It's customisable in 'Grep Find Command' (in the group 'grep').

Cheers,
Phil
-- 
 Phil Jackson
 http://www.shellarchive.co.uk




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

* Re: IDE features:  M-x find-grep
  2008-04-27 20:36 IDE features: M-x find-grep Davi Leal
  2008-04-27 21:12 ` Phil Jackson
@ 2008-04-27 21:48 ` Kim F. Storm
  2008-04-27 22:44   ` Davi Leal
  2008-05-02 23:46   ` Juri Linkov
  1 sibling, 2 replies; 19+ messages in thread
From: Kim F. Storm @ 2008-04-27 21:48 UTC (permalink / raw)
  To: Davi Leal; +Cc: emacs-devel

Davi Leal <davi@leals.com> writes:

> "find-grep" lists the matches too under the CVS, .svn, .git, ... directories.

M-x rgrep doesn't...

-- 
Kim F. Storm <storm@cua.dk> http://www.cua.dk





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

* Re: IDE features:  M-x find-grep
  2008-04-27 21:12 ` Phil Jackson
@ 2008-04-27 22:10   ` Davi Leal
  0 siblings, 0 replies; 19+ messages in thread
From: Davi Leal @ 2008-04-27 22:10 UTC (permalink / raw)
  To: emacs-devel; +Cc: Phil Jackson

Phil Jackson wrote:
> > So, instead of the current find-grep default command [1], emacs could
> > offer one which prune the repository control directories [2], [3], ...
> >
> >  [1] find . -type f -print0 | xargs -0 -e grep -nH -e
[...]
> > Can such behavior be got just configuring .emacs?
>
> It's customisable in 'Grep Find Command' (in the group 'grep').

Thanks Phil, it works for me.


However, following the IDE idea, maybe it could be good emacs adding 
such "prune directory" automatically depending on if the user ask for 
find-grep on a CVS, SVN or other repository type:

That is to say, automatic selection of the prune part of the find-grep 
command:

    -path '*/CVS' -prune
    -path '*/.svn' -prune
    -path '*/.git' -prune
    ...

That to emulate the find-grep result and behavior of IDEs as eclipse, etc.




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

* Re: IDE features:  M-x find-grep
  2008-04-27 21:48 ` Kim F. Storm
@ 2008-04-27 22:44   ` Davi Leal
  2008-05-02 23:46   ` Juri Linkov
  1 sibling, 0 replies; 19+ messages in thread
From: Davi Leal @ 2008-04-27 22:44 UTC (permalink / raw)
  To: emacs-devel; +Cc: Kim F. Storm

Kim F. Storm wrote:
> > "find-grep" lists the matches too under the CVS, .svn, .git, ...
> > directories.
>
> M-x rgrep doesn't...

A more clever command!  Thanks.




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

* Re: IDE features:  M-x find-grep
  2008-04-27 21:48 ` Kim F. Storm
  2008-04-27 22:44   ` Davi Leal
@ 2008-05-02 23:46   ` Juri Linkov
  2008-05-03  0:27     ` Lennart Borgman (gmail)
  1 sibling, 1 reply; 19+ messages in thread
From: Juri Linkov @ 2008-05-02 23:46 UTC (permalink / raw)
  To: Kim F. Storm; +Cc: Davi Leal, emacs-devel

>> "find-grep" lists the matches too under the CVS, .svn, .git, ... directories.
>
> M-x rgrep doesn't...

Then why this very useful command is hidden from the users?
Maybe add it to the menu?

Also what do you think about ignoring more useless files in rgrep and lgrep
like below?

Index: emacs/lisp/progmodes/grep.el
@@ -690,7 +702,16 @@
 	(setq command (grep-expand-template
 		       grep-template
 		       regexp
-		       files))
+		       files
+		       (concat "\\("
+			       (and completion-ignored-extensions
+				    (concat " -name '*"
+					    (mapconcat #'identity
+						       completion-ignored-extensions
+						       "' -o -name '*")
+					    "'"))
+			       " -name '*~' -o -name '#*' -o -name '.#*' \\) -o ")
+		       ))
 	(when command
 	  (if (equal current-prefix-arg '(4))
 	      (setq command
@@ -768,7 +789,17 @@
 					       " -o -path ")
 				    " "
 				    (shell-quote-argument ")")
-				    " -prune -o ")))))
+				    " -prune -o "
+				    (shell-quote-argument "(")
+				    (and completion-ignored-extensions
+					 (concat " -name '*"
+						 (mapconcat #'identity
+							    completion-ignored-extensions
+							    "' -o -name '*")
+						 "'"))
+				    " -name '*~' -o -name '#*' -o -name '.#*' "
+				    (shell-quote-argument ")") " -o "
+				    )))))
 	(when command
 	  (if current-prefix-arg
 	      (setq command

-- 
Juri Linkov
http://www.jurta.org/emacs/




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

* Re: IDE features:  M-x find-grep
  2008-05-02 23:46   ` Juri Linkov
@ 2008-05-03  0:27     ` Lennart Borgman (gmail)
  2008-05-03 21:01       ` Richard M Stallman
  0 siblings, 1 reply; 19+ messages in thread
From: Lennart Borgman (gmail) @ 2008-05-03  0:27 UTC (permalink / raw)
  To: Juri Linkov; +Cc: emacs-devel, Davi Leal, Kim F. Storm

Juri Linkov wrote:
>>> "find-grep" lists the matches too under the CVS, .svn, .git, ... directories.
>> M-x rgrep doesn't...
> 
> Then why this very useful command is hidden from the users?
> Maybe add it to the menu?
> 
> Also what do you think about ignoring more useless files in rgrep and lgrep
> like below?

Yes, I use to say that they should be in the Edit menu every time we 
discuss this ... ;-)

Seriously, they are very useful and I see no reason not to put them 
there. And `occur' and `multi-occur' should be there too, of course.


I would also prefer removing grep from the Tools menu. This is an 
advanced command.




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

* Re: IDE features:  M-x find-grep
  2008-05-03  0:27     ` Lennart Borgman (gmail)
@ 2008-05-03 21:01       ` Richard M Stallman
  2008-05-03 23:03         ` Juri Linkov
  2008-05-04  2:04         ` Lennart Borgman (gmail)
  0 siblings, 2 replies; 19+ messages in thread
From: Richard M Stallman @ 2008-05-03 21:01 UTC (permalink / raw)
  To: Lennart Borgman (gmail); +Cc: juri, storm, davi, emacs-devel

    Yes, I use to say that they should be in the Edit menu every time we 
    discuss this ... ;-)

    Seriously, they are very useful and I see no reason not to put them 
    there. And `occur' and `multi-occur' should be there too, of course.

There are lots of commands that are "worth putting in the menu" if we
judge by their usefulness.  But if we put them all in the menu it will
be so big it is inconvenient to use.  So arguing that "this command is
worth including" is not a good way to think about the question.




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

* Re: IDE features:  M-x find-grep
  2008-05-03 21:01       ` Richard M Stallman
@ 2008-05-03 23:03         ` Juri Linkov
  2008-05-04  1:16           ` Re[2]: " Eric M. Ludlam
  2008-05-04 20:07           ` Richard M Stallman
  2008-05-04  2:04         ` Lennart Borgman (gmail)
  1 sibling, 2 replies; 19+ messages in thread
From: Juri Linkov @ 2008-05-03 23:03 UTC (permalink / raw)
  To: rms; +Cc: davi, storm, Lennart Borgman (gmail), emacs-devel

>     Yes, I use to say that they should be in the Edit menu every time we
>     discuss this ... ;-)
>
>     Seriously, they are very useful and I see no reason not to put them
>     there. And `occur' and `multi-occur' should be there too, of course.
>
> There are lots of commands that are "worth putting in the menu" if we
> judge by their usefulness.  But if we put them all in the menu it will
> be so big it is inconvenient to use.  So arguing that "this command is
> worth including" is not a good way to think about the question.

The menu is not necessarily flat.  Using submenus it would be possible
to organize most useful commands in a convenient way.  For instance,
the "Search" menu could have submenus "Search files" for the grep family
of commands, and "Search buffers" for the occur family of commands.

-- 
Juri Linkov
http://www.jurta.org/emacs/




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

* Re[2]: IDE features:  M-x find-grep
  2008-05-03 23:03         ` Juri Linkov
@ 2008-05-04  1:16           ` Eric M. Ludlam
  2008-05-04  2:05             ` Lennart Borgman (gmail)
  2008-05-04 20:07           ` Richard M Stallman
  1 sibling, 1 reply; 19+ messages in thread
From: Eric M. Ludlam @ 2008-05-04  1:16 UTC (permalink / raw)
  To: Juri Linkov; +Cc: lennart.borgman, emacs-devel, davi, rms, storm

>>> Juri Linkov <juri@jurta.org> seems to think that:
>>     Yes, I use to say that they should be in the Edit menu every time we
>>     discuss this ... ;-)
>>
>>     Seriously, they are very useful and I see no reason not to put them
>>     there. And `occur' and `multi-occur' should be there too, of course.
>>
>> There are lots of commands that are "worth putting in the menu" if we
>> judge by their usefulness.  But if we put them all in the menu it will
>> be so big it is inconvenient to use.  So arguing that "this command is
>> worth including" is not a good way to think about the question.
>
>The menu is not necessarily flat.  Using submenus it would be possible
>to organize most useful commands in a convenient way.  For instance,
>the "Search" menu could have submenus "Search files" for the grep family
>of commands, and "Search buffers" for the occur family of commands.

A better option is that the menu item might just be "find".  Instead
of a singular minibuffer prompt to a specific grep command, a buffer
explaining different grep options could be provided.  The cursor lands
on a text widget, and then the users types in the expression, and then
choses the right type of grep/find command from a selection of
buttons.  An expert Emacs user would, of course, just type M-x
my-favorite-grep-command RET, but for a new user, this would cover all
the bases in one menu item.

Eric

-- 
          Eric Ludlam:                       eric@siege-engine.com
   Siege: www.siege-engine.com          Emacs: http://cedet.sourceforge.net




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

* Re: IDE features:  M-x find-grep
  2008-05-03 21:01       ` Richard M Stallman
  2008-05-03 23:03         ` Juri Linkov
@ 2008-05-04  2:04         ` Lennart Borgman (gmail)
  1 sibling, 0 replies; 19+ messages in thread
From: Lennart Borgman (gmail) @ 2008-05-04  2:04 UTC (permalink / raw)
  To: rms; +Cc: juri, storm, davi, emacs-devel

Richard M Stallman wrote:
>     Yes, I use to say that they should be in the Edit menu every time we 
>     discuss this ... ;-)
> 
>     Seriously, they are very useful and I see no reason not to put them 
>     there. And `occur' and `multi-occur' should be there too, of course.
> 
> There are lots of commands that are "worth putting in the menu" if we
> judge by their usefulness.  But if we put them all in the menu it will
> be so big it is inconvenient to use.  So arguing that "this command is
> worth including" is not a good way to think about the question.

I can argue for it, but is it really necessary in this case? All four 
commands, occur, multi-occur, lgrep and rgrep are general commands for 
searching that are very useful. I think it is a good guess that users 
look for them in the menus where other search commands are. They do 
something very different from the other search commands that are there.

Is not that enough?

Juri suggested a bit restructuring of the menus. That seems good to me 
in a case like this. (If you want to do things fast you do not use the 
menus for this. The menus are more for finding things in this case.)





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

* Re: IDE features:  M-x find-grep
  2008-05-04  1:16           ` Re[2]: " Eric M. Ludlam
@ 2008-05-04  2:05             ` Lennart Borgman (gmail)
  2008-05-04  2:37               ` Re[2]: " Eric M. Ludlam
  0 siblings, 1 reply; 19+ messages in thread
From: Lennart Borgman (gmail) @ 2008-05-04  2:05 UTC (permalink / raw)
  To: Eric M. Ludlam; +Cc: Juri Linkov, emacs-devel, davi, rms, storm



Eric M. Ludlam wrote:
>>>> Juri Linkov <juri@jurta.org> seems to think that:
>>>     Yes, I use to say that they should be in the Edit menu every time we
>>>     discuss this ... ;-)
>>>
>>>     Seriously, they are very useful and I see no reason not to put them
>>>     there. And `occur' and `multi-occur' should be there too, of course.
>>>
>>> There are lots of commands that are "worth putting in the menu" if we
>>> judge by their usefulness.  But if we put them all in the menu it will
>>> be so big it is inconvenient to use.  So arguing that "this command is
>>> worth including" is not a good way to think about the question.
>> The menu is not necessarily flat.  Using submenus it would be possible
>> to organize most useful commands in a convenient way.  For instance,
>> the "Search" menu could have submenus "Search files" for the grep family
>> of commands, and "Search buffers" for the occur family of commands.
> 
> A better option is that the menu item might just be "find".  Instead
> of a singular minibuffer prompt to a specific grep command, a buffer
> explaining different grep options could be provided.  The cursor lands
> on a text widget, and then the users types in the expression, and then
> choses the right type of grep/find command from a selection of
> buttons.  An expert Emacs user would, of course, just type M-x
> my-favorite-grep-command RET, but for a new user, this would cover all
> the bases in one menu item.

One drawback of this might be that it is harder to learn which commands 
there are. Maybe this can be cured by showing the command to carry out 
on that page.




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

* Re[2]: IDE features:  M-x find-grep
  2008-05-04  2:05             ` Lennart Borgman (gmail)
@ 2008-05-04  2:37               ` Eric M. Ludlam
  2008-05-05 20:21                 ` Lennart Borgman (gmail)
  0 siblings, 1 reply; 19+ messages in thread
From: Eric M. Ludlam @ 2008-05-04  2:37 UTC (permalink / raw)
  To: Lennart Borgman (gmail); +Cc: juri, storm, davi, rms, emacs-devel

>>> "Lennart Borgman (gmail)" <lennart.borgman@gmail.com> seems to think that:
>
>
>Eric M. Ludlam wrote:
>>>>> Juri Linkov <juri@jurta.org> seems to think that:
>>>>     Yes, I use to say that they should be in the Edit menu every time we
>>>>     discuss this ... ;-)
>>>>
>>>>     Seriously, they are very useful and I see no reason not to put them
>>>>     there. And `occur' and `multi-occur' should be there too, of course.
>>>>
>>>> There are lots of commands that are "worth putting in the menu" if we
>>>> judge by their usefulness.  But if we put them all in the menu it will
>>>> be so big it is inconvenient to use.  So arguing that "this command is
>>>> worth including" is not a good way to think about the question.
>>> The menu is not necessarily flat.  Using submenus it would be possible
>>> to organize most useful commands in a convenient way.  For instance,
>>> the "Search" menu could have submenus "Search files" for the grep family
>>> of commands, and "Search buffers" for the occur family of commands.
>> 
>> A better option is that the menu item might just be "find".  Instead
>> of a singular minibuffer prompt to a specific grep command, a buffer
>> explaining different grep options could be provided.  The cursor lands
>> on a text widget, and then the users types in the expression, and then
>> choses the right type of grep/find command from a selection of
>> buttons.  An expert Emacs user would, of course, just type M-x
>> my-favorite-grep-command RET, but for a new user, this would cover all
>> the bases in one menu item.
>
>One drawback of this might be that it is harder to learn which commands 
>there are. Maybe this can be cured by showing the command to carry out 
>on that page.

Indeed.  You would have half a screen to provide as much information
as needed, such as:

--------------
Find: Enter string to search for:

 [-!-                       ] <- gray widget here

[ occur ] - Search this buffer [more]
[ multi-occur ] - Search many buffers [more]

Arguments and Files for Search:

 [-!-                       ] <- gray widget here too

 [ grep ] - use grep to search files [more]
 [ lgrep ] - use grep to search for regexp [more]
 [ find-grep ] - Search files specified by find [more]

-----------------

Not that I've used all these functions.

Eric

-- 
          Eric Ludlam:                       eric@siege-engine.com
   Siege: www.siege-engine.com          Emacs: http://cedet.sourceforge.net




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

* Re: IDE features:  M-x find-grep
  2008-05-03 23:03         ` Juri Linkov
  2008-05-04  1:16           ` Re[2]: " Eric M. Ludlam
@ 2008-05-04 20:07           ` Richard M Stallman
  2008-05-04 23:17             ` Juri Linkov
  1 sibling, 1 reply; 19+ messages in thread
From: Richard M Stallman @ 2008-05-04 20:07 UTC (permalink / raw)
  To: Juri Linkov; +Cc: davi, storm, lennart.borgman, emacs-devel

    The menu is not necessarily flat.  Using submenus it would be possible
    to organize most useful commands in a convenient way.  For instance,
    the "Search" menu could have submenus "Search files" for the grep family
    of commands, and "Search buffers" for the occur family of commands.

More levels of menu is also inconvenient.  The general point is
still valid: we should have to design the best menu, not stuff
in all the commands that we think "beginners should see".




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

* Re: IDE features:  M-x find-grep
  2008-05-04 20:07           ` Richard M Stallman
@ 2008-05-04 23:17             ` Juri Linkov
  2008-05-04 23:47               ` Drew Adams
  2008-05-05 15:14               ` Richard M Stallman
  0 siblings, 2 replies; 19+ messages in thread
From: Juri Linkov @ 2008-05-04 23:17 UTC (permalink / raw)
  To: rms; +Cc: davi, storm, lennart.borgman, emacs-devel

>     The menu is not necessarily flat.  Using submenus it would be possible
>     to organize most useful commands in a convenient way.  For instance,
>     the "Search" menu could have submenus "Search files" for the grep family
>     of commands, and "Search buffers" for the occur family of commands.
>
> More levels of menu is also inconvenient.  The general point is
> still valid: we should have to design the best menu, not stuff
> in all the commands that we think "beginners should see".

I think long menus are more inconvenient than deep menus.
Currently we have overly long menu Tools (28 items!), so
moving search related commands to Edit->Search will make the
Tools menu shorter.

-- 
Juri Linkov
http://www.jurta.org/emacs/




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

* RE: IDE features:  M-x find-grep
  2008-05-04 23:17             ` Juri Linkov
@ 2008-05-04 23:47               ` Drew Adams
  2008-05-05 15:14                 ` Richard M Stallman
  2008-05-05 15:14               ` Richard M Stallman
  1 sibling, 1 reply; 19+ messages in thread
From: Drew Adams @ 2008-05-04 23:47 UTC (permalink / raw)
  To: 'Juri Linkov', rms; +Cc: lennart.borgman, emacs-devel, davi, storm

> > More levels of menu is also inconvenient.  The general point is
> > still valid: we should have to design the best menu, not stuff
> > in all the commands that we think "beginners should see".
> 
> I think long menus are more inconvenient than deep menus.
> Currently we have overly long menu Tools (28 items!), so
> moving search related commands to Edit->Search will make the
> Tools menu shorter.

I was going to stay out of this one, but yes, I agree about Search. (And about
Tools having become a catch-all - everything, after all, is a tool.)

All Search stuff should be moved from Tools to a Search menu. I use a top-level
Search menu, and I have for decades.

Yes, I know that some of you have said that the menu-bar is not wide enough to
add a Search menu. In that case, leave it under Edit or sacrifice one of the
other top-level menus - move Buffers under File, for instance. Whatever.

The menu-bar is the main bottleneck for adding menus, so it is natural to add
submenus, at least at the menu-bar level. Yes, it is also bad to have menus that
are too shallow: zillions of submenus everywhere, so you have to cascade
multiple levels to get to things. As an example, Interleaf was notorious for
that.

It's about balance.

The decision of whether to add a menu or a menu item should be based on its
usefulness to users, not on whether the menus are already too crowded, too
numerous, or too deep. That is a phony argument; it just supports the menus and
items we have now, the status quo. Except in extreme limit conditions, menus can
accommodate a lot of submenus and menu items without impacting their usefulness.

On the other hand, yes, whether a menu or item is useful to users is not a
question of completeness either - there is no reason to add stuff just for
completeness, as Richard reminds us often.

Menus are an important way of structuring information. Operations that have
something in common are grouped together. This grouping makes menus a good
learning tool.

No, I don't expect to convince those who never use menus. But then, maybe they
shouldn't be the ones to decide what the menus should be. ;-)






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

* Re: IDE features:  M-x find-grep
  2008-05-04 23:17             ` Juri Linkov
  2008-05-04 23:47               ` Drew Adams
@ 2008-05-05 15:14               ` Richard M Stallman
  1 sibling, 0 replies; 19+ messages in thread
From: Richard M Stallman @ 2008-05-05 15:14 UTC (permalink / raw)
  To: Juri Linkov; +Cc: davi, storm, lennart.borgman, emacs-devel

    Currently we have overly long menu Tools (28 items!), so
    moving search related commands to Edit->Search will make the
    Tools menu shorter.

Maybe you are right.  If so, it just goes to show we have been
too ready to add commands to menus.

Once this is done, one could reconsider the question of adding certain
commands.  Or replacing one by another.

But it will still (and always) be true that the right question is not
"is this command worth putting in the menu" but rather "what is the
best set of commands to have in this menu".

Please do not waste time arguing against this.




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

* Re: IDE features:  M-x find-grep
  2008-05-04 23:47               ` Drew Adams
@ 2008-05-05 15:14                 ` Richard M Stallman
  0 siblings, 0 replies; 19+ messages in thread
From: Richard M Stallman @ 2008-05-05 15:14 UTC (permalink / raw)
  To: Drew Adams; +Cc: juri, lennart.borgman, emacs-devel, davi, storm

    All Search stuff should be moved from Tools to a Search menu. I use a top-level
    Search menu, and I have for decades.

That is out of teh question.  There is no room for another global item
in the menu bar.




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

* Re: IDE features:  M-x find-grep
  2008-05-04  2:37               ` Re[2]: " Eric M. Ludlam
@ 2008-05-05 20:21                 ` Lennart Borgman (gmail)
  0 siblings, 0 replies; 19+ messages in thread
From: Lennart Borgman (gmail) @ 2008-05-05 20:21 UTC (permalink / raw)
  To: Eric M. Ludlam; +Cc: juri, storm, davi, rms, emacs-devel

[-- Attachment #1: Type: text/plain, Size: 933 bytes --]

Eric M. Ludlam wrote:
>> One drawback of this might be that it is harder to learn which commands 
>> there are. Maybe this can be cured by showing the command to carry out 
>> on that page.
> 
> Indeed.  You would have half a screen to provide as much information
> as needed, such as:
> 
> --------------
> Find: Enter string to search for:
> 
>  [-!-                       ] <- gray widget here
> 
> [ occur ] - Search this buffer [more]
> [ multi-occur ] - Search many buffers [more]
> 
> Arguments and Files for Search:
> 
>  [-!-                       ] <- gray widget here too
> 
>  [ grep ] - use grep to search files [more]
>  [ lgrep ] - use grep to search for regexp [more]
>  [ find-grep ] - Search files specified by find [more]
> 
> -----------------
> 
> Not that I've used all these functions.
> 
> Eric

I have played a bit with this idea, see the attached file. (Note that 
lgrep/rgrep does not work at the moment.)

[-- Attachment #2: search-form.el --]
[-- Type: text/plain, Size: 11142 bytes --]

;;; search-form.el --- Search form
;;
;; Author: Lennart Borgman (lennart O borgman A gmail O com)
;; Created: 2008-05-05T01:50:20+0200 Sun
;; Version: 0.1
;; Last-Updated:
;; URL:
;; Keywords:
;; Compatibility:
;;
;; Features that might be required by this library:
;;
;;   None
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;; Commentary:
;;
;; After an idea by Eric Ludlam on Emacs Devel:
;;
;;  http://lists.gnu.org/archive/html/emacs-devel/2008-05/msg00152.html
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;; Change log:
;;
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; This program is free software; you can redistribute it and/or
;; modify it under the terms of the GNU General Public License as
;; published by the Free Software Foundation; either version 2, or
;; (at your option) any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
;; General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with this program; see the file COPYING.  If not, write to
;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth
;; Floor, Boston, MA 02110-1301, USA.
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;; Code:

(require 'cus-edit)

(defvar search-form-sfield nil)
(make-variable-buffer-local 'search-form-sfield)
(defvar search-form-rfield nil)
(make-variable-buffer-local 'search-form-rfield)

(defun search-form-multi-occur-get-buffers ()
  (let* ((bufs (list (read-buffer "First buffer to search: "
                                  (current-buffer) t)))
         (buf nil)
         (ido-ignore-item-temp-list bufs))
    (while (not (string-equal
                 (setq buf (read-buffer
                            (if (eq read-buffer-function 'ido-read-buffer)
                                "Next buffer to search (C-j to end): "
                              "Next buffer to search (RET to end): ")
                            nil t))
                 ""))
      (add-to-list 'bufs buf)
      (setq ido-ignore-item-temp-list bufs))
    (nreverse (mapcar #'get-buffer bufs))))

(defun search-form-notify-1 (use-search-field use-replace-field w &rest ignore)
  (let ((search-string  (when use-search-field  (widget-value search-form-sfield)))
        (replace-string (when use-replace-field (widget-value search-form-rfield)))
        (search-form-buffer (current-buffer))
        (this-search (widget-get w :do-search))
        (do-it t))
    (when (and use-search-field
               (= 0 (length search-string)))
      (setq do-it nil)
      (message "Please specify a search string"))
    (when (and use-replace-field
               (= 0 (length replace-string)))
      (setq do-it nil)
      (message "Please specify a replace string"))
    (when do-it
      (delete-window (selected-window))
      (funcall this-search w)
      (kill-buffer search-form-buffer)
      ;;(message "Done.")
      )))

(defun search-form-notify-no-field (w &rest ignore)
  (search-form-notify-1 nil nil w))

(defun search-form-notify-sfield (w &rest ignore)
  (search-form-notify-1 t nil w))

(defun search-form-notify-both-fields (w &rest ignore)
  (search-form-notify-1 t t w))

(defvar search-form-current-buffer nil)

(defun search-form-insert-button (title function descr do-fun)
  (widget-insert "  ")
  (let ((button-title (format " %-15s " title)))
    (widget-create 'push-button
                   :do-search do-search-fun
                   :notify 'search-form-notify-no-field
                   :current-buffer search-form-current-buffer
                   button-title))
  (widget-insert " " descr)
  (widget-insert "\n"))

(defun search-form-insert-search (title search-fun descr do-search-fun)
  (widget-insert "  ")
  (let ((button-title (format " %-15s " title)))
    (widget-create 'push-button
                   :do-search do-search-fun
                   :notify 'search-form-notify-sfield
                   :current-buffer search-form-current-buffer
                   button-title))
  (widget-insert " " descr " ")
  (search-form-insert-help search-fun)
  (widget-insert "\n"))

(defun search-form-insert-fb (descr
                              use-sfield
                              forward-fun
                              do-forward-fun
                              backward-fun
                              do-backward-fun)
  (widget-insert (format "  %s: " descr))
  (widget-create 'push-button
                 :do-search do-forward-fun
                 :notify (if use-sfield
                             'search-form-notify-sfield
                           'search-form-notify-no-field)
                 :current-buffer search-form-current-buffer
                 " Forward ")
  (widget-insert " ")
  (search-form-insert-help forward-fun)
  (widget-insert "  ")
  (widget-create 'push-button
                 :do-search do-backward-fun
                 :notify (if use-sfield
                             'search-form-notify-sfield
                           'search-form-notify-no-field)
                 :current-buffer search-form-current-buffer
                 " Backward ")
  (widget-insert " ")
  (search-form-insert-help backward-fun)
  (widget-insert "\n"))

(defun search-form-insert-replace (title replace-fun descr do-replace-fun)
  (widget-insert "  ")
  (let ((button-title (format " %-15s " title)))
    (widget-create 'push-button
                   :do-search do-replace-fun
                   :notify 'search-form-notify-both-fields
                   :current-buffer search-form-current-buffer
                   button-title))
  (widget-insert " " descr " ")
  (search-form-insert-help replace-fun)
  (widget-insert "\n"))

(defun search-form-insert-help (fun)
  (widget-insert "(")
  (widget-create 'function-link
                 :value fun
                 :tag "help"
                 :button-face 'link)
  (widget-insert ")"))

(defun search-form ()
  (interactive)
  (let* ((buf-name "*Search Form*")
         (cur-buf (current-buffer)))
    (setq search-form-current-buffer (current-buffer))
    (switch-to-buffer-other-window buf-name)

    (kill-all-local-variables) ;; why???
    (let ((inhibit-read-only t))
      (erase-buffer))
    ;;(Custom-mode)
    (remove-overlays)

    (make-local-variable 'widget-button-face)
    (setq widget-button-face custom-button)
    (setq show-trailing-whitespace nil)
    (when custom-raised-buttons
      (set (make-local-variable 'widget-push-button-prefix) "")
      (set (make-local-variable 'widget-push-button-suffix) "")
      (set (make-local-variable 'widget-link-prefix) "")
      (set (make-local-variable 'widget-link-suffix) ""))

    (widget-insert (propertize "Emacs Search/Replace Form" 'face 'font-lock-comment-face)
                   "\n\n")
    (search-form-insert-fb
     "Incremental String Search" nil
     'isearch-forward
     (lambda (w) (call-interactively 'isearch-forward))
     'isearch-backward
     (lambda (w) (call-interactively 'isearch-backward)))

    (search-form-insert-fb
     "Incremental Regexp Search" nil
     'isearch-forward-regexp
     (lambda (w) (call-interactively 'isearch-forward-regexp))
     'isearch-backward-regexp
     (lambda (w) (call-interactively 'isearch-backward-regexp)))

    (widget-insert (make-string (window-width) ?-) "\n")

    (widget-insert "Search:")
    (setq search-form-sfield
          (widget-create 'editable-field
                         :size 60))
    (widget-insert "\n\n")
    (widget-insert (propertize "* Buffers:" 'face 'font-lock-comment-face) "\n")
    (search-form-insert-fb
     "String Search" t
     'nonincremental-search-forward
     (lambda (w) (call-interactively 'nonincremental-search-forward search-string))
     'nonincremental-search-backward
     (lambda (w) (call-interactively 'nonincremental-search-backward search-string)))

    (search-form-insert-fb
     "Regexp Search" t
     'nonincremental-re-search-forward
     (lambda (w) (call-interactively 'nonincremental-re-search-forward search-string))
     'nonincremental-re-search-backward
     (lambda (w) (call-interactively 'nonincremental-re-search-backward search-string)))

    ;; occur
    (search-form-insert-search
     "Occur"
     'occur
     "Lines in this buffer"
     (lambda (w)
       (with-current-buffer (widget-get w :current-buffer)
         (occur search-string))))

    ;; multi-occur
    (search-form-insert-search
     "Multi-Occur"
     'multi-occur
     "Lines in specified buffers"
     (lambda (w)
       (let ((bufs (search-form-multi-occur-get-buffers)))
         (multi-occur bufs search-string))))
    ;;
    (widget-insert "\n")
    (widget-insert (propertize "* Files:" 'face 'font-lock-comment-face)
                   "\n")

    (search-form-insert-search
     "lgrep"
     'lgrep
     "Grep in directory"
     (lambda (w)
       (with-current-buffer (widget-get w :current-buffer)
         (lgrep search-string))))
    (search-form-insert-search
     "rgrep"
     'rgrep
     "Grep in directory tree"
     (lambda (w)
       (with-current-buffer (widget-get w :current-buffer)
         (rgrep search-string))))

    (widget-insert "\n")

    (search-form-insert-search
     "Tagged Files"
     'tags-search
     "Search files in tags table"
     (lambda (w)
       (with-current-buffer (widget-get w :current-buffer)
         (tags-search search-string))))

    (widget-insert (make-string (window-width) ?-) "\n")

    (widget-insert "Replace:")
    (setq search-form-rfield
          (widget-create 'editable-field
                         :size 60))
    (widget-insert "\n\n")

    (widget-insert (propertize "* Buffers:" 'face 'font-lock-comment-face) "\n")
    (search-form-insert-replace "Replace String"
                                'query-replace
                                "In buffer from point"
                                (lambda (w)
                                  (query-replace search-string replace-string)))

    (search-form-insert-replace "Replace Regexp"
                                'query-replace-regexp
                                "In buffer from point"
                                (lambda (w)
                                  (query-replace-regexp search-string replace-string)))

    (widget-insert "\n" (propertize "* Files:" 'face 'font-lock-comment-face) "\n")

    (search-form-insert-replace "Tagged Files"
                                'query-replace-regexp
                                "Replace in files in tags tables"
                                (lambda (w)
                                  (tags-query-replace search-string replace-string)))

    (buffer-disable-undo)
    (widget-setup)
    (buffer-enable-undo)
    (use-local-map widget-keymap)
    (widget-forward 1)
    ))


(provide 'search-form)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; search-form.el ends here

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

end of thread, other threads:[~2008-05-05 20:21 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-04-27 20:36 IDE features: M-x find-grep Davi Leal
2008-04-27 21:12 ` Phil Jackson
2008-04-27 22:10   ` Davi Leal
2008-04-27 21:48 ` Kim F. Storm
2008-04-27 22:44   ` Davi Leal
2008-05-02 23:46   ` Juri Linkov
2008-05-03  0:27     ` Lennart Borgman (gmail)
2008-05-03 21:01       ` Richard M Stallman
2008-05-03 23:03         ` Juri Linkov
2008-05-04  1:16           ` Re[2]: " Eric M. Ludlam
2008-05-04  2:05             ` Lennart Borgman (gmail)
2008-05-04  2:37               ` Re[2]: " Eric M. Ludlam
2008-05-05 20:21                 ` Lennart Borgman (gmail)
2008-05-04 20:07           ` Richard M Stallman
2008-05-04 23:17             ` Juri Linkov
2008-05-04 23:47               ` Drew Adams
2008-05-05 15:14                 ` Richard M Stallman
2008-05-05 15:14               ` Richard M Stallman
2008-05-04  2:04         ` Lennart Borgman (gmail)

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