branch: externals/urgrep commit aba02cc3f96fc77ef1c093eca4222aaf42f4e47f Author: Jim Porter <jporterb...@gmail.com> Commit: Jim Porter <jporterb...@gmail.com>
Add support for ripgrep and ack --- README.md | 2 +- urgrep-tests.el | 24 ++++++++++++++++++++++++ urgrep.el | 31 +++++++++++++++++++++++++++---- 3 files changed, 52 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index abb2c401f0..18b3e8c28e 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ Urgrep is an experimental Emacs package to provide an alternative to `M-x rgrep` (and similar packages) which will eventually support for *any* grep-like tool. -Currently, `ag`, `git grep`, and `grep`/`find` are supported. +Currently, `ripgrep`, `ag`, `ack`, `git grep`, and `grep`/`find` are supported. ## Using Urgrep diff --git a/urgrep-tests.el b/urgrep-tests.el index ec4d2c0e82..fd79b04b7b 100644 --- a/urgrep-tests.el +++ b/urgrep-tests.el @@ -26,6 +26,18 @@ (require 'ert) +(ert-deftest urgrep-tests-command-ripgrep () + (let ((tool (assoc "ripgrep" urgrep-tools)) + (common-args "rg --color always --colors path\\:fg\\:magenta --colors match\\:fg\\:red --colors match\\:style\\:bold ")) + (should (equal (urgrep-command "foo" :tool tool) + (concat common-args "-F --heading -- foo"))) + (should (equal (urgrep-command "foo" :tool tool :group nil) + (concat common-args "-F --no-heading -- foo"))) + (should (equal (urgrep-command "foo" :tool tool :regexp t) + (concat common-args "--heading -- foo"))) + (should (equal (urgrep-command "foo" :tool tool :context 3) + (concat common-args "-C3 -F --heading -- foo"))))) + (ert-deftest urgrep-tests-command-ag () (let ((tool (assoc "ag" urgrep-tools)) (common-args "ag --color-path 35 --color-match 1\\;31 ")) @@ -38,6 +50,18 @@ (should (equal (urgrep-command "foo" :tool tool :context 3) (concat common-args "-C3 -Q --group -- foo"))))) +(ert-deftest urgrep-tests-command-ack () + (let ((tool (assoc "ack" urgrep-tools)) + (common-args "ack --color-filename magenta --color-match bold\\ red ")) + (should (equal (urgrep-command "foo" :tool tool) + (concat common-args "-Q --group -- foo"))) + (should (equal (urgrep-command "foo" :tool tool :group nil) + (concat common-args "-Q --nogroup -- foo"))) + (should (equal (urgrep-command "foo" :tool tool :regexp t) + (concat common-args "--group -- foo"))) + (should (equal (urgrep-command "foo" :tool tool :context 3) + (concat common-args "-C3 -Q --group -- foo"))))) + (ert-deftest urgrep-tests-command-git-grep () (let ((tool (assoc "git-grep" urgrep-tools)) (common-args "git --no-pager -c color.grep.filename\\=magenta -c color.grep.match\\=bold\\ red grep --color -n --recurse-submodules ")) diff --git a/urgrep.el b/urgrep.el index 10451daa0d..98f3d03516 100644 --- a/urgrep.el +++ b/urgrep.el @@ -23,8 +23,8 @@ ;;; Commentary: -;; A universal frontend to various grep-like tools. Currently, ag, git-grep, and -;; grep are supported. +;; A universal frontend to various grep-like tools. Currently, ripgrep, ag, ack, +;; git-grep, and grep are supported. ;;; Code: @@ -79,7 +79,16 @@ (rgrep-default-command query "*" nil)) (defvar urgrep-tools - `(("ag" + `(("ripgrep" + (executable-name "rg") + (pre-arguments ("--color" "always" "--colors" "path:fg:magenta" + "--colors" "match:fg:red" "--colors" "match:style:bold")) + (post-arguments ("--")) + (group-arguments ((t ("--heading")) + (nil ("--no-heading")))) + (regexp-arguments ((nil ("-F")))) + (context-arguments "-C%d")) + ("ag" (executable-name "ag") (pre-arguments ("--color-path" "35" "--color-match" "1;31")) (post-arguments ("--")) @@ -87,6 +96,14 @@ (nil ("--nogroup")))) (regexp-arguments ((nil ("-Q")))) (context-arguments "-C%d")) + ("ack" + (executable-name "ack") + (pre-arguments ("--color-filename" "magenta" "--color-match" "bold red")) + (post-arguments ("--")) + (group-arguments ((t ("--group")) + (nil ("--nogroup")))) + (regexp-arguments ((nil ("-Q")))) + (context-arguments "-C%d")) ("git-grep" (executable-name "git") (vc-backend "Git") @@ -341,7 +358,13 @@ This function is called from `compilation-filter-hook'." (when (< (point) end) (setq end (copy-marker end)) ;; Highlight matches and delete ANSI escapes. - (while (re-search-forward "\033\\[0?1;31m\\(.*?\\)\033\\[0?m" end 1) + (while (re-search-forward + (concat "\\(?:" + "\033\\[0?1;31m" ; Find the escapes together... + "\\|" + "\033\\[1m\033\\[31m" ; ... or apart. + "\\)\\(.*?\\)\033\\[0?m") + end 1) (replace-match (propertize (match-string 1) 'face nil 'font-lock-face 'urgrep-match) t t)