* using find-grep in emacs
@ 2013-05-13 23:47 Rami A
2013-05-14 0:45 ` Dan Espen
2013-05-15 18:25 ` Rami A
0 siblings, 2 replies; 17+ messages in thread
From: Rami A @ 2013-05-13 23:47 UTC (permalink / raw)
To: help-gnu-emacs
Hi,
I am trying to setup some default for grep-find in emacs.
I do the following to search in the source code:
M-x find-grep
which give:
find . -type f -exec grep -n {} /dev/null \;
Now I have to change /dev/null to be the directory which I want to search in.
How is it possible to not do that every time I use find-grep and that it could remember the directory I am specifying.
Also, How to make it default to search all three file types .h .s .c and nothing else?
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: using find-grep in emacs
2013-05-13 23:47 using find-grep in emacs Rami A
@ 2013-05-14 0:45 ` Dan Espen
2013-05-14 2:36 ` Barry Margolin
2013-05-14 4:45 ` Bob Proulx
2013-05-15 18:25 ` Rami A
1 sibling, 2 replies; 17+ messages in thread
From: Dan Espen @ 2013-05-14 0:45 UTC (permalink / raw)
To: help-gnu-emacs
Rami A <rami.ammari@gmail.com> writes:
> Hi,
> I am trying to setup some default for grep-find in emacs.
> I do the following to search in the source code:
> M-x find-grep
> which give:
> find . -type f -exec grep -n {} /dev/null \;
>
> Now I have to change /dev/null to be the directory which I want to search in.
> How is it possible to not do that every time I use find-grep and that it could remember the directory I am specifying.
>
> Also, How to make it default to search all three file types .h .s .c and nothing else?
In emacs 24.2.1 the string is:
find . -type f -print0 | "xargs" -0 -e grep -nH -e
To only look at .hsc files I'd do:
find . -type f -a -name '*.[hsc]' -exec grep -n {} /dev/null \;
(Not tested but you should get the idea.)
The "." after find is the directory you want to search in, if you don't
want to search the current directory, replace the ".".
I believe /dev/null is there to convince grep that it should display
file names because it is looking at multiple files.
--
Dan Espen
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: using find-grep in emacs
2013-05-14 0:45 ` Dan Espen
@ 2013-05-14 2:36 ` Barry Margolin
2013-05-14 13:31 ` Ludwig, Mark
2013-05-14 4:45 ` Bob Proulx
1 sibling, 1 reply; 17+ messages in thread
From: Barry Margolin @ 2013-05-14 2:36 UTC (permalink / raw)
To: help-gnu-emacs
In article <icbo8ewfsj.fsf@home.home>, Dan Espen <despen@verizon.net>
wrote:
> I believe /dev/null is there to convince grep that it should display
> file names because it is looking at multiple files.
Right. Modern greps have -H for this (and -h to suppress filenames even
when there are multiple inputs).
--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: using find-grep in emacs
2013-05-14 0:45 ` Dan Espen
2013-05-14 2:36 ` Barry Margolin
@ 2013-05-14 4:45 ` Bob Proulx
2013-05-14 11:48 ` Andreas Röhler
1 sibling, 1 reply; 17+ messages in thread
From: Bob Proulx @ 2013-05-14 4:45 UTC (permalink / raw)
To: help-gnu-emacs
Dan Espen wrote:
> Rami A writes:
> > M-x find-grep
> > find . -type f -exec grep -n {} /dev/null \;
What version of emacs are you using? That isn't emacs 23 nor emacs 24.
So what version is it? M-x emacs-version
Specifically "\;" should be "+" in emacs 24.
> > Now I have to change /dev/null to be the directory which I want to search in.
There is a misunderstanding of how that command works. You wouldn't
replace /dev/null. Leave it the same. (Or use -H.)
The string you would want to replace with the directory you want to
search is the "." string not the "/dev/null" string. The "."
specifies the directory to search.
That space between the "-n" and "{}" is where you should type in the
search pattern.
> > How is it possible to not do that every time I use find-grep and
> > that it could remember the directory I am specifying.
> >
> > Also, How to make it default to search all three file types .h .s
> > .c and nothing else?
>
> In emacs 24.2.1 the string is:
>
> find . -type f -print0 | "xargs" -0 -e grep -nH -e
That looks more like emacs 23.2.1 not 24.2.1. Emacs 24.3.1 uses this
string by default:
find . -type f -exec grep -nH -e {} +
^ cursor here
> To only look at .hsc files I'd do:
>
> find . -type f -a -name '*.[hsc]' -exec grep -n {} /dev/null \;
>
> (Not tested but you should get the idea.)
Looks good to me. But also include the pattern. And the -a is superfluous.
find . -type f -name '*.[hsc]' -exec grep -nH PATTERN {} +
> The "." after find is the directory you want to search in, if you don't
> want to search the current directory, replace the ".".
>
> I believe /dev/null is there to convince grep that it should display
> file names because it is looking at multiple files.
Yes. Definitely! :-)
Bob
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: using find-grep in emacs
2013-05-14 4:45 ` Bob Proulx
@ 2013-05-14 11:48 ` Andreas Röhler
2013-05-14 15:27 ` Peter Dyballa
0 siblings, 1 reply; 17+ messages in thread
From: Andreas Röhler @ 2013-05-14 11:48 UTC (permalink / raw)
To: help-gnu-emacs
Am 14.05.2013 06:45, schrieb Bob Proulx:
> Dan Espen wrote:
>> Rami A writes:
>>> M-x find-grep
>>> find . -type f -exec grep -n {} /dev/null \;
>
[ ... ]
>>
>> I believe /dev/null is there to convince grep that it should display
>> file names because it is looking at multiple files.
>
> Yes. Definitely! :-)
>
> Bob
>
>
Because a Null -- 0 -- offers the most space to fill all that in?
:)
^ permalink raw reply [flat|nested] 17+ messages in thread
* RE: using find-grep in emacs
2013-05-14 2:36 ` Barry Margolin
@ 2013-05-14 13:31 ` Ludwig, Mark
0 siblings, 0 replies; 17+ messages in thread
From: Ludwig, Mark @ 2013-05-14 13:31 UTC (permalink / raw)
To: Barry Margolin, help-gnu-emacs@gnu.org
> From: Barry Margolin, Monday, May 13, 2013 9:36 PM
> > I believe /dev/null is there to convince grep that it should display
> > file names because it is looking at multiple files.
>
> Right. Modern greps have -H for this (and -h to suppress filenames even when
> there are multiple inputs).
Since we're on the subject, is there a way to make Emacs not add "/dev/null" (UNIX, or "NUL" on Windows) at the end? I have a couple of "specialized" grep-like commands that I run as the command in M-x grep, and I've adjusted those scripts to ignore a trailing "/dev/null" argument in order to be compatible with Emacs. (I would never add "/dev/null" interactively if I were invoking them.)
Thanks!
Mark Ludwig
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: using find-grep in emacs
2013-05-14 11:48 ` Andreas Röhler
@ 2013-05-14 15:27 ` Peter Dyballa
2013-05-14 15:42 ` Bob Proulx
[not found] ` <mailman.25743.1368546134.855.help-gnu-emacs@gnu.org>
0 siblings, 2 replies; 17+ messages in thread
From: Peter Dyballa @ 2013-05-14 15:27 UTC (permalink / raw)
To: Andreas Röhler; +Cc: help-gnu-emacs
Am 14.05.2013 um 13:48 schrieb Andreas Röhler:
> Because a Null -- 0 -- offers the most space to fill all that in?
No! It's the least space to read from. No other file ends earlier.
--
Mit friedvollen Grüßen
Pete
"Debugging? Klingons do not debug. Our software does not coddle the weak."
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: using find-grep in emacs
2013-05-14 15:27 ` Peter Dyballa
@ 2013-05-14 15:42 ` Bob Proulx
2013-05-14 17:19 ` Andreas Röhler
[not found] ` <mailman.25743.1368546134.855.help-gnu-emacs@gnu.org>
1 sibling, 1 reply; 17+ messages in thread
From: Bob Proulx @ 2013-05-14 15:42 UTC (permalink / raw)
To: help-gnu-emacs
Peter Dyballa wrote:
> schrieb Andreas Röhler:
> > Because a Null -- 0 -- offers the most space to fill all that in?
>
> No! It's the least space to read from. No other file ends earlier.
In case this issue confuses people I wanted to say a few words. Prior
to the addition of the grep -H option the behavior was this following.
The grep, egrep, fgrep programs would print matching lines from files.
If one file was searched then no file name would be printed. If more
than one file was searched then grep would prefix the line by the name
of the file so that you could tell which file it came from.
So the problem was how do you instruct grep to print the name of the
file even when you were only searching one file? The answer was to
tell grep to search more than one file. But, you say, I only want to
search one file. The answer is to search /dev/null in addition to
whatever file you are wanting to search. /dev/null will return end of
file immediately. It won't use any cpu time. With multiple files
being searched grep will print the file name on each line. An elegant
Unix solution. That is why the grep template uses grep with /dev/null
so that grep will print the file name so that Emacs compile mode can
parse it.
GNU grep has an extension to print file names without needing to have
an extra null file argument. With GNU grep you can specify the -H
option and GNU grep will print the file name for all matches
regardless of the number of files being searched. Newer emacs
versions use this option and make the assumption that you have GNU
grep available. (Or it might figure it out dynamically. I don't
know.)
But the grep -H option is only available in GNU grep for the GNU
system and BSD grep for BSD systems. It is not available in the older
traditional Unix systems. It isn't in the POSIX standard. Therefore
using -H is non-portable. It won't work on HP-UX or IBM AIX for example.
http://pubs.opengroup.org/onlinepubs/009695399/utilities/grep.html
But if you are using Emacs then you probably have grep -H available
too and might as well use it.
The Emacs grep find templates can be customized. See the
grep-find-template variable in this case for example.
Bob
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: using find-grep in emacs
2013-05-14 15:42 ` Bob Proulx
@ 2013-05-14 17:19 ` Andreas Röhler
0 siblings, 0 replies; 17+ messages in thread
From: Andreas Röhler @ 2013-05-14 17:19 UTC (permalink / raw)
To: help-gnu-emacs
Am 14.05.2013 17:42, schrieb Bob Proulx:
> Peter Dyballa wrote:
>> schrieb Andreas Röhler:
>>> Because a Null -- 0 -- offers the most space to fill all that in?
>>
>> No! It's the least space to read from. No other file ends earlier.
>
> In case this issue confuses people I wanted to say a few words. Prior
> to the addition of the grep -H option the behavior was this following.
> The grep, egrep, fgrep programs would print matching lines from files.
> If one file was searched then no file name would be printed. If more
> than one file was searched then grep would prefix the line by the name
> of the file so that you could tell which file it came from.
>
> So the problem was how do you instruct grep to print the name of the
> file even when you were only searching one file? The answer was to
> tell grep to search more than one file. But, you say, I only want to
> search one file. The answer is to search /dev/null in addition to
> whatever file you are wanting to search. /dev/null will return end of
> file immediately. It won't use any cpu time. With multiple files
> being searched grep will print the file name on each line. An elegant
> Unix solution. That is why the grep template uses grep with /dev/null
> so that grep will print the file name so that Emacs compile mode can
> parse it.
>
> GNU grep has an extension to print file names without needing to have
> an extra null file argument. With GNU grep you can specify the -H
> option and GNU grep will print the file name for all matches
> regardless of the number of files being searched. Newer emacs
> versions use this option and make the assumption that you have GNU
> grep available. (Or it might figure it out dynamically. I don't
> know.)
>
> But the grep -H option is only available in GNU grep for the GNU
> system and BSD grep for BSD systems. It is not available in the older
> traditional Unix systems. It isn't in the POSIX standard. Therefore
> using -H is non-portable. It won't work on HP-UX or IBM AIX for example.
>
> http://pubs.opengroup.org/onlinepubs/009695399/utilities/grep.html
>
> But if you are using Emacs then you probably have grep -H available
> too and might as well use it.
>
> The Emacs grep find templates can be customized. See the
> grep-find-template variable in this case for example.
>
> Bob
>
>
Thanks a lot digging into, great to learn that.
Andreas
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: using find-grep in emacs
[not found] ` <mailman.25743.1368546134.855.help-gnu-emacs@gnu.org>
@ 2013-05-14 19:41 ` Barry Margolin
0 siblings, 0 replies; 17+ messages in thread
From: Barry Margolin @ 2013-05-14 19:41 UTC (permalink / raw)
To: help-gnu-emacs
In article <mailman.25743.1368546134.855.help-gnu-emacs@gnu.org>,
Bob Proulx <bob@proulx.com> wrote:
> An elegant
> Unix solution.
AKA "a kludge" :)
--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: using find-grep in emacs
2013-05-13 23:47 using find-grep in emacs Rami A
2013-05-14 0:45 ` Dan Espen
@ 2013-05-15 18:25 ` Rami A
2013-05-15 18:49 ` Dan Espen
` (2 more replies)
1 sibling, 3 replies; 17+ messages in thread
From: Rami A @ 2013-05-15 18:25 UTC (permalink / raw)
To: help-gnu-emacs
Thank you all for your feedback.
I am actually using 2 emacs binaries "24.3.1" and "23.3.1".
I am trying to bind all this command that also defaults to search only [*.shc] files.
How can I do that?
Basically I want to be able to hit for example F1 and simply type the pattern I am looking for without continuously adding the [*.shc].
Also I would like emacs to ask the default folder to look for the pattern underneath only once.
Was not able to find a way to achieve all of that.
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: using find-grep in emacs
2013-05-15 18:25 ` Rami A
@ 2013-05-15 18:49 ` Dan Espen
2013-05-15 18:51 ` Andreas Röhler
[not found] ` <mailman.25858.1368643771.855.help-gnu-emacs@gnu.org>
2 siblings, 0 replies; 17+ messages in thread
From: Dan Espen @ 2013-05-15 18:49 UTC (permalink / raw)
To: help-gnu-emacs
Rami A <rami.ammari@gmail.com> writes:
> Thank you all for your feedback.
> I am actually using 2 emacs binaries "24.3.1" and "23.3.1".
>
> I am trying to bind all this command that also defaults to search only [*.shc] files.
> How can I do that?
>
> Basically I want to be able to hit for example F1 and simply type the pattern I am looking for without continuously adding the [*.shc].
> Also I would like emacs to ask the default folder to look for the pattern underneath only once.
> Was not able to find a way to achieve all of that.
Someone else can tell you the variable that contains the initial string.
I'll just point out that you can recall the last command you typed with
M-p and probably with the arrow keys.
So, type it once per session, recall though the history with one or a
couple of keystrokes.
I don't think I'd mess with the initial command, I use Emacs in way too
many contexts.
--
Dan Espen
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: using find-grep in emacs
2013-05-15 18:25 ` Rami A
2013-05-15 18:49 ` Dan Espen
@ 2013-05-15 18:51 ` Andreas Röhler
[not found] ` <mailman.25858.1368643771.855.help-gnu-emacs@gnu.org>
2 siblings, 0 replies; 17+ messages in thread
From: Andreas Röhler @ 2013-05-15 18:51 UTC (permalink / raw)
To: help-gnu-emacs
Am 15.05.2013 20:25, schrieb Rami A:
> Thank you all for your feedback.
> I am actually using 2 emacs binaries "24.3.1" and "23.3.1".
>
> I am trying to bind all this command that also defaults to search only [*.shc] files.
> How can I do that?
>
> Basically I want to be able to hit for example F1 and simply type the pattern I am looking for without continuously adding the [*.shc].
>
> Also I would like emacs to ask the default folder to look for the pattern underneath only once.
>
> Was not able to find a way to achieve all of that.
>
M-x customize-variable RET grep-find-command RET
If that's not enough, for example as I like to change switch some parameters quite often, write your own commands.
The command below uses -maxdepth 9, while another aliased gf1 uses -maxdepth 1 etc.
(defalias 'gf9 'neun-grep-find)
(defun neun-grep-find ()
(interactive)
(grep-apply-setting 'grep-find-command "find . -maxdepth 9 -type f -name \"*.el\" -print0 | xargs -0 -e grep -nH -e ")
(grep-find (car (progn
(grep-compute-defaults)
(list (read-shell-command "Run find (like this): "
grep-find-command 'grep-find-history))))))
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: using find-grep in emacs
[not found] ` <mailman.25858.1368643771.855.help-gnu-emacs@gnu.org>
@ 2013-05-15 19:11 ` Rami A
2013-05-15 19:46 ` Andreas Röhler
0 siblings, 1 reply; 17+ messages in thread
From: Rami A @ 2013-05-15 19:11 UTC (permalink / raw)
To: help-gnu-emacs
Andreas,
Thanks a lot.
Is there a way to search in specific directories?
I have my main directory lets say ./main/ then I have multiple directories underneath ./main/source ./main/headers/ ./main/something1 ./main/something2...etc
I want to only specify the search to be for directories "headers" and "source" once I specified ./main as my default grep destination.
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: using find-grep in emacs
2013-05-15 19:11 ` Rami A
@ 2013-05-15 19:46 ` Andreas Röhler
2013-05-15 21:23 ` Peter Dyballa
0 siblings, 1 reply; 17+ messages in thread
From: Andreas Röhler @ 2013-05-15 19:46 UTC (permalink / raw)
To: help-gnu-emacs
Am 15.05.2013 21:11, schrieb Rami A:
> Andreas, Thanks a lot. Is there a way to search in specific directories?
Sure.
Specify the directory following "find"
i.e. find .
assumes the current directory, so try
find ./main/source
find ./main/headers/
etc.
or do some scripting like
for i in "./main/source" "./main/headers/" "./main/something1" "./main/something2"; do
...
done
> I have my main directory lets say ./main/ then I have multiple directories underneath ./main/source ./main/headers/ ./main/something1 ./main/something2...etc I want to
> only specify the search to be for directories "headers" and "source" once I specified ./main as my default grep destination.
>
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: using find-grep in emacs
2013-05-15 19:46 ` Andreas Röhler
@ 2013-05-15 21:23 ` Peter Dyballa
2013-05-16 5:10 ` Andreas Röhler
0 siblings, 1 reply; 17+ messages in thread
From: Peter Dyballa @ 2013-05-15 21:23 UTC (permalink / raw)
To: Andreas Röhler; +Cc: help-gnu-emacs
Am 15.05.2013 um 21:46 schrieb Andreas Röhler:
> assumes the current directory, so try
>
> find ./main/source
>
> find ./main/headers/
>
> etc.
And it's also possible to use
find main/source main/headers ...
BTW, the path element "./anything" is the same as "anything". "./" plays a role when dealing with executables.
--
Greetings
Pete
People say that if you play Microsoft CD's backwards, you hear satanic things, but that's nothing, because if you play them forwards, they install MS Windows.
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: using find-grep in emacs
2013-05-15 21:23 ` Peter Dyballa
@ 2013-05-16 5:10 ` Andreas Röhler
0 siblings, 0 replies; 17+ messages in thread
From: Andreas Röhler @ 2013-05-16 5:10 UTC (permalink / raw)
To: Peter Dyballa; +Cc: help-gnu-emacs
Am 15.05.2013 23:23, schrieb Peter Dyballa:
>
> Am 15.05.2013 um 21:46 schrieb Andreas Röhler:
>
>> assumes the current directory, so try
>>
>> find ./main/source
>>
>> find ./main/headers/
>>
>> etc.
>
> And it's also possible to use
>
> find main/source main/headers ...
>
Thanks pointing at.
Andreas
^ permalink raw reply [flat|nested] 17+ messages in thread
end of thread, other threads:[~2013-05-16 5:10 UTC | newest]
Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-05-13 23:47 using find-grep in emacs Rami A
2013-05-14 0:45 ` Dan Espen
2013-05-14 2:36 ` Barry Margolin
2013-05-14 13:31 ` Ludwig, Mark
2013-05-14 4:45 ` Bob Proulx
2013-05-14 11:48 ` Andreas Röhler
2013-05-14 15:27 ` Peter Dyballa
2013-05-14 15:42 ` Bob Proulx
2013-05-14 17:19 ` Andreas Röhler
[not found] ` <mailman.25743.1368546134.855.help-gnu-emacs@gnu.org>
2013-05-14 19:41 ` Barry Margolin
2013-05-15 18:25 ` Rami A
2013-05-15 18:49 ` Dan Espen
2013-05-15 18:51 ` Andreas Röhler
[not found] ` <mailman.25858.1368643771.855.help-gnu-emacs@gnu.org>
2013-05-15 19:11 ` Rami A
2013-05-15 19:46 ` Andreas Röhler
2013-05-15 21:23 ` Peter Dyballa
2013-05-16 5:10 ` Andreas Röhler
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.