[Top][All Lists]

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

RE: Grep with matching lines syntax highlighted [snippet]

From: Drew Adams
Subject: RE: Grep with matching lines syntax highlighted [snippet]
Date: Sun, 10 Dec 2006 07:49:39 -0800

> > grep+.el:
> > I defined a command, bound in buffer *grep* to `;', that
> > removes all lines that start with a comment.
> But what about the case when it is a multiline comment (e.g. in C /*
> ... */) and one of the middle lines are matched, so you can't recognize
> with a simple regexp it's a commented line?

You're welcome ;-).

I don't try to handle that case. I also don't handle the situation where the
files grepped at once are in different languages (grep foo *.el *.c), so
that there is no single `comment-start' (; vs //) that can be used. My own
use is just for Lisp, and the `;' command does what I want for that.

> Why don't you apply some of the original idea then?
> If the regular expression doesn't match the line then you should check
> if the file is already opened and if it is then check if the whole line
> has font-lock-comment face. If it has the it can also be filtered.
> If the line doesn't have comment face, but it doesn't have the
> 'fontified property either (stealth fontification) then you should
> trigger the appropriate fontification function (if there's any for the
> mode) for the region to find out if the line is a commented line.
> It's not that complicated and it could be very useful. The most common
> case (for me at least) is removing commented lines from grep output not
> just any regexp, so I think this case warrants a special treatment for
> convenience.

You are welcome to try and see what can be done. Multiline comments are not
important to me, but I can see that they might be to others.

BTW: If you are going to visit the grepped files anyway, you might just pick
up the `comment-start' and `comment-end' values for each file, and use that
info to strip the lines; that might make it unnecessary to rely upon
fontification. And perhaps there is a command already that hides all
comments in any program file; if so, you might use that.

reply via email to

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