branch: externals/urgrep
commit 3643c933c4264e3185942965f76c5a78abca4068
Author: Jim Porter <jporterb...@gmail.com>
Commit: Jim Porter <jporterb...@gmail.com>

    Add support for ugrep
---
 README.md       | 11 ++++++++-
 urgrep-tests.el | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++++++--
 urgrep.el       | 21 +++++++++++++++-
 3 files changed, 103 insertions(+), 4 deletions(-)

diff --git a/README.md b/README.md
index 07827482fd..701c80a4be 100644
--- a/README.md
+++ b/README.md
@@ -2,7 +2,8 @@
 
 **Urgrep** is an Emacs package to provide a universal frontend for *any*
 grep-like tool, as an alternative to the built-in `M-x rgrep` (and other 
similar
-packages). Currently, `ripgrep`, `ag`, `ack`, `git grep`, and `grep`/`find` are
+packages). Currently, [`ugrep`][ugrep], [`ripgrep`][ripgrep], [`ag`][ag],
+[`ack`][ack], [`git grep`][git-grep], and [`grep`][grep]/[`find`][find] are
 supported.
 
 ## Why Urgrep?
@@ -86,3 +87,11 @@ arguments. For more information, consult the docstring for 
`urgrep-command`.
 
 Feedback is welcome, but it's a bit early for code contributions. Thanks for 
the
 thought, though! (Hopefully this will change after not too long.)
+
+[ugrep]: https://github.com/Genivia/ugrep
+[ripgrep]: https://github.com/BurntSushi/ripgrep
+[ag]: https://github.com/ggreer/the_silver_searcher
+[ack]: https://beyondgrep.com/
+[git-grep]: https://git-scm.com/docs/git-grep
+[grep]: https://www.gnu.org/software/grep/
+[find]: https://www.gnu.org/software/findutils/
diff --git a/urgrep-tests.el b/urgrep-tests.el
index 5d04e4e90a..75f2d8c535 100644
--- a/urgrep-tests.el
+++ b/urgrep-tests.el
@@ -48,6 +48,77 @@
   (should (string= command (mapconcat #'urgrep--maybe-shell-quote-argument
                                       expected-arguments " "))))
 
