[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/urgrep 7780887977 005/115: Add initial support for git
From: |
ELPA Syncer |
Subject: |
[elpa] externals/urgrep 7780887977 005/115: Add initial support for git grep |
Date: |
Wed, 10 May 2023 03:00:37 -0400 (EDT) |
branch: externals/urgrep
commit 7780887977c2cbe7483f17ee42976f6767fdbcb4
Author: Jim Porter <jporterbugs@gmail.com>
Commit: Jim Porter <jporterbugs@gmail.com>
Add initial support for git grep
---
urgrep-test.el | 15 ++++++++++++---
urgrep.el | 47 ++++++++++++++++++++++++++++++++++++++---------
2 files changed, 50 insertions(+), 12 deletions(-)
diff --git a/urgrep-test.el b/urgrep-test.el
index e71f2ebd07..150e8f1bd5 100644
--- a/urgrep-test.el
+++ b/urgrep-test.el
@@ -30,10 +30,19 @@
(cl-letf (((symbol-function #'urgrep-get-tool)
(lambda () (assoc "ag" urgrep-tools))))
(should (equal (urgrep-command "foo")
- "ag --group --color-match 1\\;31 foo"))
+ "ag --color-path 35 --color-match 1\\;31 --group foo"))
(let ((urgrep-group-matches nil))
(should (equal (urgrep-command "foo")
- "ag --nogroup --color-match 1\\;31 foo")))))
+ "ag --color-path 35 --color-match 1\\;31 --nogroup
foo")))))
+
+(ert-deftest urgrep-test-command-git-grep ()
+ (cl-letf (((symbol-function #'urgrep-get-tool)
+ (lambda () (assoc "git-grep" urgrep-tools))))
+ (should (equal (urgrep-command "foo")
+ "git -c color.grep.filename\\=magenta grep -n --color
--heading --break foo"))
+ (let ((urgrep-group-matches nil))
+ (should (equal (urgrep-command "foo")
+ "git -c color.grep.filename\\=magenta grep -n --color
foo")))))
(ert-deftest urgrep-test-command-grep ()
(cl-letf (((symbol-function #'urgrep-get-tool)
@@ -50,7 +59,7 @@
(text-start (re-search-forward ":"))
(text-end (line-end-position))
(match-start (text-property-any text-start text-end 'font-lock-face
- 'urgrep-match-face)))
+ 'urgrep-match)))
(should (equal (caar (compilation--loc->file-struct loc))
"urgrep-test.el"))
(should (equal (compilation--loc->line loc) line))
diff --git a/urgrep.el b/urgrep.el
index 40237272fd..7b50196b29 100644
--- a/urgrep.el
+++ b/urgrep.el
@@ -72,7 +72,16 @@
(defvar urgrep-tools
`(("ag"
(executable-name "ag")
- (always-arguments ("--color-match" "1;31")))
+ (always-arguments ("--color-path" "35" "--color-match" "1;31"))
+ (group-arguments ((t ("--group"))
+ (nil ("--nogroup")))))
+ ;; XXX: Handle submodules for git-grep.
+ ("git-grep"
+ (executable-name "git")
+ (vc-backend "Git")
+ (always-arguments ("-c" "color.grep.filename=magenta" "grep" "-n"
+ "--color"))
+ (group-arguments ((t ("--heading" "--break")))))
("grep"
(executable-name "grep")
(command-function ,#'urgrep-rgrep--command)))
@@ -83,11 +92,26 @@
(when-let ((prop-entry (assoc prop (cdr tool))))
(cadr prop-entry)))
+(defun urgrep-get-property-assoc (tool prop key)
+ "Get a given property PROP from TOOL, selecting a KEY from the alist value."
+ (when-let ((prop-value (urgrep-get-property tool prop))
+ (assoc-value (assoc key prop-value)))
+ (cadr assoc-value)))
+
(defun urgrep-get-tool ()
"Get the preferred urgrep tool from `urgrep-tools'."
- (cl-dolist (i urgrep-tools)
- (when (executable-find (urgrep-get-property i 'executable-name) t)
- (cl-return i))))
+ (let ((vc-backend-name))
+ (cl-dolist (tool urgrep-tools)
+ (let ((tool-executable (urgrep-get-property tool 'executable-name))
+ (tool-vc-backend (urgrep-get-property tool 'vc-backend)))
+ ;; Cache the VC backend name if we need it.
+ (when (and tool-vc-backend (not vc-backend-name))
+ (setq vc-backend-name
+ (vc-responsible-backend (project-root (project-current)))))
+ (when (and (executable-find tool-executable t)
+ (or (not tool-vc-backend)
+ (string= vc-backend-name tool-vc-backend)))
+ (cl-return tool))))))
(defvar urgrep-mode-map
(let ((map (make-sparse-keymap)))
@@ -181,13 +205,18 @@ See `compilation-error-regexp-alist' for format details.")
(cmd-fun (urgrep-get-property tool 'command-function)))
(if cmd-fun
(funcall cmd-fun query)
- (let ((arguments (or (urgrep-get-property tool 'always-arguments) '())))
- (setq arguments (cons (if urgrep-group-matches "--group" "--nogroup")
- arguments))
+ (let ((executable (urgrep-get-property tool 'executable-name))
+ (always-args (or (urgrep-get-property tool 'always-arguments) '()))
+ (arguments '()))
+ ;; Fill in group arguments. Eventually there will be more arguments
like
+ ;; this. XXX: Maybe figure out a more flexible way to do this?
+ (let ((group (urgrep-get-property-assoc tool 'group-arguments
+ urgrep-group-matches)))
+ (when group (setq arguments (append group arguments))))
;; FIXME: Inside compile and dired buffers, `shell-quote-argument'
;; doesn't handle TRAMP right...
(mapconcat #'shell-quote-argument
- (append '("ag") arguments `(,query))
+ (append `(,executable) always-args arguments `(,query))
" ")))))
(defun urgrep-process-setup ()
@@ -235,7 +264,7 @@ This function is called from `compilation-filter-hook'."
;; Highlight matching filenames and delete ANSI escapes.
(when urgrep-group-matches
(goto-char beg)
- (while (re-search-forward "\033\\[1;32m\\(.*?\\)\033\\[0?m" end 1)
+ (while (re-search-forward "\033\\[35m\\(.*?\\)\033\\[0?m" end 1)
(replace-match
(propertize (match-string 1) 'face nil 'font-lock-face 'urgrep-hit
'urgrep-file-name t)
- [elpa] branch externals/urgrep created (now 7823d384e6), ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep ccd6fe0d4c 002/115: Add a basic keymap, ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep 8832dc103f 003/115: Add support for find/grep by delegating to Emacs' built-in `rgrep', ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep 133d308eec 004/115: Don't add `-face' to face names, ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep 4ec9d9febd 010/115: Fix behavior of temporarily overriding `urgrep-search-regexp', ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep 7780887977 005/115: Add initial support for git grep,
ELPA Syncer <=
- [elpa] externals/urgrep d965e6b848 007/115: Add the ability to toggle regexp mode when entering a search, ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep 764742fd14 006/115: Recurse submodules with git grep, ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep 6d9217c344 013/115: Rename urgrep-test.el to urgrep-tests.el, ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep aba02cc3f9 017/115: Add support for ripgrep and ack, ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep 53d72fe09c 023/115: Don't cache tool results for hosts which can use VC-specific tools, ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep 266965a0a2 024/115: Add support for intelligent editing of previous search commands, ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep 350d6d1889 027/115: Add support for regexp-syntax and context with the grep backend, ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep 887114113c 001/115: Initial revision, ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep b578b0f857 009/115: Add a README and more-detailed docstrings, ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep 026c54d11e 012/115: Add support for setting context, ELPA Syncer, 2023/05/10