all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* highlight regular expression in grep window
@ 2013-09-04 17:47 Rami A
  2013-09-04 18:48 ` Drew Adams
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Rami A @ 2013-09-04 17:47 UTC (permalink / raw)
  To: help-gnu-emacs

Greetings,
I am wondering if there is a way to have the regular expression I am grepping on highlighted at the top of the grep window.
Something like:

grep [reg expr]   ;Where [] highlighted
....results of grep....


Or at least at the title of window at the bottom something like:

*grep* [reg exp]


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

* RE: highlight regular expression in grep window
  2013-09-04 17:47 highlight regular expression in grep window Rami A
@ 2013-09-04 18:48 ` Drew Adams
       [not found] ` <mailman.1313.1378320529.10748.help-gnu-emacs@gnu.org>
  2014-02-08 22:33 ` Rami A
  2 siblings, 0 replies; 9+ messages in thread
From: Drew Adams @ 2013-09-04 18:48 UTC (permalink / raw)
  To: Rami A, help-gnu-emacs

> I am wondering if there is a way to have the regular expression I am
> grepping on highlighted at the top of the grep window.
> Something like:
> 
> grep [reg expr]   ;Where [] highlighted
> ....results of grep....
> 
> 
> Or at least at the title of window at the bottom something like:
> 
> *grep* [reg exp]

I don't have an answer for you, but just to be sure what you are asking:

You're not talking about highlighting the text that the regexp matches.
You just want to highlight the regexp itself.  Right?

I ask because older Emacs versions do not highlight regexp matches, and
if that's all you want then one answer is to either use a newer Emacs
or use library grep+.el.



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

* Re: highlight regular expression in grep window
       [not found] ` <mailman.1313.1378320529.10748.help-gnu-emacs@gnu.org>
@ 2013-09-04 19:32   ` Rami A
  2013-09-04 20:33     ` Drew Adams
       [not found]     ` <mailman.1317.1378326833.10748.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 9+ messages in thread
From: Rami A @ 2013-09-04 19:32 UTC (permalink / raw)
  To: help-gnu-emacs

Thanks Drew.
You are right, I am not looking to highlight the regexp in the results but only to highlight it at the top of results.
I checked your grep+.el but the problem is that I already customized grep.el functions for my needs and don't want to do the same again.
I am not even worried about "highlighting" the regexp, I just want a way to find out what the expression that I grepped for once I switch to that window.

My customized grep function is something like:

find . -type d \( -name unix -o -name "*_sim" -o -name RCS -o -name CVS -o -name SCCS \) -prune -o -type f \! -name \*\~ \! -name \*\,v \! -name s.\* \! -name .\#\* -name \*.\[sch\] -print | xargs -e grep -n -i  mem_test  /dev/null

So the token "mem_test" which I am looking for would be invisible because it is at the end of that string.

I just want something like:

The token I am grepping on is: mem_test
find . -type d \( -name unix -o -name "*_sim" -o -name RCS -o -name CVS -o -name SCCS \) -prune -o -type f \! -name \*\~ \! -name \*\,v \! -name s.\* \! -name .\#\* -name \*.\[sch\] -print | xargs -e grep -n -i  mem_test  /dev/null

or, as I mentioned earlier to include that token at the bottom along with the title of the buffer "*grep* mem_test

I am sure there should be a way to modify the grep.el functions to achieve that somehow.


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

* RE: highlight regular expression in grep window
  2013-09-04 19:32   ` Rami A
@ 2013-09-04 20:33     ` Drew Adams
  2013-09-05  6:47       ` Kevin Rodgers
       [not found]     ` <mailman.1317.1378326833.10748.help-gnu-emacs@gnu.org>
  1 sibling, 1 reply; 9+ messages in thread
From: Drew Adams @ 2013-09-04 20:33 UTC (permalink / raw)
  To: Rami A, help-gnu-emacs

> I am not even worried about "highlighting" the regexp, I just want a way to
> find out what the expression that I grepped for once I switch to that
> window.

