]> code.delx.au - gnu-emacs/blobdiff - lisp/progmodes/grep.el
Add rx.el support for numbered groups (Bug#8776).
[gnu-emacs] / lisp / progmodes / grep.el
index 12295efc2d126918628d58f3acecef4d3e6c01ab..db8e82193b340fdd4c5c6061350cc618d766ef8f 100644 (file)
@@ -476,17 +476,23 @@ Set up `compilation-exit-message-function' and run `grep-setup-hook'."
   "Handle match highlighting escape sequences inserted by the grep process.
 This function is called from `compilation-filter-hook'."
   (save-excursion
-    (let ((end (point-marker)))
-      ;; Highlight grep matches and delete marking sequences.
+    (forward-line 0)
+    (let ((end (point)))
       (goto-char compilation-filter-start)
-      (while (re-search-forward "\033\\[01;31m\\(.*?\\)\033\\[[0-9]*m" end 1)
-       (replace-match (propertize (match-string 1)
-                                  'face nil 'font-lock-face grep-match-face)
-                      t t))
-      ;; Delete all remaining escape sequences
-      (goto-char compilation-filter-start)
-      (while (re-search-forward "\033\\[[0-9;]*[mK]" end 1)
-       (replace-match "" t t)))))
+      (forward-line 0)
+      ;; Only operate on whole lines so we don't get caught with part of an
+      ;; escape sequence in one chunk and the rest in another.
+      (when (< (point) end)
+        (setq end (copy-marker end))
+        ;; Highlight grep matches and delete marking sequences.
+        (while (re-search-forward "\033\\[01;31m\\(.*?\\)\033\\[[0-9]*m" end 1)
+          (replace-match (propertize (match-string 1)
+                                     'face nil 'font-lock-face grep-match-face)
+                         t t))
+        ;; Delete all remaining escape sequences
+        (goto-char compilation-filter-start)
+        (while (re-search-forward "\033\\[[0-9;]*[mK]" end 1)
+          (replace-match "" t t))))))
 
 (defun grep-probe (command args &optional func result)
   (let (process-file-side-effects)
@@ -692,6 +698,9 @@ This function is called from `compilation-filter-hook'."
        grep-hit-face)
   (set (make-local-variable 'compilation-error-regexp-alist)
        grep-regexp-alist)
+  ;; compilation-directory-matcher can't be nil, so we set it to a regexp that
+  ;; can never match.
+  (set (make-local-variable 'compilation-directory-matcher) '("\\`a\\`"))
   (set (make-local-variable 'compilation-process-setup-function)
        'grep-process-setup)
   (set (make-local-variable 'compilation-disable-input) t)