From 66fdbe77cc5e9baeace5ab05c6c7ba52d408b53c Mon Sep 17 00:00:00 2001 From: Vincent Zhang Date: Thu, 20 Apr 2017 09:51:04 +0800 Subject: [PATCH] Fix: Highlighting doesn't work with ripgrep 0.5.1. https://github.com/nlamirault/ripgrep.el/issues/20 --- lisp/init-utils.el | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/lisp/init-utils.el b/lisp/init-utils.el index 44bc6717d..f631eb46c 100644 --- a/lisp/init-utils.el +++ b/lisp/init-utils.el @@ -140,7 +140,36 @@ (setq wgrep-auto-save-buffer t) (setq wgrep-change-readonly-file t)) -(use-package ripgrep) +(use-package ripgrep + :config + ;; FIXME: Highlighting doesn't work with ripgrep 0.5.1 + ;; https://github.com/nlamirault/ripgrep.el/issues/20 + (setq ripgrep-executable "rg --color=always") + + ;; Taken from grep-filter, just changed the color regex. + (defun ripgrep-filter () + "Handle match highlighting escape sequences inserted by the rg process. +This function is called from `compilation-filter-hook'." + (when ripgrep-highlight-search + (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 rg matches and delete marking sequences. + (while (re-search-forward "\033\\[m\033\\[31m\033\\[1m\\(.*?\\)\033\\[[0-9]*m" end 1) + (replace-match (propertize (match-string 1) + 'face nil 'font-lock-face 'ripgrep-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)))))))) ;; Jump to definition via ag/rg/grep (use-package dumb-jump