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: Fri, 25 Jun 2004 02:16:45 +0300 Organization: JURTA Sender: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Message-ID: <87isdgnzzi.fsf@mail.jurta.org> References: NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1088131046 28018 80.91.224.253 (25 Jun 2004 02:37:26 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Fri, 25 Jun 2004 02:37:26 +0000 (UTC) Cc: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Fri Jun 25 04:37:14 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 1BdgaY-000338-00 for ; Fri, 25 Jun 2004 04:37:14 +0200 Original-Received: from lists.gnu.org ([199.232.76.165]) by quimby.gnus.org with esmtp (Exim 3.35 #1 (Debian)) id 1BdgaX-0004Sw-00 for ; Fri, 25 Jun 2004 04:37:13 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.33) id 1Bdgby-0007RC-Sk for emacs-devel@quimby.gnus.org; Thu, 24 Jun 2004 22:38:42 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.33) id 1Bdgbv-0007R0-Gc for emacs-devel@gnu.org; Thu, 24 Jun 2004 22:38:39 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.33) id 1Bdgbu-0007Qo-MZ for emacs-devel@gnu.org; Thu, 24 Jun 2004 22:38:39 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.33) id 1Bdgbu-0007Ql-KW for emacs-devel@gnu.org; Thu, 24 Jun 2004 22:38:38 -0400 Original-Received: from [66.33.205.9] (helo=spatula.dreamhost.com) by monty-python.gnu.org with esmtp (Exim 4.34) id 1BdgaQ-0001pm-J8 for emacs-devel@gnu.org; Thu, 24 Jun 2004 22:37:06 -0400 Original-Received: from mail.jurta.org (80-235-35-178-dsl.mus.estpak.ee [80.235.35.178]) by spatula.dreamhost.com (Postfix) with ESMTP id 1E02F17D024; Thu, 24 Jun 2004 19:36:59 -0700 (PDT) Original-To: Daniel Pfeiffer In-Reply-To: (emacs-diffs-request@gnu.org's message of "Thu, 24 Jun 2004 03:25:07 -0700 (PDT)") 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:25242 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:25242 Daniel Pfeiffer 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/