Function: grep-filter

grep-filter is a byte-compiled function defined in grep.el.gz.

Signature

(grep-filter)

Documentation

Handle match highlighting escape sequences inserted by the grep process.

This function is called from compilation-filter-hook.

Source Code

;; Defined in /usr/src/emacs/lisp/progmodes/grep.el.gz
(defun grep-filter ()
  "Handle match highlighting escape sequences inserted by the grep process.
This function is called from `compilation-filter-hook'."
  (save-excursion
    (forward-line 0)
    (let ((end (point)) beg)
      (goto-char compilation-filter-start)
      (forward-line 0)
      (setq beg (point))
      ;; 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 grep-match-regexp end 1)
          (replace-match (propertize (match-string 1)
                                     'face nil 'font-lock-face grep-match-face)
                         t t)
          (cl-incf grep-num-matches-found))
        ;; Delete all remaining escape sequences
        (goto-char beg)
        (while (re-search-forward "\033\\[[0-9;]*[mK]" end 1)
          (replace-match "" t t))))))