[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/urgrep e5d485de84 034/115: Improve behavior of `urgrep'
|
From: |
ELPA Syncer |
|
Subject: |
[elpa] externals/urgrep e5d485de84 034/115: Improve behavior of `urgrep' to allow passing options and add `urgrep-run-command' |
|
Date: |
Wed, 10 May 2023 03:00:40 -0400 (EDT) |
branch: externals/urgrep
commit e5d485de84cc5b492fa33a627caa199ecfa1e4b0
Author: Jim Porter <jporterbugs@gmail.com>
Commit: Jim Porter <jporterbugs@gmail.com>
Improve behavior of `urgrep' to allow passing options and add
`urgrep-run-command'
---
urgrep-tests.el | 9 +++++++++
urgrep.el | 46 +++++++++++++++++++++++++++++-----------------
2 files changed, 38 insertions(+), 17 deletions(-)
diff --git a/urgrep-tests.el b/urgrep-tests.el
index e5242cd54a..af5f9be4c4 100644
--- a/urgrep-tests.el
+++ b/urgrep-tests.el
@@ -282,4 +282,13 @@
(re-search-forward "urgrep-tests.el:")
(urgrep-tests--check-match-at-point))
+(ert-deftest urgrep-tests-urgrep-run-command ()
+ (switch-to-buffer
+ (urgrep-run-command "ag --color-path 35 --color-match 1\\;31 urgrep" nil))
+ (sit-for 1)
+ (goto-char (point-min))
+ (re-search-forward "urgrep-tests.el")
+ (beginning-of-line 2)
+ (urgrep-tests--check-match-at-point))
+
;;; urgrep-tests.el ends here
diff --git a/urgrep.el b/urgrep.el
index 57dd17d533..f9fe33212d 100644
--- a/urgrep.el
+++ b/urgrep.el
@@ -448,9 +448,9 @@ If EDIT-COMMAND is non-nil, the search can be edited."
(defun urgrep--grouped-filename ()
"Look backwards for the filename when a match is found in grouped output."
(save-excursion
- (let ((match (text-property-search-backward 'urgrep-file-name)))
- (buffer-substring (prop-match-beginning match)
- (prop-match-end match)))))
+ (if-let ((match (text-property-search-backward 'urgrep-file-name)))
+ (buffer-substring (prop-match-beginning match)
+ (prop-match-end match)))))
(defconst urgrep-regexp-alist
;; XXX: Try to rely on ANSI escapes as with the match highlight?
@@ -672,7 +672,7 @@ future searches."
(define-key map "\M-sA" #'urgrep-set-after-context)
map))
-(cl-defun urgrep--read-query (initial &key (group urgrep-group-matches)
+(cl-defun urgrep--read-query (initial &key tool (group urgrep-group-matches)
(regexp urgrep-search-regexp)
(case-fold urgrep-case-fold)
(context urgrep-context-lines))
@@ -689,8 +689,9 @@ command."
(read-from-minibuffer prompt initial urgrep-minibuffer-map
nil
'urgrep-search-history default)))
(query (if (equal query "") default query)))
- (list query :group group :regexp urgrep-search-regexp
- :case-fold urgrep-case-fold :context urgrep-context-lines)))
+ (list query :tool (urgrep-get-tool tool) :group group
+ :regexp urgrep-search-regexp :case-fold urgrep-case-fold
+ :context urgrep-context-lines)))
(defun urgrep--read-command (command)
"Read a shell command to use for searching, with initial value COMMAND."
@@ -714,7 +715,7 @@ directory."
(t (read-directory-name "In directory: " nil nil t))))
;;;###autoload
-(cl-defun urgrep (query directory &rest rest &key commandp &allow-other-keys)
+(cl-defun urgrep (query directory &rest rest &allow-other-keys)
"Recursively search in DIRECTORY for a given QUERY.
When called interactively, search in the project's root directory, or
@@ -733,17 +734,28 @@ Type \\[urgrep-set-context] to set the number of context
lines.
Type \\[urgrep-set-before-context] to set the number of before context lines.
Type \\[urgrep-set-after-context] to set the number of after context lines."
(interactive
- (list
- ;; This will wrap the command in a list so that we can tell it's a real
- ;; command, not just a query.
- (urgrep--read-query nil)
- (urgrep--read-directory current-prefix-arg)))
- (let ((command (cond ((listp query) (apply #'urgrep-command query))
- (commandp query)
- (t (apply #'urgrep-command query rest))))
- (default-directory (or directory default-directory)))
+ (list (urgrep--read-query nil)
+ (urgrep--read-directory current-prefix-arg)))
+ (let* ((query (if (listp query) query (cons query rest)))
+ (command (apply #'urgrep-command query))
+ (default-directory (or directory default-directory)))
(with-current-buffer (compilation-start command 'urgrep-mode)
- (setq urgrep-last-query (if (listp query) query command))
+ (setq urgrep-last-query query)
+ (current-buffer))))
+
+;;;###autoload
+(defun urgrep-run-command (command directory)
+ "Recursively search in DIRECTORY using the given COMMAND.
+
+When called interactively, this behaves like `urgrep', but allows you
+to edit the command before running it."
+ (interactive
+ (list (urgrep--read-command
+ (apply #'urgrep-command (urgrep--read-query nil)))
+ (urgrep--read-directory current-prefix-arg)))
+ (let ((default-directory (or directory default-directory)))
+ (with-current-buffer (compilation-start command 'urgrep-mode)
+ (setq urgrep-last-query command)
(current-buffer))))
(provide 'urgrep)
- [elpa] externals/urgrep 814ad5c60d 038/115: Update tests to work on MS Windows, (continued)
- [elpa] externals/urgrep 814ad5c60d 038/115: Update tests to work on MS Windows, ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep 86c36492b9 064/115: Include a description of how to enable wgrep support in the README, ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep 7453367e6d 065/115: Avoid false-positives when looking for context lines in results, ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep 593d209a31 067/115: Search in untracked files with git grep, ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep 1c08b41324 078/115: s/TRAMP/Tramp/g, ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep 6df13a8dee 071/115: Add support for urgrep command in Eshell, ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep 11e1f7474e 079/115: Add CI configuration, ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep a7d87da8b5 096/115: Slight improvements to docstrings for defcustoms, ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep 1172efb5a2 107/115: Don't allow using an unknown tool in `urgrep-command`, ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep 7823d384e6 115/115: Add .elpaignore, ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep e5d485de84 034/115: Improve behavior of `urgrep' to allow passing options and add `urgrep-run-command',
ELPA Syncer <=
- [elpa] externals/urgrep 31fe7d5e5c 022/115: Cache the default tool per-host and allow users to override the tool preferences, ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep 4fec944d51 016/115: Fix output of git-grep and grep on Linux, ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep f2ac6d6b02 011/115: Fix getting vc backend, ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep 3fb6b95f21 026/115: Add support for smart case-folding, ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep a405b9c459 031/115: Add ability to toggle case-sensitivity for the current search, ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep 74f38b1021 037/115: Add ability to filter the files to be searched, ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep 8065bb9f5e 039/115: Update requirements and fix failing MS Windows test, ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep b0dbe7c6c1 046/115: Update heading, ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep e9e70552db 057/115: Use 'format-prompt' if available, ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep 6f5813ba78 062/115: Add support for wgrep; resolves #2, ELPA Syncer, 2023/05/10