`g' in that window, then `M-p' should show you the last `grep' command, with
its regexp.  Does that help?

> My customized grep function is something like:
> 
> find . -type d \( -name unix -o -name "*_sim" -o -name RCS -o -name CVS -o -
> name SCCS \) -prune -o -type f \! -name \*\~ \! -name \*\,v \! -name s.\* \!
> -name .\#\* -name \*.\[sch\] -print | xargs -e grep -n -i  mem_test
> /dev/null

Ah, so this is not about `M-x grep'.  I guess it's about `grep-find'.
Still, repeating the command and using `M-p' should show you the previous
command used, including its regexp.

> So the token "mem_test" which I am looking for would be invisible because it
> is at the end of that string.  I just want something like:
> 
> The token I am grepping on is: mem_test
...
> or, as I mentioned earlier to include that token at the bottom along with
> the title of the buffer "*grep* mem_test
> 
> I am sure there should be a way to modify the grep.el functions to achieve
> that somehow.

The regexp you typed was not seen as such by Emacs.  All that was seen was
the entire input command, including that regexp.  To extract the regexp I
think you would need to add code that matches that input against the template
`grep-find-command', which has the hole into which you inserted the regexp.

Maybe someone else can help more; sorry.



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

* Re: highlight regular expression in grep window
  2013-09-04 20:33     ` Drew Adams
@ 2013-09-05  6:47       ` Kevin Rodgers
  0 siblings, 0 replies; 9+ messages in thread
From: Kevin Rodgers @ 2013-09-05  6:47 UTC (permalink / raw)
  To: help-gnu-emacs

On 9/4/13 2:33 PM, Drew Adams wrote:
>> My customized grep function is something like:
>>
>> find . -type d \( -name unix -o -name "*_sim" -o -name RCS -o -name CVS -o -
>> name SCCS \) -prune -o -type f \! -name \*\~ \! -name \*\,v \! -name s.\* \!
>> -name .\#\* -name \*.\[sch\] -print | xargs -e grep -n -i  mem_test
>> /dev/null
>
> Ah, so this is not about `M-x grep'.  I guess it's about `grep-find'.
> Still, repeating the command and using `M-p' should show you the previous
> command used, including its regexp.
...
> The regexp you typed was not seen as such by Emacs.  All that was seen was
> the entire input command, including that regexp.  To extract the regexp I
> think you would need to add code that matches that input against the template
> `grep-find-command', which has the hole into which you inserted the regexp.
>
> Maybe someone else can help more; sorry.

rgrep is an interactive autoloaded Lisp function in `grep.el'.

(rgrep REGEXP &optional FILES DIR CONFIRM)

Recursively grep for REGEXP in FILES in directory tree rooted at DIR.
The search is limited to file names matching shell pattern FILES.
FILES may use abbreviations defined in `grep-files-aliases', e.g.
entering `ch' is equivalent to `*.[ch]'.

With C-u prefix, you can edit the constructed shell command line
before it is executed.
With two C-u prefixes, directly edit and run `grep-find-command'.

Collect output in a buffer.  While find runs asynchronously, you
can use C-x ` (M-x next-error), or
Uses keymap "grep-mode-map", which is not currently defined.
M-x compile-goto-error in the grep output buffer,
to go to the lines where grep found matches.

This command shares argument histories with M-x lgrep and M-x grep-find.

-- 
Kevin Rodgers
Denver, Colorado, USA




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

