From: "Drew Adams" <drew.adams@oracle.com>
Subject: RE: Highlighting in grep buffer
Date: Mon, 5 Apr 2004 16:05:35 -0700 [thread overview]
Message-ID: <FDELKNEBLPKKDCEBEJCBOEELCDAA.drew.adams@oracle.com> (raw)
In-Reply-To: <E1BAcBl-0000Dk-TO@fencepost.gnu.org>
FYI - This was part of the Emacs 20 code I sent previously (files
compile-.el and compile+.el).
My code treated the common-case grep patterns using simple regexps (see #3,
below).
My code did *not* try to:
- treat possible occurrences of grep as part of another command sequence
(e.g. piped)
- treat grep options: -i for case insensitivity, -E etc. for other grep
flavors etc.
- treat environment variable substitution
It just grabbed the regexp (quoted or not) from an Emacs M-x grep command,
and used it for highlighting.
Y'all decided that "this is pretty much the same feature that has now been
integrated into Emacs". I don't have Emacs 21, so I took your word for it;
I know Emacs 21 has lots of great stuff.
I personally find it saves time and eye fatigue to have the search pattern
stand out from the context. The feature is simple, but helpful. If you turn
on Google highlighting, then you will appreciate this same feature for grep.
>From my code:
1. The grep pattern is used here to highlight occurrences in the *grep*
buffer (in function compilation-mode-font-lock-keywords):
;; NOTE: No account is taken here of case-insensitivity options to grep
;; (e.g. `-i'). This is not generally possible, as different grep's may
use
;; different options. Here, only the literal `grep-pattern' string is
;; highlighted.
(and grep-pattern ; Does nothing if this is not a grep command.
(list
(list (concat "\\(" (regexp-quote grep-pattern) "\\)")
1 grep-regexp-face)))
2. The grep pattern is used here to highlight the particulat occurrence in
the line visited by compilation-goto-locus (in function
compilation-goto-locus):
(set-window-point w (car next-error))
(set-window-start w (car next-error))
(highlight-regexp-region (save-excursion (beginning-of-line) (point))
(save-excursion (end-of-line) (point))
grep-pattern grep-regexp-face)
3. The grep pattern is saved here (in command grep):
(cond (;; Quoted pattern (either "..." or '...')
(string-match
(concat
grep-program
"[ \t]*\\(-[a-zA-Z]+\\s-+\\)*[ \t]*\\('[^']+'\\|\"[^\"]+\"\\)") ;"
command-args)
(setq grep-pattern
(substring command-args
(1+ (match-beginning 2)) (1- (match-end 2)))))
(;; Unquoted pattern.
(string-match
(concat grep-program
"[ \t]*\\(-[a-zA-Z]+\\s-+\\)*[ \t]*\\([^ \n\t'\"]+\\)") ; "
command-args)
(setq grep-pattern
(substring command-args (match-beginning 2) (match-end 2))))
(t;; Bad pattern.
(setq grep-pattern nil))
4. Function compile resets the grep pattern (from last grep) to nil.
HTH,
Drew
-----Original Message-----
From: emacs-devel-bounces+drew.adams=oracle.com@gnu.org
[mailto:emacs-devel-bounces+drew.adams=oracle.com@gnu.org]On Behalf Of
Richard Stallman
Sent: Monday, April 05, 2004 3:03 PM
To: emacs-devel@gnu.org
Subject: Highlighting in grep buffer
It would be useful to highlight the string in each line that matched
the specified regexp. It may be nontrivial to parse the command line
that was run, but it would be quite useful, even if it only works
in the most common cases.
next prev parent reply other threads:[~2004-04-05 23:05 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-04-05 22:03 Highlighting in grep buffer Richard Stallman
2004-04-05 23:05 ` Drew Adams [this message]
2004-04-07 17:45 ` Richard Stallman
2004-04-07 18:16 ` Drew Adams
2004-04-08 4:21 ` Juri Linkov
2004-04-08 16:38 ` Stefan Monnier
2004-04-10 22:29 ` Juri Linkov
2004-04-11 23:20 ` Stefan Monnier
2004-05-06 8:55 ` Juri Linkov
2004-05-06 14:39 ` Stefan Monnier
2004-05-06 21:03 ` Miles Bader
2004-05-08 21:46 ` Juri Linkov
2004-04-09 22:46 ` Richard Stallman
2004-04-10 22:28 ` Juri Linkov
2004-04-12 3:52 ` Richard Stallman
2004-04-12 4:32 ` Miles Bader
[not found] <DNEMKBNJBGPAOPIJOOICMEGCCAAA.drew.adams@oracle.com>
2004-04-13 11:45 ` Juri Linkov
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
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=FDELKNEBLPKKDCEBEJCBOEELCDAA.drew.adams@oracle.com \
--to=drew.adams@oracle.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 public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).