+(ert-deftest urgrep-tests-command-ugrep ()
+  (let ((tool (assq 'ugrep urgrep-tools))
+        (common-args '("ugrep" "--color=always"
+                       "--colors=mt=01;31:fn=35:ln=:bn=:se=:sl=:cx=:ne"
+                       "-n" "--ignore-files")))
+    ;; String/case
+    (urgrep-test--check-command
+     (urgrep-command "foo" :tool tool)
+     (append common-args '("--heading" "--break" "-i" "-F" "-e" "foo")))
+    (urgrep-test--check-command
+     (urgrep-command "Foo" :tool tool)
+     (append common-args '("--heading" "--break" "-F" "-e" "Foo")))
+    (let ((case-fold-search nil))
+      (urgrep-test--check-command
+       (urgrep-command "foo" :tool tool)
+       (append common-args '("--heading" "--break" "-F" "-e" "foo"))))
+    (urgrep-test--check-command
+     (urgrep-command "foo" :tool tool :case-fold t)
+     (append common-args '("--heading" "--break" "-i" "-F" "-e" "foo")))
+    (urgrep-test--check-command
+     (urgrep-command "foo" :tool tool :case-fold nil)
+     (append common-args '("--heading" "--break" "-F" "-e" "foo")))
+    (urgrep-test--check-command
+     (urgrep-command "foo" :tool tool :case-fold 'smart)
+     (append common-args '("--heading" "--break" "-i" "-F" "-e" "foo")))
+    (urgrep-test--check-command
+     (urgrep-command "Foo" :tool tool :case-fold 'smart)
+     (append common-args '("--heading" "--break" "-F" "-e" "Foo")))
+    ;; Group
+    (urgrep-test--check-command
+     (urgrep-command "foo" :tool tool :group nil)
+     (append common-args '("-i" "-F" "-e" "foo")))
+    ;; Regexp
+    (urgrep-test--check-command
+     (urgrep-command "(foo)" :tool tool :regexp t)
+     (append common-args '("--heading" "--break" "-i" "-G" "-e" "(foo)")))
+    (urgrep-test--check-command
+     (urgrep-command "(foo)" :tool tool :regexp 'bre)
+     (append common-args '("--heading" "--break" "-i" "-G" "-e" "(foo)")))
+    (urgrep-test--check-command
+     (urgrep-command "(foo)" :tool tool :regexp 'ere)
+     (append common-args '("--heading" "--break" "-i" "-E" "-e" "(foo)")))
+    (urgrep-test--check-command
+     (urgrep-command "(foo)" :tool tool :regexp 'pcre)
+     (append common-args '("--heading" "--break" "-i" "-P" "-e" "(foo)")))
+    ;; Context
+    (urgrep-test--check-command
+     (urgrep-command "foo" :tool tool :context 3)
+     (append common-args '("--heading" "--break" "-C3" "-i" "-F" "-e" "foo")))
+    (urgrep-test--check-command
+     (urgrep-command "foo" :tool tool :context '(3 . 3))
+     (append common-args '("--heading" "--break" "-C3" "-i" "-F" "-e" "foo")))
+    (urgrep-test--check-command
+     (urgrep-command "foo" :tool tool :context '(2 . 4))
+     (append common-args '("--heading" "--break" "-B2" "-A4" "-i" "-F" "-e"
+                           "foo")))
+    ;; File wildcard
+    (urgrep-test--check-command
+     (urgrep-command "foo" :tool tool :files "*.el")
+     (append common-args '("--include=*.el" "--heading" "--break" "-i" "-F" 
"-e"
+                           "foo")))
+    (urgrep-test--check-command
+     (urgrep-command "foo" :tool tool :files '("*.c" "*.h"))
+     (append common-args '("--include=*.c" "--include=*.h" "--heading" 
"--break"
+                           "-i" "-F" "-e" "foo")))
+    ;; Color
+    (urgrep-test--check-command
+     (urgrep-command "foo" :tool tool :color nil)
+     (append '("ugrep" "--color=never" "-n" "--ignore-files" "--heading"
+               "--break" "-i" "-F" "-e" "foo")))))
+
 (ert-deftest urgrep-tests-command-ripgrep ()
   (let ((tool (assq 'ripgrep urgrep-tools))
         (common-args '("rg" "--color" "always" "--colors" "path:fg:magenta"
@@ -383,8 +454,8 @@
   (cl-letf (((symbol-function #'executable-find) #'always))
     (let* ((urgrep--host-defaults)
            (tool (urgrep-get-tool)))
-      (should (equal (car tool) 'ripgrep))
-      (should (equal (urgrep--get-prop 'executable-name tool) "rg"))
+      (should (equal (car tool) 'ugrep))
+      (should (equal (urgrep--get-prop 'executable-name tool) "ugrep"))
       (should (equal urgrep--host-defaults `((localhost . ,tool)))))))
 
 (ert-deftest urgrep-tests-get-tool-default-cached ()
diff --git a/urgrep.el b/urgrep.el
index 75974f1a4e..8554cde585 100644
--- a/urgrep.el
+++ b/urgrep.el
@@ -201,7 +201,26 @@ See also `grep-process-setup'."
   (setenv "GREP_COLORS" "mt=01;31:fn=:ln=:bn=:se=:sl=:cx=:ne"))
 
 (defvar urgrep-tools
-  `((ripgrep
+  `((ugrep
+     (executable-name . "ugrep")
+     (regexp-syntax bre ere pcre)
+     (arguments executable color "-n" "--ignore-files" file-wildcards group
+                context case-fold regexp "-e" query)
+     (color-arguments
+      ('nil '("--color=never"))
+      (_    '("--color=always"
+              "--colors=mt=01;31:fn=35:ln=:bn=:se=:sl=:cx=:ne")))
+     (group-arguments ((pred identity) '("--heading" "--break")))
+     (context-arguments . ,urgrep--context-arguments)
+     (regexp-arguments ('bre  '("-G"))
+                       ('ere  '("-E"))
+                       ('pcre '("-P"))
+                       (_     '("-F")))
+     (case-fold-arguments ((pred identity) '("-i")))
+     (file-wildcards-arguments
+      ((and x (pred identity))
+       (mapcar (lambda (i) (concat "--include=" i)) x))))
+    (ripgrep
      (executable-name . "rg")
      (regexp-syntax pcre)
      (arguments executable color file-wildcards group context case-fold regexp

Reply via email to