* Re: highlight regular expression in grep window
       [not found]     ` <mailman.1317.1378326833.10748.help-gnu-emacs@gnu.org>
@ 2014-02-08 19:46       ` Rami A
  2014-02-08 22:19         ` Drew Adams
  0 siblings, 1 reply; 9+ messages in thread
From: Rami A @ 2014-02-08 19:46 UTC (permalink / raw)
  To: help-gnu-emacs

On Wednesday, September 4, 2013 1:33:24 PM UTC-7, Drew Adams wrote:
> > I am not even worried about "highlighting" the regexp, I just want a way to
> 
> > find out what the expression that I grepped for once I switch to that
> 
> > window.
> 
> 
> 
> `g' in that window, then `M-p' should show you the last `grep' command, with
> 
> its regexp.  Does that help?
> 
> 
> 
> > My customized grep function is something like:
> 
> > 
> 
> > find . -type d \( -name unix -o -name "*_sim" -o -name RCS -o -name CVS -o -
> 
> > name SCCS \) -prune -o -type f \! -name \*\~ \! -name \*\,v \! -name s.\* \!
> 
> > -name .\#\* -name \*.\[sch\] -print | xargs -e grep -n -i  mem_test
> 
> > /dev/null
> 
> 
> 
> Ah, so this is not about `M-x grep'.  I guess it's about `grep-find'.
> 
> Still, repeating the command and using `M-p' should show you the previous
> 
> command used, including its regexp.
> 
> 
> 
> > So the token "mem_test" which I am looking for would be invisible because it
> 
> > is at the end of that string.  I just want something like:
> 
> > 
> 
> > The token I am grepping on is: mem_test
> 
> ...
> 
> > or, as I mentioned earlier to include that token at the bottom along with
> 
> > the title of the buffer "*grep* mem_test
> 
> > 
> 
> > I am sure there should be a way to modify the grep.el functions to achieve
> 
> > that somehow.
> 
> 
Drew,
I went back and tried using your grep+.el library.
I have a couple of questions:
1. Is it possible to tweak it so it would remove/toggle comments in the grep window for a C language based file or assembly?
2. Is there an option to highlight the match in the grep window? "this is different than my question asked in this thread." I am really looking to highlight each match in a busy grep window.



> 
> The regexp you typed was not seen as such by Emacs.  All that was seen was
> 
> the entire input command, including that regexp.  To extract the regexp I
> 
> think you would need to add code that matches that input against the template
> 
> `grep-find-command', which has the hole into which you inserted the regexp.
> 
> 
> 
> Maybe someone else can help more; sorry.



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

* RE: highlight regular expression in grep window
  2014-02-08 19:46       ` Rami A
@ 2014-02-08 22:19         ` Drew Adams
  0 siblings, 0 replies; 9+ messages in thread
From: Drew Adams @ 2014-02-08 22:19 UTC (permalink / raw)
  To: Rami A, help-gnu-emacs

Wow, a reply to a thread from 6 months ago!

> I went back and tried using your grep+.el library.
> I have a couple of questions:
>
> 1. Is it possible to tweak it so it would remove/toggle comments in
> the grep window for a C language based file or assembly?

By "grep window" I guess you mean the window showing buffer *grep*.

Yes.  If you use a prefix arg with `grepp-remove-comments' then
you are prompted for the regexp that is used to match commented
lines.  Really, it is not necessarily about comments.  This is just
a regexp that is passed to command `flush-lines' after making the
buffer writable etc.

For example, `C-u ;' then enter, say, ":[0-9]+: */\*" (without the
quotes) at the prompt, to match lines containing `/*'.  Or whatever.

You can alternatively customize `grepp-default-comment-line-regexp'
so it matches the comment syntax you want (or whatever other syntax
pattern you want to match, for removal).

You can also define your own command that binds that option value
to whatever regexp you want:

(defun remove-C-comment-starts ()
  "Remove lines with C comment starts: `/*'."
  (interactive)
  (let ((grepp-default-comment-line-regexp  ":[0-9]+: */\\*"))
    (grepp-remove-comments)))

