unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Juri Linkov <juri@jurta.org>
Cc: emacs-devel@gnu.org
Subject: Re: Changes to emacs/lisp/progmodes/grep.el
Date: Wed, 30 Jun 2004 08:08:59 +0300	[thread overview]
Message-ID: <87oen1k4yc.fsf@mail.jurta.org> (raw)
In-Reply-To: <20040629220851.07104e4c@pfdabpc.inhouse.start.de> (Daniel Pfeiffer's message of "Tue, 29 Jun 2004 22:08:51 +0200")

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/

  parent reply	other threads:[~2004-06-30  5:08 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <E1BdGt8-0003Tg-Qb@lists.gnu.org>
2004-06-24 23:16 ` Changes to emacs/lisp/progmodes/grep.el Juri Linkov
2004-06-25 20:03   ` Daniel Pfeiffer
2004-06-26  0:03     ` Juri Linkov
2004-06-27 10:43       ` Daniel Pfeiffer
2004-06-26  6:03     ` Richard Stallman
2004-06-27 10:33       ` Daniel Pfeiffer
2004-06-27 11:58         ` Adrian Aichner
2004-06-28  2:23         ` Richard Stallman
2004-06-28  2:37           ` Miles Bader
2004-06-28  4:44           ` David Kastrup
2004-06-28  8:40             ` Daniel Pfeiffer
2004-06-28 18:00               ` Eli Zaretskii
2004-06-28 21:22                 ` Daniel Pfeiffer
2004-06-29  5:10                   ` Eli Zaretskii
2004-06-29 20:08                     ` Daniel Pfeiffer
2004-06-29 21:19                       ` Eli Zaretskii
2004-06-30  5:16                         ` Juri Linkov
2004-07-01 22:20                         ` Daniel Pfeiffer
2004-06-30  5:08                       ` Juri Linkov [this message]
2004-07-02 21:58                         ` Daniel Pfeiffer
2004-07-01 23:31                           ` Stefan
2004-07-01 23:38                             ` David Kastrup
2004-07-01 23:46                               ` Stefan
2004-07-03 18:20                               ` Richard Stallman
2004-07-04 10:47                                 ` Mark handling (Was: Changes to emacs/lisp/progmodes/grep.el) Daniel Pfeiffer
2004-07-05 16:56                                   ` Richard Stallman
2004-07-05 19:57                                     ` Daniel Pfeiffer
2004-07-06 22:00                                       ` Richard Stallman
2004-07-07 19:47                                         ` Daniel Pfeiffer
2004-07-08 23:18                                           ` Richard Stallman
2004-07-10 19:54                                             ` Daniel Pfeiffer
2004-07-06 22:00                                       ` Richard Stallman
2004-07-07 20:58                                         ` Richard Stallman
2004-07-02  0:20                             ` Transient mark mode (was: " Paul Pogonyshev
2004-07-03  8:28                             ` Changes to emacs/lisp/progmodes/grep.el Daniel Pfeiffer
2004-07-02  9:07                               ` Juri Linkov
2004-07-03 11:35                                 ` Daniel Pfeiffer
2004-07-02  8:48                           ` Juri Linkov
2004-07-06 16:55                         ` Juri Linkov
2004-07-06 18:16                           ` Luc Teirlinck
2004-07-07 20:57                           ` Richard Stallman
2004-06-30 18:52                       ` Richard Stallman
2004-07-01  5:08                         ` 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=87oen1k4yc.fsf@mail.jurta.org \
    --to=juri@jurta.org \
    --cc=emacs-devel@gnu.org \
    /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).