all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Drew Adams <drew.adams@oracle.com>
To: Rami A <rami.ammari@gmail.com>, help-gnu-emacs@gnu.org
Subject: RE: highlight regular expression in grep window
Date: Sat, 8 Feb 2014 14:19:21 -0800 (PST)	[thread overview]
Message-ID: <c2c9b1c4-c30f-4b90-bf4d-cc21d032b5e3@default> (raw)
In-Reply-To: <0cd4f26f-2ba8-48b0-a839-6e3e169ee56f@googlegroups.com>

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	other threads:[~2014-02-08 22:19 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2014-02-08 22:33 ` Rami A
2014-02-08 22:50   ` Drew Adams

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=c2c9b1c4-c30f-4b90-bf4d-cc21d032b5e3@default \
    --to=drew.adams@oracle.com \
    --cc=help-gnu-emacs@gnu.org \
    --cc=rami.ammari@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.