[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/urgrep 350d6d1889 027/115: Add support for regexp-synta
From: |
ELPA Syncer |
Subject: |
[elpa] externals/urgrep 350d6d1889 027/115: Add support for regexp-syntax and context with the grep backend |
Date: |
Wed, 10 May 2023 03:00:40 -0400 (EDT) |
branch: externals/urgrep
commit 350d6d18892ac31e85acdcb966805fba2c572479
Author: Jim Porter <jporterbugs@gmail.com>
Commit: Jim Porter <jporterbugs@gmail.com>
Add support for regexp-syntax and context with the grep backend
---
urgrep-tests.el | 22 +++++++++++++---------
urgrep.el | 26 ++++++++++++++++++++------
2 files changed, 33 insertions(+), 15 deletions(-)
diff --git a/urgrep-tests.el b/urgrep-tests.el
index d9c8ed4fc4..e7fefa918f 100644
--- a/urgrep-tests.el
+++ b/urgrep-tests.el
@@ -147,29 +147,33 @@
(ert-deftest urgrep-tests-command-grep ()
(let ((tool (assoc "grep" urgrep-tools)))
;; String/case
- (should (string-match "^find \\. .*grep .*-i .*foo"
+ (should (string-match "^find \\. .*grep -F .*-i .*foo"
(urgrep-command "foo" :tool tool)))
- (should (string-match "^find \\. .*grep .*Foo"
+ (should (string-match "^find \\. .*grep -F .*Foo"
(urgrep-command "Foo" :tool tool)))
(let ((case-fold-search nil))
- (should (string-match "^find \\. .*grep .*foo"
+ (should (string-match "^find \\. .*grep -F .*foo"
(urgrep-command "foo" :tool tool))))
;; Group
- (should (string-match "^find \\. .*grep .*-i .*foo"
+ (should (string-match "^find \\. .*grep -F .*-i .*foo"
(urgrep-command "foo" :tool tool :group nil)))
;; Regexp
- (should (string-match "^find \\. .*grep .*-i .*\\\\(foo\\\\)"
+ (should (string-match "^find \\. .*grep -G .*-i .*\\\\(foo\\\\)"
(urgrep-command "(foo)" :tool tool
:regexp-syntax 'bre)))
- (should (string-match "^find \\. .*grep .*-i .*\\\\(foo\\\\)"
+ (should (string-match "^find \\. .*grep -E .*-i .*\\\\(foo\\\\)"
(urgrep-command "(foo)" :tool tool
:regexp-syntax 'ere)))
- (should (string-match "^find \\. .*grep .*-i .*\\\\(foo\\\\)"
+ (should (string-match "^find \\. .*grep -P .*-i .*\\\\(foo\\\\)"
(urgrep-command "(foo)" :tool tool
:regexp-syntax 'pcre)))
;; Context
- (should (string-match "^find \\. .*grep .*-i .*foo"
- (urgrep-command "foo" :tool tool :context 3)))))
+ (should (string-match "^find \\. .*grep -F -C3 .*-i .*foo"
+ (urgrep-command "foo" :tool tool :context 3)))
+ (should (string-match "^find \\. .*grep -F -C3 .*-i .*foo"
+ (urgrep-command "foo" :tool tool :context '(3 . 3))))
+ (should (string-match "^find \\. .*grep -F -B2 -A4 .*-i .*foo"
+ (urgrep-command "foo" :tool tool :context '(2 .
4))))))
(ert-deftest urgrep-tests-get-tool-default ()
(cl-letf (((symbol-function #'executable-find) #'always))
diff --git a/urgrep.el b/urgrep.el
index 39ef195278..b2a73571cb 100644
--- a/urgrep.el
+++ b/urgrep.el
@@ -82,11 +82,20 @@ If a cons, show CAR and CDR lines before and after,
respectively."
;; Urgrep tools
-(cl-defun urgrep-rgrep--command (query &key &allow-other-keys)
- ;; XXX: Support literal/regexp and context settings. Perhaps let-bind
- ;; `grep-find-template' to include these options?
+(cl-defun urgrep--rgrep-command (query &key tool regexp-syntax context
+ &allow-other-keys)
(grep-compute-defaults)
- (rgrep-default-command query "*" nil))
+ ;; Locally add options to `grep-find-template' that grep.el isn't aware of.
+ (let ((grep-find-template grep-find-template))
+ (dolist (i `((regexp-arguments . ,regexp-syntax)
+ (context-arguments . ,context)))
+ (when-let ((args (urgrep-get-property-pcase tool (car i) (cdr i)))
+ (args (mapconcat #'urgrep--maybe-shell-quote-argument args
+ " "))
+ ((string-match "<C>" grep-find-template)))
+ (setq grep-find-template
+ (replace-match (concat args " <C>") t t grep-find-template))))
+ (rgrep-default-command query "*" nil)))
(defconst urgrep--context-arguments
'(((or '(0 . 0) 0) nil)
@@ -145,7 +154,12 @@ If a cons, show CAR and CDR lines before and after,
respectively."
(case-fold-arguments (((pred identity) '("-i")))))
("grep"
(executable-name "grep")
- (command-function ,#'urgrep-rgrep--command)))
+ (command-function ,#'urgrep--rgrep-command)
+ (context-arguments ,urgrep--context-arguments)
+ (regexp-arguments (('bre '("-G"))
+ ('ere '("-E"))
+ ('pcre '("-P"))
+ (_ '("-F"))))))
"An alist of known tools to try when running urgrep.")
(defcustom urgrep-preferred-tools nil
@@ -248,7 +262,7 @@ for MS shells."
(context 0))
(if-let ((tool (urgrep-get-tool tool))
(cmd-fun (urgrep-get-property tool 'command-function)))
- (apply cmd-fun query rest)
+ (apply cmd-fun query :tool tool rest)
(let* ((tool-re-syntax (urgrep--get-best-syntax regexp-syntax tool))
(query (urgrep--convert-regexp query regexp-syntax tool-re-syntax))
(fold-case (and case-fold-search
- [elpa] externals/urgrep 8832dc103f 003/115: Add support for find/grep by delegating to Emacs' built-in `rgrep', (continued)
- [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, 2023/05/10
- [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 <=
- [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
- [elpa] externals/urgrep ca67ad1f4d 030/115: Use isearch-like bindings in the urgrep minibuffer, ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep 8bb469a526 036/115: Add some details about our buffer-local variables, ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep 9ff22a4481 041/115: Minor fixes to defcustoms, ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep c879c02558 040/115: Add some docs and clean up spacing, ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep 5b792fe0de 045/115: Use symbols instead of strings for `urgrep-tools' keys, ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep 3dde21c501 047/115: Add `urgrep-setup-hook', ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep f686c2baa3 051/115: Fix off-by-one error with matches in Emacs 28; see Emacs bug#49624, ELPA Syncer, 2023/05/10