Created
January 22, 2013 00:15
-
-
Save sathlan/4590829 to your computer and use it in GitHub Desktop.
Inspiration for ag.el improvement.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; can be used to improve matching of ag.el. See also: | |
; - grep-mode-map | |
; - define-compilation-mode where everything happens | |
(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 "\033\\[0?1;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 beg) | |
(while (re-search-forward "\033\\[[0-9;]*[mK]" end 1) | |
(replace-match "" t t)))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment