From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.devel Subject: Re: Highlighting in grep buffer Date: Thu, 06 May 2004 11:55:49 +0300 Organization: JURTA Sender: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Message-ID: <87zn8m9boq.fsf@mail.jurta.org> References: <87hdvvhzgh.fsf@mail.jurta.org> <87isgafmte.fsf-monnier+emacs@alfajor.local> <87isg7cmcy.fsf@mail.jurta.org> NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1083835107 32306 80.91.224.253 (6 May 2004 09:18:27 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Thu, 6 May 2004 09:18:27 +0000 (UTC) Cc: rms@gnu.org, drew.adams@oracle.com, emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Thu May 06 11:18:20 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 1BLf1I-00010I-00 for ; Thu, 06 May 2004 11:18:20 +0200 Original-Received: from monty-python.gnu.org ([199.232.76.173]) by quimby.gnus.org with esmtp (Exim 3.35 #1 (Debian)) id 1BLf1H-0002HX-00 for ; Thu, 06 May 2004 11:18:19 +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 1BLezD-0002Qd-TH for emacs-devel@quimby.gnus.org; Thu, 06 May 2004 05:16:11 -0400 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.30) id 1BLeyT-0002Nk-Nv for emacs-devel@gnu.org; Thu, 06 May 2004 05:15:25 -0400 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.30) id 1BLekH-0005gu-CU for emacs-devel@gnu.org; Thu, 06 May 2004 05:01:16 -0400 Original-Received: from [66.33.219.19] (helo=spoon.dreamhost.com) by monty-python.gnu.org with esmtp (Exim 4.30) id 1BLegb-0004p9-5K; Thu, 06 May 2004 04:56:57 -0400 Original-Received: from mail.jurta.org (80-235-39-194-dsl.mus.estpak.ee [80.235.39.194]) by spoon.dreamhost.com (Postfix) with ESMTP id E35BA13D85C; Thu, 6 May 2004 01:56:53 -0700 (PDT) Original-To: Stefan Monnier In-Reply-To: (Stefan Monnier's message of "11 Apr 2004 19:20:25 -0400") User-Agent: Gnus/5.110002 (No Gnus v0.2) Emacs/21.3.50 (gnu/linux) 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:22837 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:22837 I was thinking about the best solution and it seems that using font-lock machinery for fontification of grep matches is the simplest and most consistent with principles which compile.el is based on: a new rule is added to `grep-mode-font-lock-keywords' which fontifies the text inside the grep markers and deletes them afterwards. I also made changes in `compilation-goto-locus' to highlight the matching string in the source buffer. The variable `highlight-regexp' is set to a string found in `compilation-locus' face. But perhaps this is not the best way to achieve the goal. Could someone familiar with compile.el suggest a better method, for example, something like setting the `message' property with calculated `col' and `end-col' on grep markers in `grep-mode-font-lock-keywords' and using them in `compilation-goto-locus'? Index: emacs/lisp/progmodes/grep.el =================================================================== RCS file: /cvsroot/emacs/emacs/lisp/progmodes/grep.el,v retrieving revision 1.12 diff -u -r1.12 grep.el --- emacs/lisp/progmodes/grep.el 20 Apr 2004 21:41:50 -0000 1.12 +++ emacs/lisp/progmodes/grep.el 6 May 2004 07:33:14 -0000 @@ -64,6 +64,21 @@ :version "21.4" :group 'grep) +(defcustom grep-highlight-matches t + "*Non-nil to use grep markers to highlight matching strings. + +Some grep programs are able to surround matching strings with +special markers in grep output. Such markers can be used to +highlight matching strings in grep mode. + +This option sets the environment variable GREP_COLOR to specify +markers for highlighting and GREP_OPTIONS to place the --color +option in front of any explicit grep options before starting +the grep." + :type 'boolean + :version "21.4" + :group 'grep) + (defcustom grep-scroll-output nil "*Non-nil to scroll the *grep* buffer window as output appears. @@ -244,7 +259,12 @@ ("^Grep \\(exited abnormally\\) with code \\([0-9]+\\).*" (0 '(face nil message nil help-echo nil mouse-face nil) t) (1 compilation-warning-face) - (2 compilation-line-face))) + (2 compilation-line-face)) + ("\033\\[01;41m\\([^\033\n]*\\)\033\\[00m" + (1 'compilation-locus) + ((lambda (p)) + (progn (delete-region (match-end 1) (match-end 0)) + (delete-region (match-beginning 0) (match-beginning 1)))))) "Additional things to highlight in grep output. This gets tacked on the end of the generated expressions.") @@ -281,6 +301,10 @@ (defun grep-process-setup () "Setup compilation variables and buffer for `grep'. Set up `compilation-exit-message-function' and run `grep-setup-hook'." + (when grep-highlight-matches + ;; Modify `process-environment' locally bound in `compilation-start' + (setenv "GREP_OPTIONS" (concat (getenv "GREP_OPTIONS") " --color=always")) + (setenv "GREP_COLOR" "01;41")) (set (make-local-variable 'compilation-exit-message-function) (lambda (status code msg) (if (eq status 'exit) Index: emacs/lisp/progmodes/compile.el =================================================================== RCS file: /cvsroot/emacs/emacs/lisp/progmodes/compile.el,v retrieving revision 1.316 diff -u -r1.316 compile.el --- emacs/lisp/progmodes/compile.el 2 May 2004 20:45:36 -0000 1.316 +++ emacs/lisp/progmodes/compile.el 6 May 2004 07:33:16 -0000 @@ -1541,10 +1541,17 @@ (w (or (get-buffer-window (marker-buffer msg) 'visible) ;; Pop up a window. (display-buffer (marker-buffer msg)))) + p (highlight-regexp (with-current-buffer (marker-buffer msg) ;; also do this while we change buffer (compilation-set-window w msg) - compilation-highlight-regexp))) + (if (setq p (text-property-any + (point) (line-end-position) + 'face 'compilation-locus)) + (buffer-substring-no-properties + p (next-single-char-property-change + p 'face)) + compilation-highlight-regexp)))) (compilation-set-window-height w) (when (and highlight-regexp @@ -1552,8 +1559,9 @@ (unless compilation-highlight-overlay (setq compilation-highlight-overlay (make-overlay (point-min) (point-min))) - (overlay-put compilation-highlight-overlay 'face 'region)) + (overlay-put compilation-highlight-overlay 'face 'compilation-locus)) (with-current-buffer (marker-buffer mk) + (setq p nil) (save-excursion (end-of-line) (let ((end (point))) @@ -1561,11 +1569,42 @@ (if (and (stringp highlight-regexp) (re-search-forward highlight-regexp end t)) (progn - (goto-char (match-beginning 0)) - (move-overlay compilation-highlight-overlay (match-beginning 0) (match-end 0))) - (move-overlay compilation-highlight-overlay (point) end)) - (sit-for 0.5) - (delete-overlay compilation-highlight-overlay))))))) + (goto-char (setq p (match-beginning 0))) + (move-overlay compilation-highlight-overlay (match-beginning 0) (match-end 0) (current-buffer))) + (move-overlay compilation-highlight-overlay (point) end (current-buffer))) + (sit-for 0.5) + (delete-overlay compilation-highlight-overlay))) + (if p (goto-char p)))))) + +(defface compilation-locus + '((t (:inherit region))) + "Face used to highlight compilation locus." + :group 'font-lock-highlighting-faces + :version "21.4") -- Juri Linkov http://www.jurta.org/emacs/