* When grep-find, show the count of matches
@ 2010-06-28 9:59 filebat Mark
2010-06-28 11:33 ` Tim Landscheidt
0 siblings, 1 reply; 8+ messages in thread
From: filebat Mark @ 2010-06-28 9:59 UTC (permalink / raw)
To: help-gnu-emacs
[-- Attachment #1: Type: text/plain, Size: 1127 bytes --]
Hi emacsers
I am wondering how to show the count of matches when grep-find. Like the
following.
,-----------
| -*- mode: grep; default-directory:
"d:/ntemacs23/myemacs/private_data/out_of_svn/" -*-
| Grep started at Mon Jun 28 17:46:18
|
| find . -name ".svn" -prune -o -type f -print0 | xargs -0 -e grep -inH -e
emacs
| ./#tmp.txt#:7:#+TAGS: ARCHIVE(a) WEBPAGE(w) LIFE(l) EMACS(e) IMPORTANT(i)
HARD(h) COMPUTER(c) RECOMMENDATE(r) Tool(t)
| ./#tmp.txt#:47438:* TODO log4j-mode in emacs
| ./#tmp.txt#:47529:Hi emacsers
| ./tmp.html:554:<p class="creator">HTML generated by org-mode 6.35i in
emacs 23</p>
| ./tmp.html~:153:<p class="creator">HTML generated by org-mode 6.35i in
emacs 23</p>
| ./tmp.txt:7:#+TAGS: ARCHIVE(a) WEBPAGE(w) LIFE(l) EMACS(e) IMPORTANT(i)
HARD(h) COMPUTER(c) RECOMMENDATE(r) Tool(t)
| ./tmp.txt:47438:* TODO log4j-mode in emacs
|
| Grep finished (7 matches found) at Mon Jun 28 17:46:20
`-----------
IMHO, one feasible way may be counting the output of *grep* buffer.
Before moving any further, I am very willing to hear your ideas, comment or
codesnipet for this?
--
Thanks & Regards
Denny Zhang
[-- Attachment #2: Type: text/html, Size: 1287 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: When grep-find, show the count of matches
2010-06-28 9:59 When grep-find, show the count of matches filebat Mark
@ 2010-06-28 11:33 ` Tim Landscheidt
2010-06-28 13:23 ` filebat Mark
0 siblings, 1 reply; 8+ messages in thread
From: Tim Landscheidt @ 2010-06-28 11:33 UTC (permalink / raw)
To: help-gnu-emacs
filebat Mark <filebat.mark@gmail.com> wrote:
> I am wondering how to show the count of matches when grep-find. Like the
> following.
> ,-----------
> | -*- mode: grep; default-directory:
> "d:/ntemacs23/myemacs/private_data/out_of_svn/" -*-
> | Grep started at Mon Jun 28 17:46:18
> |
> | find . -name ".svn" -prune -o -type f -print0 | xargs -0 -e grep -inH -e
> emacs
> | ./#tmp.txt#:7:#+TAGS: ARCHIVE(a) WEBPAGE(w) LIFE(l) EMACS(e) IMPORTANT(i)
> HARD(h) COMPUTER(c) RECOMMENDATE(r) Tool(t)
> | ./#tmp.txt#:47438:* TODO log4j-mode in emacs
> | ./#tmp.txt#:47529:Hi emacsers
> | ./tmp.html:554:<p class="creator">HTML generated by org-mode 6.35i in
> emacs 23</p>
> | ./tmp.html~:153:<p class="creator">HTML generated by org-mode 6.35i in
> emacs 23</p>
> | ./tmp.txt:7:#+TAGS: ARCHIVE(a) WEBPAGE(w) LIFE(l) EMACS(e) IMPORTANT(i)
> HARD(h) COMPUTER(c) RECOMMENDATE(r) Tool(t)
> | ./tmp.txt:47438:* TODO log4j-mode in emacs
> |
> | Grep finished (7 matches found) at Mon Jun 28 17:46:20
> `-----------
> IMHO, one feasible way may be counting the output of *grep* buffer.
> Before moving any further, I am very willing to hear your ideas, comment or
> codesnipet for this?
- "find ... | xargs -0r grep ... | wc -l"?
- "find ... | xargs -0r cat | grep -c"?
- Read "(7 matches found)"?
Tim
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: When grep-find, show the count of matches
2010-06-28 11:33 ` Tim Landscheidt
@ 2010-06-28 13:23 ` filebat Mark
2010-06-28 13:51 ` Tim Landscheidt
0 siblings, 1 reply; 8+ messages in thread
From: filebat Mark @ 2010-06-28 13:23 UTC (permalink / raw)
To: help-gnu-emacs
[-- Attachment #1: Type: text/plain, Size: 1627 bytes --]
Hi Tim
Your commands can help to count the matches, however my point is to get both
the matches and the count of how many matches. ^-^
Regards,
Denny
On 6/28/10, Tim Landscheidt <tim@tim-landscheidt.de> wrote:
>
> filebat Mark <filebat.mark@gmail.com> wrote:
>
> > I am wondering how to show the count of matches when grep-find. Like the
> > following.
> > ,-----------
> > | -*- mode: grep; default-directory:
> > "d:/ntemacs23/myemacs/private_data/out_of_svn/" -*-
> > | Grep started at Mon Jun 28 17:46:18
> > |
> > | find . -name ".svn" -prune -o -type f -print0 | xargs -0 -e grep -inH
> -e
> > emacs
> > | ./#tmp.txt#:7:#+TAGS: ARCHIVE(a) WEBPAGE(w) LIFE(l) EMACS(e)
> IMPORTANT(i)
> > HARD(h) COMPUTER(c) RECOMMENDATE(r) Tool(t)
> > | ./#tmp.txt#:47438:* TODO log4j-mode in emacs
> > | ./#tmp.txt#:47529:Hi emacsers
> > | ./tmp.html:554:<p class="creator">HTML generated by org-mode 6.35i in
> > emacs 23</p>
> > | ./tmp.html~:153:<p class="creator">HTML generated by org-mode 6.35i in
> > emacs 23</p>
> > | ./tmp.txt:7:#+TAGS: ARCHIVE(a) WEBPAGE(w) LIFE(l) EMACS(e) IMPORTANT(i)
> > HARD(h) COMPUTER(c) RECOMMENDATE(r) Tool(t)
> > | ./tmp.txt:47438:* TODO log4j-mode in emacs
> > |
> > | Grep finished (7 matches found) at Mon Jun 28 17:46:20
> > `-----------
>
> > IMHO, one feasible way may be counting the output of *grep* buffer.
> > Before moving any further, I am very willing to hear your ideas, comment
> or
> > codesnipet for this?
>
>
> - "find ... | xargs -0r grep ... | wc -l"?
> - "find ... | xargs -0r cat | grep -c"?
> - Read "(7 matches found)"?
>
>
> Tim
>
>
>
--
Thanks & Regards
Denny Zhang
[-- Attachment #2: Type: text/html, Size: 2267 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: When grep-find, show the count of matches
2010-06-28 13:23 ` filebat Mark
@ 2010-06-28 13:51 ` Tim Landscheidt
2010-06-28 15:57 ` filebat Mark
0 siblings, 1 reply; 8+ messages in thread
From: Tim Landscheidt @ 2010-06-28 13:51 UTC (permalink / raw)
To: help-gnu-emacs
filebat Mark <filebat.mark@gmail.com> wrote:
>> > I am wondering how to show the count of matches when grep-find. Like the
>> > following.
>> > ,-----------
>> > | -*- mode: grep; default-directory:
>> > "d:/ntemacs23/myemacs/private_data/out_of_svn/" -*-
>> > | Grep started at Mon Jun 28 17:46:18
>> > |
>> > | find . -name ".svn" -prune -o -type f -print0 | xargs -0 -e grep -inH
>> -e
>> > emacs
>> > | ./#tmp.txt#:7:#+TAGS: ARCHIVE(a) WEBPAGE(w) LIFE(l) EMACS(e)
>> IMPORTANT(i)
>> > HARD(h) COMPUTER(c) RECOMMENDATE(r) Tool(t)
>> > | ./#tmp.txt#:47438:* TODO log4j-mode in emacs
>> > | ./#tmp.txt#:47529:Hi emacsers
>> > | ./tmp.html:554:<p class="creator">HTML generated by org-mode 6.35i in
>> > emacs 23</p>
>> > | ./tmp.html~:153:<p class="creator">HTML generated by org-mode 6.35i in
>> > emacs 23</p>
>> > | ./tmp.txt:7:#+TAGS: ARCHIVE(a) WEBPAGE(w) LIFE(l) EMACS(e) IMPORTANT(i)
>> > HARD(h) COMPUTER(c) RECOMMENDATE(r) Tool(t)
>> > | ./tmp.txt:47438:* TODO log4j-mode in emacs
>> > |
>> > | Grep finished (7 matches found) at Mon Jun 28 17:46:20
>> > `-----------
>> > IMHO, one feasible way may be counting the output of *grep* buffer.
>> > Before moving any further, I am very willing to hear your ideas, comment
>> or
>> > codesnipet for this?
>> - "find ... | xargs -0r grep ... | wc -l"?
>> - "find ... | xargs -0r cat | grep -c"?
>> - Read "(7 matches found)"?
> Your commands can help to count the matches, however my point is to get both
> the matches and the count of how many matches. ^-^
Your point /was/ "how to show the count of matches". For
your current point, you could:
a) put something like:
| (save-excursion
| (set-buffer "*grep*")
| (message
| "%d matches found"
| (- (count-lines (point-min) (point-max))
| 6)))
on a hot key,
b) defadvice grep-process-setup/set grep-setup-hook so that
the above will be executed when grep finishes.
Tim
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: When grep-find, show the count of matches
2010-06-28 13:51 ` Tim Landscheidt
@ 2010-06-28 15:57 ` filebat Mark
2010-06-28 17:59 ` Tim Landscheidt
[not found] ` <mailman.1.1277747970.703.help-gnu-emacs@gnu.org>
0 siblings, 2 replies; 8+ messages in thread
From: filebat Mark @ 2010-06-28 15:57 UTC (permalink / raw)
To: help-gnu-emacs
[-- Attachment #1: Type: text/plain, Size: 2866 bytes --]
Thank you very much, Tim. Sorry for my confusing illustration.
You have point a good way to solve my problem. Changing grep-process-setup
seems don't work, so I change the function of grep-find.
One slight problem is that, since the grep command takes some time, even
though we define an after-defadive, the function is executed before *grep*
buffer is stable.
My workaround is to sleep for some while. No idea whether we have better
solution.
(defadvice grep-find (after show-grep())
(save-excursion
(setq SLEEP_INTERVAL 2)
(set-buffer "*grep*")
(sleep-for SLEEP_INTERVAL)
(message
"%d matches found"
(- (count-lines (point-min) (point-max)) 6))
)
)
(ad-activate 'grep-find)
On Mon, Jun 28, 2010 at 9:51 PM, Tim Landscheidt <tim@tim-landscheidt.de>wrote:
> filebat Mark <filebat.mark@gmail.com> wrote:
>
> >> > I am wondering how to show the count of matches when grep-find. Like
> the
> >> > following.
> >> > ,-----------
> >> > | -*- mode: grep; default-directory:
> >> > "d:/ntemacs23/myemacs/private_data/out_of_svn/" -*-
> >> > | Grep started at Mon Jun 28 17:46:18
> >> > |
> >> > | find . -name ".svn" -prune -o -type f -print0 | xargs -0 -e grep
> -inH
> >> -e
> >> > emacs
> >> > | ./#tmp.txt#:7:#+TAGS: ARCHIVE(a) WEBPAGE(w) LIFE(l) EMACS(e)
> >> IMPORTANT(i)
> >> > HARD(h) COMPUTER(c) RECOMMENDATE(r) Tool(t)
> >> > | ./#tmp.txt#:47438:* TODO log4j-mode in emacs
> >> > | ./#tmp.txt#:47529:Hi emacsers
> >> > | ./tmp.html:554:<p class="creator">HTML generated by org-mode 6.35i
> in
> >> > emacs 23</p>
> >> > | ./tmp.html~:153:<p class="creator">HTML generated by org-mode 6.35i
> in
> >> > emacs 23</p>
> >> > | ./tmp.txt:7:#+TAGS: ARCHIVE(a) WEBPAGE(w) LIFE(l) EMACS(e)
> IMPORTANT(i)
> >> > HARD(h) COMPUTER(c) RECOMMENDATE(r) Tool(t)
> >> > | ./tmp.txt:47438:* TODO log4j-mode in emacs
> >> > |
> >> > | Grep finished (7 matches found) at Mon Jun 28 17:46:20
> >> > `-----------
>
> >> > IMHO, one feasible way may be counting the output of *grep* buffer.
> >> > Before moving any further, I am very willing to hear your ideas,
> comment
> >> or
> >> > codesnipet for this?
>
> >> - "find ... | xargs -0r grep ... | wc -l"?
> >> - "find ... | xargs -0r cat | grep -c"?
> >> - Read "(7 matches found)"?
>
> > Your commands can help to count the matches, however my point is to get
> both
> > the matches and the count of how many matches. ^-^
>
> Your point /was/ "how to show the count of matches". For
> your current point, you could:
>
> a) put something like:
>
> | (save-excursion
> | (set-buffer "*grep*")
> | (message
> | "%d matches found"
> | (- (count-lines (point-min) (point-max))
> | 6)))
>
> on a hot key,
>
> b) defadvice grep-process-setup/set grep-setup-hook so that
> the above will be executed when grep finishes.
>
> Tim
>
>
>
--
Thanks & Regards
Denny Zhang
[-- Attachment #2: Type: text/html, Size: 3990 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: When grep-find, show the count of matches
2010-06-28 15:57 ` filebat Mark
@ 2010-06-28 17:59 ` Tim Landscheidt
2010-06-29 5:04 ` Kevin Rodgers
[not found] ` <mailman.1.1277747970.703.help-gnu-emacs@gnu.org>
1 sibling, 1 reply; 8+ messages in thread
From: Tim Landscheidt @ 2010-06-28 17:59 UTC (permalink / raw)
To: help-gnu-emacs
filebat Mark <filebat.mark@gmail.com> wrote:
> Thank you very much, Tim. Sorry for my confusing illustration.
> You have point a good way to solve my problem. Changing grep-process-setup
> seems don't work, so I change the function of grep-find.
> One slight problem is that, since the grep command takes some time, even
> though we define an after-defadive, the function is executed before *grep*
> buffer is stable.
> My workaround is to sleep for some while. No idea whether we have better
> solution.
> (defadvice grep-find (after show-grep())
> (save-excursion
> (setq SLEEP_INTERVAL 2)
> (set-buffer "*grep*")
> (sleep-for SLEEP_INTERVAL)
> (message
> "%d matches found"
> (- (count-lines (point-min) (point-max)) 6))
> )
> )
> (ad-activate 'grep-find)
> [...]
No, you should defadvice *around* grep-process-setup, copy
the whole original from the Emacs distribution, and replace
the lambda construct in:
| (set (make-local-variable 'compilation-exit-message-function)
| (lambda (status code msg)
| (if (eq status 'exit)
| (cond ((zerop code)
| '("finished (matches found)\n" . "matched"))
| ((= code 1)
| '("finished with no matches found\n" . "no match"))
| (t
| (cons msg code)))
| (cons msg code))))
with another that inserts the number of matches into the
buffer.
Tim
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: When grep-find, show the count of matches
[not found] ` <mailman.1.1277747970.703.help-gnu-emacs@gnu.org>
@ 2010-06-28 18:40 ` Andreas Politz
0 siblings, 0 replies; 8+ messages in thread
From: Andreas Politz @ 2010-06-28 18:40 UTC (permalink / raw)
To: help-gnu-emacs
Tim Landscheidt <tim@tim-landscheidt.de> writes:
> filebat Mark <filebat.mark@gmail.com> wrote:
>
>> Thank you very much, Tim. Sorry for my confusing illustration.
>
>> You have point a good way to solve my problem. Changing grep-process-setup
>> seems don't work, so I change the function of grep-find.
>
>> One slight problem is that, since the grep command takes some time, even
>> though we define an after-defadive, the function is executed before *grep*
>> buffer is stable.
>
>> My workaround is to sleep for some while. No idea whether we have better
>> solution.
>
>> (defadvice grep-find (after show-grep())
>> (save-excursion
>> (setq SLEEP_INTERVAL 2)
>> (set-buffer "*grep*")
>> (sleep-for SLEEP_INTERVAL)
>> (message
>> "%d matches found"
>> (- (count-lines (point-min) (point-max)) 6))
>> )
>> )
>> (ad-activate 'grep-find)
>> [...]
>
> No, you should defadvice *around* grep-process-setup, copy
> the whole original from the Emacs distribution, and replace
> the lambda construct in:
>
> | (set (make-local-variable 'compilation-exit-message-function)
> | (lambda (status code msg)
> | (if (eq status 'exit)
> | (cond ((zerop code)
> | '("finished (matches found)\n" . "matched"))
> | ((= code 1)
> | '("finished with no matches found\n" . "no match"))
> | (t
> | (cons msg code)))
> | (cons msg code))))
>
> with another that inserts the number of matches into the
> buffer.
>
> Tim
Why use a `hack', if there is a defined way of doing these things
(`grep-setup-hook') ?
-ap
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: When grep-find, show the count of matches
2010-06-28 17:59 ` Tim Landscheidt
@ 2010-06-29 5:04 ` Kevin Rodgers
0 siblings, 0 replies; 8+ messages in thread
From: Kevin Rodgers @ 2010-06-29 5:04 UTC (permalink / raw)
To: help-gnu-emacs
Tim Landscheidt wrote:
...
> No, you should defadvice *around* grep-process-setup, copy
> the whole original from the Emacs distribution, and replace
> the lambda construct in:
>
> | (set (make-local-variable 'compilation-exit-message-function)
> | (lambda (status code msg)
> | (if (eq status 'exit)
> | (cond ((zerop code)
> | '("finished (matches found)\n" . "matched"))
> | ((= code 1)
> | '("finished with no matches found\n" . "no match"))
> | (t
> | (cons msg code)))
> | (cons msg code))))
>
> with another that inserts the number of matches into the
> buffer.
Copying the grep-process-setup function definition defeats the purpose of
defadvice. As the function's doc string suggests, this is what grep-setup-hook
is intended for (resetting compilation-exit-message-function).
--
Kevin Rodgers
Denver, Colorado, USA
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2010-06-29 5:04 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-06-28 9:59 When grep-find, show the count of matches filebat Mark
2010-06-28 11:33 ` Tim Landscheidt
2010-06-28 13:23 ` filebat Mark
2010-06-28 13:51 ` Tim Landscheidt
2010-06-28 15:57 ` filebat Mark
2010-06-28 17:59 ` Tim Landscheidt
2010-06-29 5:04 ` Kevin Rodgers
[not found] ` <mailman.1.1277747970.703.help-gnu-emacs@gnu.org>
2010-06-28 18:40 ` Andreas Politz
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.