From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: filebat Mark Newsgroups: gmane.emacs.help Subject: Re: When grep-find, show the count of matches Date: Mon, 28 Jun 2010 23:57:05 +0800 Message-ID: References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=001636e0b66c18ca7e048a192ca9 X-Trace: dough.gmane.org 1277740700 9929 80.91.229.12 (28 Jun 2010 15:58:20 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Mon, 28 Jun 2010 15:58:20 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon Jun 28 17:58:18 2010 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1OTGiu-0002ZA-ME for geh-help-gnu-emacs@m.gmane.org; Mon, 28 Jun 2010 17:58:17 +0200 Original-Received: from localhost ([127.0.0.1]:36177 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OTGit-0006nS-ID for geh-help-gnu-emacs@m.gmane.org; Mon, 28 Jun 2010 11:58:15 -0400 Original-Received: from [140.186.70.92] (port=46351 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OTGhp-0006m3-UF for help-gnu-emacs@gnu.org; Mon, 28 Jun 2010 11:57:11 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OTGhn-0006k2-8x for help-gnu-emacs@gnu.org; Mon, 28 Jun 2010 11:57:09 -0400 Original-Received: from mail-pv0-f169.google.com ([74.125.83.169]:55088) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OTGhm-0006jr-S4 for help-gnu-emacs@gnu.org; Mon, 28 Jun 2010 11:57:07 -0400 Original-Received: by pvg11 with SMTP id 11so3670842pvg.0 for ; Mon, 28 Jun 2010 08:57:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:received:in-reply-to :references:date:message-id:subject:from:to:content-type; bh=SjN5NEcnHUDni5RqQ2x/tS7qdOFSXWUR73qIm9W14nI=; b=o99ekcY3y3wGydaau20USwaOnQOQ0iBErh4VkhAnEjrWdaap43gz81na67QQTP8NJe G5xo5ury30JKXE3LS3Zda1ZnZPUKwTzy7/n2VRyBJVWopdiodwL9c5LK6GVlCO9rumgn qpAVjgIb3SN2M16lCNbFJtn60OCAfiQ+53YpQ= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; b=gU0HjsW2lNIZJ9fM7ZrDdGQar3zfWW5PpY7K+jeeocS/sC0U/Ctnd3sdHjm2oa6ekT 1orJsjX+We1FCEJw9MJZMw/gtV2oMyLlYL9dE7Js8qriuwnKL0qBusippPSbHUFI0Mou yh+JEZxaxHhR0U5N6wgD4LJ8DF1mKx2ftKFG8= Original-Received: by 10.143.24.32 with SMTP id b32mr4325469wfj.219.1277740625479; Mon, 28 Jun 2010 08:57:05 -0700 (PDT) Original-Received: by 10.142.194.17 with HTTP; Mon, 28 Jun 2010 08:57:05 -0700 (PDT) In-Reply-To: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:73997 Archived-At: --001636e0b66c18ca7e048a192ca9 Content-Type: text/plain; charset=ISO-8859-1 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 wrote: > filebat Mark 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:

HTML generated by org-mode 6.35i > in > >> > emacs 23

> >> > | ./tmp.html~:153:

HTML generated by org-mode 6.35i > in > >> > emacs 23

> >> > | ./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 --001636e0b66c18ca7e048a192ca9 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Thank you very much, Tim. Sorry for my confusing illustration.

You h= ave 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 p= roblem is that, since the grep command takes some time, even though we defi= ne an after-defadive, the function is executed before *grep* buffer is stab= le.

My workaround is to sleep for some while. No idea whether we have bette= r solution.


(defadvice grep-find (after show-grep())
=A0(save= -excursion
=A0=A0 (setq SLEEP_INTERVAL 2)
=A0=A0 (set-buffer "*g= rep*")
=A0=A0 (sleep-for SLEEP_INTERVAL)
=A0=A0 (message
=A0=A0=A0 "%d = matches found"
=A0=A0=A0 (- (count-lines (point-min) (point-max)) 6= ))
=A0=A0 )
)
(ad-activate 'grep-find)


On Mon, Jun 28, 2010 at 9:51 PM, Tim Landscheidt <tim@tim-landscheidt.= de> wrote:
<= div class=3D"h5">filebat Mark <filebat.mark@gmail.com> wrote:

>> > I am wondering how to show the count of matches when grep-fin= d. Like the
>> > following.
>> > ,-----------
>> > | -*- mode: grep; default-directory:
>> > "d:/ntemacs23/myemacs/private_data/out_of_svn/" -*-=
>> > | Grep started at Mon Jun 28 17:46:18
>> > |
>> > | =A0find . -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=3D"creator">HTML ge= nerated by org-mode 6.35i in
>> > emacs 23</p>
>> > | ./tmp.html~:153:<p class=3D"creator">HTML g= enerated 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* b= uffer.
>> > Before moving any further, I am very willing to hear your ide= as, 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 matc= hes, 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:

=A0 | (save-excursion
=A0 | =A0 (set-buffer "*grep*")
=A0 | =A0 (message
=A0 | =A0 =A0"%d matches found"
=A0 | =A0 =A0(- (count-lines (point-min) (point-max))
=A0 | =A0 =A0 =A0 6)))

=A0 on a hot key,

b) defadvice grep-process-setup/set grep-setup-hook so that
=A0 the above will be executed when grep finishes.

Tim





--
Thanks & Reg= ards

Denny Zhang

--001636e0b66c18ca7e048a192ca9--