Obviously, for C code things are a bit complicated for multi-line
comments.  With a simple thing like this (which is essentially just
`flush-lines') you can remove only individual lines that match a
pattern.  The code has no real understanding of C commenting.

But you could write a similar command that binds a regexp for /*
and calls `grepp-remove-comments', then binds a regexp for */ and
calls it again, then binds a regexp for // and calls it again.

That won't catch comment lines between a /* line and a */ line,
but it will at least cut down on much of the noise.

> 2. Is there an option to highlight the match in the grep window?
> "this is different than my question asked in this thread." I am
> really looking to highlight each match in a busy grep window.

IIUC, that happens already.  If you do, say, `M-x grep' and enter
this command: `grep -nH -e the.*r alloc.c' then matches for the
regexp `the.*r' are highlighted in buffer *grep*.

----

There are other things you can use, instead of using grep and
then flushing comments this way.

You can, for instance, use command `hide/show-comments' from
library `hide-comnt.el' to hide comments.  And then use search
to navigate among the uncommented code (e.g., Isearch or Icicles
search across multiple buffers or files).  (I don't think that
`occur' and `moccur' ignore the hidden comments.)

`hide/show-comments' does take care of lines between /* and */,
for instance.  And it does not hide code that is on the same line
as a comment.  It is not line-oriented; it is comment-oriented.

http://www.emacswiki.org/emacs/HideOrIgnoreComments (description)

http://www.emacswiki.org/emacs-en/download/hide-comnt.el (code)



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

* Re: highlight regular expression in grep window
  2013-09-04 17:47 highlight regular expression in grep window Rami A
  2013-09-04 18:48 ` Drew Adams
       [not found] ` <mailman.1313.1378320529.10748.help-gnu-emacs@gnu.org>
@ 2014-02-08 22:33 ` Rami A
  2014-02-08 22:50   ` Drew Adams
  2 siblings, 1 reply; 9+ messages in thread
From: Rami A @ 2014-02-08 22:33 UTC (permalink / raw)
  To: help-gnu-emacs

Drew,
I get this:
grep -nH -e WARN *.* /dev/null
grep: illegal option -- H
grep: illegal option -- e
Usage: grep -hblcnsviw pattern file . . .

Is that because I am running under Solaris? Which doesn't recognize the --color option for grep command.


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

* RE: highlight regular expression in grep window
  2014-02-08 22:33 ` Rami A
@ 2014-02-08 22:50   ` Drew Adams
  0 siblings, 0 replies; 9+ messages in thread
From: Drew Adams @ 2014-02-08 22:50 UTC (permalink / raw)
  To: Rami A, help-gnu-emacs

> I get this:
> grep -nH -e WARN *.* /dev/null
> grep: illegal option -- H
> grep: illegal option -- e
> Usage: grep -hblcnsviw pattern file . . .
> 
> Is that because I am running under Solaris? Which doesn't recognize
> the --color option for grep command.

Dunno; you tell me.  See the doc string for option
`grep-highlight-matches'.  I'm no expert on different OS `grep'
commands.

You don't mention your Emacs version.  If your version of `grep'
won't do the highlighting, you can try this (untested - this is
really for older Emacs versions, but I think it should work OK):

Do not load library grep.el or grep+.el.  Instead, load these
libraries in this order: compile-20.el, compile.el, compile+20.el.

The first and third are from Emacs Wiki.  They provide an
older version of what grep+.el provides.  They do the regexp
highlighting without depending on the `grep' OS command for it.

No, they won't give you everything that the latest and greatest
Emacs code will give you - they are what I use for Emacs 20 and
21.  But they should at least let you use `M-x grep' with
highlighting of the regexp matches in buffer *grep* (and more).



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

end of thread, other threads:[~2014-02-08 22:50 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-09-04 17:47 highlight regular expression in grep window Rami A
2013-09-04 18:48 ` Drew Adams
     [not found] ` <mailman.1313.1378320529.10748.help-gnu-emacs@gnu.org>
2013-09-04 19:32   ` Rami A
2013-09-04 20:33     ` Drew Adams
2013-09-05  6:47       ` Kevin Rodgers
     [not found]     ` <mailman.1317.1378326833.10748.help-gnu-emacs@gnu.org>
2014-02-08 19:46       ` Rami A
2014-02-08 22:19         ` Drew Adams
2014-02-08 22:33 ` Rami A
2014-02-08 22:50   ` Drew Adams

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.