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: Changes to emacs/lisp/progmodes/grep.el Date: Wed, 30 Jun 2004 08:08:59 +0300 Organization: JURTA Sender: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Message-ID: <87oen1k4yc.fsf@mail.jurta.org> References: <87isdgnzzi.fsf@mail.jurta.org> <20040625220304.0f1fd05a@pfdabpc.inhouse.start.de> <20040627123340.5d3354cd@pfdabpc.inhouse.start.de> <20040628104013.5b4eb37e@pfdabpc.inhouse.start.de> <7494-Mon28Jun2004200058+0300-eliz@gnu.org> <20040628232216.5be7f8dd@pfdabpc.inhouse.start.de> <5567-Tue29Jun2004071049+0300-eliz@gnu.org> <20040629220851.07104e4c@pfdabpc.inhouse.start.de> NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1088572504 31004 80.91.224.253 (30 Jun 2004 05:15:04 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Wed, 30 Jun 2004 05:15:04 +0000 (UTC) Cc: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Wed Jun 30 07:14:55 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 1BfXQt-0007LQ-00 for ; Wed, 30 Jun 2004 07:14:55 +0200 Original-Received: from lists.gnu.org ([199.232.76.165]) by quimby.gnus.org with esmtp (Exim 3.35 #1 (Debian)) id 1BfXQs-0000sS-00 for ; Wed, 30 Jun 2004 07:14:55 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.33) id 1BfXSa-00082c-21 for emacs-devel@quimby.gnus.org; Wed, 30 Jun 2004 01:16:40 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.33) id 1BfXSW-00081w-7l for emacs-devel@gnu.org; Wed, 30 Jun 2004 01:16:36 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.33) id 1BfXSV-00081d-Aw for emacs-devel@gnu.org; Wed, 30 Jun 2004 01:16:35 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.33) id 1BfXSV-00081T-6r for emacs-devel@gnu.org; Wed, 30 Jun 2004 01:16:35 -0400 Original-Received: from [66.33.219.4] (helo=spork.dreamhost.com) by monty-python.gnu.org with esmtp (Exim 4.34) id 1BfXQS-0000Dl-Il for emacs-devel@gnu.org; Wed, 30 Jun 2004 01:14:29 -0400 Original-Received: from mail.jurta.org (80-235-43-232-dsl.mus.estpak.ee [80.235.43.232]) by spork.dreamhost.com (Postfix) with ESMTP id 90DEE11DC0C; Tue, 29 Jun 2004 22:14:13 -0700 (PDT) Original-To: Daniel Pfeiffer In-Reply-To: <20040629220851.07104e4c@pfdabpc.inhouse.start.de> (Daniel Pfeiffer's message of "Tue, 29 Jun 2004 22:08:51 +0200") 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:25318 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:25318 dapfy@t-online.de (Daniel Pfeiffer) writes: > The interesting question is what to do with M-x grep for > highlighting the matched string: > > - Is it better to delete the Escape sequences as Juri suggested and thus > irreversibly change the buffer contents such that it can't be rehighlighted? > > - Or do we maintain save-to-file and editability, by making the Escape > sequences invisible (and maybe solving the drawbacks somehow)? Solving the drawbacks of invisible text is a separate issue. There is a `search-invisible' option in isearch.el, but it can't find a string with invisible text inside it. To discard invisible text when yanking it's possible to implement an option like `yank-excluded-properties'. Another problem with invisible text is that C-M-f or C-M-b on invisible parens like ^[[01;41m signals an error "Unbalanced parentheses". But perhaps these drawbacks are negligible for grep mode. If not, they might be addressed later, or we can add an option to choose between hiding and deleting escape sequences. Anyhow, there is a new patch below which puts an `invisible' property on matched strings. I tested it, and I find it acceptable even with invisible text since I don't operate too much on the grep buffer. Daniel, you added a new option `grep-error-screen-columns' recently. But I don't see where it is used. Could you tell how do you plan to use it? Currently I set `compilation-error-screen-columns' to nil in `grep-regexp-alist', but perhaps I should use `grep-error-screen-columns'? BTW, as you can see below I also changed handling of `end-mk' in `compilation-goto-locus'. Currently it activates the region around a matched string. This is very inconvenient. I changed this to put a highlighted overlay on a matched string just as it does now for the whole line. Index: lisp/progmodes/grep.el =================================================================== RCS file: /cvsroot/emacs/emacs/lisp/progmodes/grep.el,v retrieving revision 1.16 diff -u -r1.16 grep.el --- lisp/progmodes/grep.el 23 Jun 2004 23:10:33 -0000 1.16 +++ lisp/progmodes/grep.el 30 Jun 2004 03:27:24 -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. @@ -227,6 +242,22 @@ '(("^\\(.+?\\)[:( \t]+\ \\([0-9]+\\)\\([.:]?\\)\\([0-9]+\\)?\ \\(?:-\\(?:\\([0-9]+\\)\\3\\)?\\.?\\([0-9]+\\)?\\)?[:) \t]" 1 (2 . 5) (4 . 6)) + ("^\\(.+?\\)[:(]+\\([0-9]+\\)\\([:)]\\).*?\\(\033\\[01;41m\\)\\(.*?\\)\\(\033\\[00m\\)" + 1 2 + ((lambda () + (setq compilation-error-screen-columns nil) + (- (match-beginning 5) (match-end 3) 8)) + . + (lambda () (- (match-end 5) (match-end 3) 8))) + nil nil + (4 (list 'face nil 'invisible t 'intangible t)) + (5 (list 'face compilation-column-face)) + (6 (list 'face nil 'invisible t 'intangible t)) + ;; highlight other matches on the same line + ("\\(\033\\[01;41m\\)\\(.*?\\)\\(\033\\[00m\\)" + nil nil + (1 (list 'face nil 'invisible t 'intangible t)) + (2 (list 'face compilation-column-face) t) + (3 (list 'face nil 'invisible t 'intangible t)))) ("^Binary file \\(.+\\) matches$" 1 nil nil 1)) "Regexp used to match grep hits. See `compilation-error-regexp-alist'.") @@ -291,6 +322,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: lisp/progmodes/compile.el =================================================================== RCS file: /cvsroot/emacs/emacs/lisp/progmodes/compile.el,v retrieving revision 1.322 diff -u -r1.322 compile.el --- lisp/progmodes/compile.el 18 Jun 2004 23:00:46 -0000 1.322 +++ lisp/progmodes/compile.el 30 Jun 2004 03:35:13 -0000 @@ -579,12 +579,17 @@ (and end-line (setq end-line (match-string-no-properties end-line)) (setq end-line (string-to-number end-line))) - (and col - (setq col (match-string-no-properties col)) - (setq col (- (string-to-number col) compilation-first-column))) - (if (and end-col (setq end-col (match-string-no-properties end-col))) - (setq end-col (- (string-to-number end-col) compilation-first-column -1)) - (if end-line (setq end-col -1))) + (if col + (if (functionp col) + (setq col (funcall col)) + (and + (setq col (match-string-no-properties col)) + (setq col (- (string-to-number col) compilation-first-column))))) + (if (and end-col (functionp end-col)) + (setq end-col (funcall end-col)) + (if (and end-col (setq end-col (match-string-no-properties end-col))) + (setq end-col (- (string-to-number end-col) compilation-first-column -1)) + (if end-line (setq end-col -1)))) (if (consp type) ; not a static type, check what it is. (setq type (or (and (car type) (match-end (car type)) 1) (and (cdr type) (match-end (cdr type)) 0) @@ -726,9 +731,9 @@ ,@(when end-line `((,end-line compilation-line-face nil t))) - ,@(when col + ,@(when (integerp col) `((,col compilation-column-face nil t))) - ,@(when end-col + ,@(when (integerp end-col) `((,end-col compilation-column-face nil t))) ,@(nthcdr 6 item) @@ -1535,9 +1542,7 @@ (unless (eq (goto-char mk) (point)) (widen) (goto-char mk)) - (if end-mk - (push-mark end-mk nil t) - (if mark-active (setq mark-active))) + (if mark-active (setq mark-active)) ;; If hideshow got in the way of ;; seeing the right place, open permanently. (dolist (ov (overlays-at (point))) @@ -1557,26 +1562,31 @@ compilation-highlight-regexp))) (compilation-set-window-height w) - (when (and highlight-regexp - (not (and end-mk transient-mark-mode))) + (when highlight-regexp (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 next-error-face)) (with-current-buffer (marker-buffer mk) (save-excursion - (end-of-line) + (if end-mk (goto-char end-mk) (end-of-line)) (let ((end (point))) - (beginning-of-line) + (if mk (goto-char mk) (beginning-of-line)) (if (and (stringp highlight-regexp) (re-search-forward highlight-regexp end t)) (progn -- Juri Linkov http://www.jurta.org/emacs/