aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChong Yidong2011-05-08 01:17:17 -0400
committerChong Yidong2011-05-08 01:17:17 -0400
commitd9c54a06a0883f6be111b498dc44a4fe38c7f49e (patch)
tree17de8fc8930e7679e3373e271b362cbb98767391
parentc46626351cb23fdb990174ad86da00bd4e159c81 (diff)
downloademacs-d9c54a06a0883f6be111b498dc44a4fe38c7f49e.tar.gz
emacs-d9c54a06a0883f6be111b498dc44a4fe38c7f49e.zip
Perform grep-mode's buffer modifications in a process filter (Bug#7952)
* progmodes/grep.el (grep-mode-font-lock-keywords): Remove buffer-changing entries. (grep-filter): New function. (grep-mode): Add it to compilation-filter-hook. * progmodes/compile.el (compilation-filter-hook) (compilation-filter-start): New defvars. (compilation-filter): Call compilation-filter-hook prior to updating the process mark.
-rw-r--r--etc/NEWS8
-rw-r--r--lisp/ChangeLog12
-rw-r--r--lisp/progmodes/compile.el15
-rw-r--r--lisp/progmodes/grep.el44
4 files changed, 53 insertions, 26 deletions
diff --git a/etc/NEWS b/etc/NEWS
index 319f5f8c958..9e9778c6ac1 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -377,9 +377,15 @@ $ESHELL nor variable `explicit-shell-file-name' is set.
377 377
378** comint and modes derived from it use the generic completion code. 378** comint and modes derived from it use the generic completion code.
379 379
380** The compile.el mode can be used without font-lock-mode. 380** Compilation mode
381
382*** Compilation mode can be used without font-lock-mode.
381`compilation-parse-errors-function' is now obsolete. 383`compilation-parse-errors-function' is now obsolete.
382 384
385*** `compilation-filter-start' is let-bound to the start of the text
386inserted by the compilation filter function, when calling
387compilation-filter-hook.
388
383** The Landmark game is now invoked with `landmark', not `lm'. 389** The Landmark game is now invoked with `landmark', not `lm'.
384 390
385** Prolog mode has been completely revamped, with lots of additional 391** Prolog mode has been completely revamped, with lots of additional
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index d50712503f2..3df4ba354eb 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,15 @@
12011-05-08 Chong Yidong <cyd@stupidchicken.com>
2
3 * progmodes/grep.el (grep-mode-font-lock-keywords): Remove
4 buffer-changing entries.
5 (grep-filter): New function.
6 (grep-mode): Add it to compilation-filter-hook.
7
8 * progmodes/compile.el (compilation-filter-hook)
9 (compilation-filter-start): New defvars.
10 (compilation-filter): Call compilation-filter-hook prior to
11 updating the process mark.
12
12011-05-08 Stefan Monnier <monnier@iro.umontreal.ca> 132011-05-08 Stefan Monnier <monnier@iro.umontreal.ca>
2 14
3 * emacs-lisp/eieio.el (defmethod): Fix typo in last change. 15 * emacs-lisp/eieio.el (defmethod): Fix typo in last change.
diff --git a/lisp/progmodes/compile.el b/lisp/progmodes/compile.el
index ec0830b3b1b..830de7d6244 100644
--- a/lisp/progmodes/compile.el
+++ b/lisp/progmodes/compile.el
@@ -64,6 +64,16 @@ the compilation to be killed, you can use this hook:
64 integer) 64 integer)
65 :group 'compilation) 65 :group 'compilation)
66 66
67(defvar compilation-filter-hook nil
68 "Hook run after `compilation-filter' has inserted a string into the buffer.
69It is called with the variable `compilation-filter-start' bound
70to the position of the start of the inserted text, and point at
71its end.")
72
73(defvar compilation-filter-start nil
74 "Start of the text inserted by `compilation-filter'.
75This is bound to a buffer position before running `compilation-filter-hook'.")
76
67(defvar compilation-first-column 1 77(defvar compilation-first-column 1
68 "*This is how compilers number the first column, usually 1 or 0.") 78 "*This is how compilers number the first column, usually 1 or 0.")
69 79
@@ -2038,11 +2048,12 @@ and runs `compilation-filter-hook'."
2038 ;; If we are inserting at the end of the accessible part of the 2048 ;; If we are inserting at the end of the accessible part of the
2039 ;; buffer, keep the inserted text visible. 2049 ;; buffer, keep the inserted text visible.
2040 (min (point-min-marker)) 2050 (min (point-min-marker))
2041 (max (copy-marker (point-max) t))) 2051 (max (copy-marker (point-max) t))
2052 (compilation-filter-start (marker-position (process-mark proc))))
2042 (unwind-protect 2053 (unwind-protect
2043 (progn 2054 (progn
2044 (widen) 2055 (widen)
2045 (goto-char (process-mark proc)) 2056 (goto-char compilation-filter-start)
2046 ;; We used to use `insert-before-markers', so that windows with 2057 ;; We used to use `insert-before-markers', so that windows with
2047 ;; point at `process-mark' scroll along with the output, but we 2058 ;; point at `process-mark' scroll along with the output, but we
2048 ;; now use window-point-insertion-type instead. 2059 ;; now use window-point-insertion-type instead.
diff --git a/lisp/progmodes/grep.el b/lisp/progmodes/grep.el
index 58f2ee98f3c..12295efc2d1 100644
--- a/lisp/progmodes/grep.el
+++ b/lisp/progmodes/grep.el
@@ -1,4 +1,4 @@
1;;; grep.el --- run Grep as inferior of Emacs, parse match messages 1;;; grep.el --- run `grep' and display the results
2 2
3;; Copyright (C) 1985-1987, 1993-1999, 2001-2011 3;; Copyright (C) 1985-1987, 1993-1999, 2001-2011
4;; Free Software Foundation, Inc. 4;; Free Software Foundation, Inc.
@@ -33,7 +33,7 @@
33 33
34 34
35(defgroup grep nil 35(defgroup grep nil
36 "Run grep as inferior of Emacs, parse error messages." 36 "Run `grep' and display the results."
37 :group 'tools 37 :group 'tools
38 :group 'processes) 38 :group 'processes)
39 39
@@ -399,26 +399,7 @@ Notice that using \\[next-error] or \\[compile-goto-error] modifies
399 (0 '(face nil compilation-message nil help-echo nil mouse-face nil) t) 399 (0 '(face nil compilation-message nil help-echo nil mouse-face nil) t)
400 (1 grep-error-face) 400 (1 grep-error-face)
401 (2 grep-error-face nil t)) 401 (2 grep-error-face nil t))
402 ("^.+?-[0-9]+-.*\n" (0 grep-context-face)) 402 ("^.+?-[0-9]+-.*\n" (0 grep-context-face)))
403 ;; Highlight grep matches and delete markers.
404 ;; FIXME: Modifying the buffer text from font-lock is a bad idea!
405 ("\\(\033\\[01;31m\\)\\(.*?\\)\\(\033\\[[0-9]*m\\)"
406 ;; Refontification does not work after the markers have been
407 ;; deleted. So we use the font-lock-face property here as Font
408 ;; Lock does not clear that.
409 (2 (list 'face nil 'font-lock-face grep-match-face))
410 ((lambda (bound))
411 (progn
412 ;; Delete markers with `replace-match' because it updates
413 ;; the match-data, whereas `delete-region' would render it obsolete.
414 (syntax-ppss-flush-cache (match-beginning 0))
415 (replace-match "" t t nil 3)
416 (replace-match "" t t nil 1))))
417 ("\033\\[[0-9;]*[mK]"
418 ;; Delete all remaining escape sequences
419 ((lambda (bound))
420 (syntax-ppss-flush-cache (match-beginning 0))
421 (replace-match "" t t))))
422 "Additional things to highlight in grep output. 403 "Additional things to highlight in grep output.
423This gets tacked on the end of the generated expressions.") 404This gets tacked on the end of the generated expressions.")
424 405
@@ -491,6 +472,22 @@ Set up `compilation-exit-message-function' and run `grep-setup-hook'."
491 (cons msg code)))) 472 (cons msg code))))
492 (run-hooks 'grep-setup-hook)) 473 (run-hooks 'grep-setup-hook))
493 474
475(defun grep-filter ()
476 "Handle match highlighting escape sequences inserted by the grep process.
477This function is called from `compilation-filter-hook'."
478 (save-excursion
479 (let ((end (point-marker)))
480 ;; Highlight grep matches and delete marking sequences.
481 (goto-char compilation-filter-start)
482 (while (re-search-forward "\033\\[01;31m\\(.*?\\)\033\\[[0-9]*m" end 1)
483 (replace-match (propertize (match-string 1)
484 'face nil 'font-lock-face grep-match-face)
485 t t))
486 ;; Delete all remaining escape sequences
487 (goto-char compilation-filter-start)
488 (while (re-search-forward "\033\\[[0-9;]*[mK]" end 1)
489 (replace-match "" t t)))))
490
494(defun grep-probe (command args &optional func result) 491(defun grep-probe (command args &optional func result)
495 (let (process-file-side-effects) 492 (let (process-file-side-effects)
496 (equal (condition-case nil 493 (equal (condition-case nil
@@ -697,7 +694,8 @@ Set up `compilation-exit-message-function' and run `grep-setup-hook'."
697 grep-regexp-alist) 694 grep-regexp-alist)
698 (set (make-local-variable 'compilation-process-setup-function) 695 (set (make-local-variable 'compilation-process-setup-function)
699 'grep-process-setup) 696 'grep-process-setup)
700 (set (make-local-variable 'compilation-disable-input) t)) 697 (set (make-local-variable 'compilation-disable-input) t)
698 (add-hook 'compilation-filter-hook 'grep-filter nil t))
701 699
702 700
703;;;###autoload 701;;;###autoload