[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Changes to emacs/lisp/progmodes/grep.el
From: |
Juri Linkov |
Subject: |
Re: Changes to emacs/lisp/progmodes/grep.el |
Date: |
Fri, 25 Jun 2004 02:16:45 +0300 |
User-agent: |
Gnus/5.110002 (No Gnus v0.2) Emacs/21.3.50 (gnu/linux) |
Daniel Pfeiffer <address@hidden> writes:
> (grep-regexp-alist): Give it the full functionality of gnu style
> compilation messages with line and column ranges. Ask me for the
> perl script I'm working on, that uses these.
Requiring Emacs users to use a perl script is not a good solution.
But what about using the match highlighting feature of GNU grep?
With some changes in `compilation-mode-font-lock-keywords' and
`compilation-error-properties' this will allow to call functions
to compute columns of matches marked by grep.
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 25 Jun 2004 01:33:48 -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)
Index: lisp/progmodes/grep.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/progmodes/grep.el,v
retrieving revision 1.15
diff -u -r1.15 grep.el
--- lisp/progmodes/grep.el 18 Jun 2004 23:01:30 -0000 1.15
+++ lisp/progmodes/grep.el 25 Jun 2004 01:37:22 -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.
@@ -217,6 +232,12 @@
(defvar grep-regexp-alist
'(("^\\(.+?\\)[:( \t]+\\([0-9]+\\)\\([:)
\t]\\)\\(?:\\([0-9]+\\)\\(?:-\\([0-9]+\\)\\)?\\3\\)?" 1 2 (4 . 5))
+
("^\\(.+?\\)[:(]+\\([0-9]+\\)\\([:)]\\)[^\033\n]*\033\\[01;41m\\([^\033\n]*\\)\033\\[00m"
1 2
+ ((lambda ()
+ (setq compilation-error-screen-columns nil)
+ (- (match-beginning 4) (match-end 3) 8))
+ .
+ (lambda () (- (match-end 4) (match-end 3) 8))))
("^Binary file \\(.+\\) matches$" 1 nil nil 1))
"Regexp used to match grep hits. See `compilation-error-regexp-alist'.")
@@ -244,7 +265,13 @@
("^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 (list 'face compilation-column-face
+ 'font-lock-face compilation-column-face) t)
+ ((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 +308,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)
--
Juri Linkov
http://www.jurta.org/emacs/
- Re: Changes to emacs/lisp/progmodes/grep.el,
Juri Linkov <=
- Re: Changes to emacs/lisp/progmodes/grep.el, Daniel Pfeiffer, 2004/06/25
- Re: Changes to emacs/lisp/progmodes/grep.el, Juri Linkov, 2004/06/25
- Re: Changes to emacs/lisp/progmodes/grep.el, Richard Stallman, 2004/06/26
- Re: Changes to emacs/lisp/progmodes/grep.el, Daniel Pfeiffer, 2004/06/27
- Re: Changes to emacs/lisp/progmodes/grep.el, Adrian Aichner, 2004/06/27
- Re: Changes to emacs/lisp/progmodes/grep.el, Richard Stallman, 2004/06/27
- Re: Changes to emacs/lisp/progmodes/grep.el, Miles Bader, 2004/06/27
- Re: Changes to emacs/lisp/progmodes/grep.el, David Kastrup, 2004/06/28
- Re: Changes to emacs/lisp/progmodes/grep.el, Daniel Pfeiffer, 2004/06/28