help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: highlight regular expression in grep window


From: Drew Adams
Subject: RE: highlight regular expression in grep window
Date: Sat, 8 Feb 2014 14:19:21 -0800 (PST)

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)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]