From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: "Drew Adams" Newsgroups: gmane.emacs.devel Subject: RE: Highlighting in grep buffer Date: Mon, 5 Apr 2004 16:05:35 -0700 Sender: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Message-ID: References: NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Trace: sea.gmane.org 1081206472 7122 80.91.224.253 (5 Apr 2004 23:07:52 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Mon, 5 Apr 2004 23:07:52 +0000 (UTC) Original-X-From: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Tue Apr 06 01:07:45 2004 Return-path: Original-Received: from quimby.gnus.org ([80.91.224.244]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1BAdBx-0001lJ-00 for ; Tue, 06 Apr 2004 01:07:45 +0200 Original-Received: from monty-python.gnu.org ([199.232.76.173]) by quimby.gnus.org with esmtp (Exim 3.35 #1 (Debian)) id 1BAdBx-0002Uf-00 for ; Tue, 06 Apr 2004 01:07:45 +0200 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.30) id 1BAdBv-0001KC-6i for emacs-devel@quimby.gnus.org; Mon, 05 Apr 2004 19:07:43 -0400 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.30) id 1BAdAz-0000Rd-8y for emacs-devel@gnu.org; Mon, 05 Apr 2004 19:06:45 -0400 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.30) id 1BAdA0-0007li-QR for emacs-devel@gnu.org; Mon, 05 Apr 2004 19:06:22 -0400 Original-Received: from [148.87.2.204] (helo=inet-mail4.oracle.com) by monty-python.gnu.org with esmtp (TLSv1:DES-CBC3-SHA:168) (Exim 4.30) id 1BAd9z-0007hv-HW; Mon, 05 Apr 2004 19:05:43 -0400 Original-Received: from rgmgw4.us.oracle.com (rgmgw4.us.oracle.com [138.1.191.13]) by inet-mail4.oracle.com (Switch-3.1.4/Switch-3.1.0) with ESMTP id i35N3egi002635; Mon, 5 Apr 2004 16:03:41 -0700 (PDT) Original-Received: from rgmgw4.us.oracle.com (localhost [127.0.0.1]) by rgmgw4.us.oracle.com (Switch-2.1.5/Switch-2.1.0) with ESMTP id i35N5bf20109; Mon, 5 Apr 2004 17:05:37 -0600 (MDT) Original-Received: from dradamslap (dradams-lap.us.oracle.com [130.35.177.126]) by rgmgw4.us.oracle.com (Switch-2.1.5/Switch-2.1.0) with SMTP id i35N5af20093; Mon, 5 Apr 2004 17:05:36 -0600 (MDT) Original-To: , X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook IMO, Build 9.0.6604 (9.0.2911.0) In-reply-to: X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 Importance: Normal X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.4 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Xref: main.gmane.org gmane.emacs.devel:21291 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:21291 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.