[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/urgrep 61478da305 077/115: Improve reliability of runni
|
From: |
ELPA Syncer |
|
Subject: |
[elpa] externals/urgrep 61478da305 077/115: Improve reliability of running urgrep over Tramp |
|
Date: |
Wed, 10 May 2023 03:00:46 -0400 (EDT) |
branch: externals/urgrep
commit 61478da305ab801c1e887d6191a0f7fd3a4e4ea9
Author: Jim Porter <jporterbugs@gmail.com>
Commit: Jim Porter <jporterbugs@gmail.com>
Improve reliability of running urgrep over Tramp
In particular, this allows running urgrep to search a directory on a
different
host even when the current buffer is itself a urgrep buffer.
---
urgrep-tests.el | 4 +-
urgrep.el | 111 ++++++++++++++++++++++++++++----------------------------
2 files changed, 58 insertions(+), 57 deletions(-)
diff --git a/urgrep-tests.el b/urgrep-tests.el
index 3d84b98df1..479ec88552 100644
--- a/urgrep-tests.el
+++ b/urgrep-tests.el
@@ -518,7 +518,7 @@
(- match-start text-start)))))
(ert-deftest urgrep-tests-urgrep-group ()
- (switch-to-buffer (urgrep "urgrep" nil))
+ (switch-to-buffer (urgrep "urgrep"))
(should (and (equal urgrep-current-tool (urgrep-get-tool))
(local-variable-p 'urgrep-current-tool)))
(should (and (equal urgrep-current-query '("urgrep"))
@@ -530,7 +530,7 @@
(urgrep-tests--check-match-at-point))
(ert-deftest urgrep-tests-urgrep-nogroup ()
- (switch-to-buffer (urgrep "urgrep" nil :group nil))
+ (switch-to-buffer (urgrep "urgrep" :group nil))
(should (and (equal urgrep-current-tool (urgrep-get-tool))
(local-variable-p 'urgrep-current-tool)))
(should (and (equal urgrep-current-query '("urgrep" :group nil))
diff --git a/urgrep.el b/urgrep.el
index 79449de4de..0bb746b7d6 100644
--- a/urgrep.el
+++ b/urgrep.el
@@ -432,7 +432,8 @@ for MS shells."
;;;###autoload
(cl-defun urgrep-command (query &key tool regexp (case-fold 'inherit) files
- (group t) (context 0) (color t))
+ (group t) (context 0) (color t)
+ (directory default-directory))
"Return a command to use to search for QUERY.
Several keyword arguments can be supplied to adjust the resulting
command:
@@ -457,43 +458,44 @@ CONTEXT: the number of lines of context to show around
results; either
an integer (to show the same number of lines before and after) or a
cons (to show CAR and CDR lines before and after, respectively).
-COLOR: non-nil (the default) if the output should use color."
- (let* ((regexp-syntax (if (eq regexp t) urgrep-regexp-syntax regexp))
- (files (if (listp files) files (list files)))
- (tool (urgrep-get-tool tool))
- (tool-re-syntax (urgrep--get-best-syntax regexp-syntax tool))
- (query (urgrep--convert-regexp query regexp-syntax tool-re-syntax))
- (cmd-fun (urgrep--get-prop 'command-function tool)))
- ;; Determine whether to search case-sensitively or not.
- (when (eq case-fold 'inherit)
- (setq case-fold (if case-fold-search 'smart nil)))
- (when (eq case-fold 'smart)
- (setq case-fold (isearch-no-upper-case-p query regexp-syntax)))
- ;; Build the command arguments.
- (if cmd-fun
- (funcall cmd-fun query :tool tool :regexp regexp-syntax
- :case-fold case-fold :files files :group group
- :context context :color color)
- (let* ((executable (urgrep--get-prop 'executable-name tool))
- (arguments (urgrep--get-prop 'arguments tool)))
- (setq arguments (cl-substitute executable 'executable arguments))
- (setq arguments (cl-substitute query 'query arguments))
- ;; Fill in various options according to the tool's argument syntax.
- (pcase-dolist (`(,k . ,v) `((regexp . ,tool-re-syntax)
- (case-fold . ,case-fold)
- (file-wildcards . ,files)
- (group . ,group)
- (context . ,context)
- (color . ,color)))
- (let* ((prop (intern (concat (symbol-name k) "-arguments")))
- (args (urgrep--get-prop-pcase prop tool v)))
- (setq arguments (cl-substitute args k arguments))))
- (setq arguments (flatten-list arguments))
- ;; XXX: Should we wrap more code with
`with-connection-local-variables'?
- ;; There might be some other variables we use that would benefit from
- ;; being connection-local aware...
- (with-connection-local-variables
- (mapconcat #'urgrep--maybe-shell-quote-argument arguments " "))))))
+COLOR: non-nil (the default) if the output should use color.
+
+DIRECTORY: the directory to search in, or nil to use the
+`default-directory'."
+ (let ((default-directory (or directory default-directory)))
+ (with-connection-local-variables
+ (let* ((regexp-syntax (if (eq regexp t) urgrep-regexp-syntax regexp))
+ (files (if (listp files) files (list files)))
+ (tool (urgrep-get-tool tool))
+ (tool-re-syntax (urgrep--get-best-syntax regexp-syntax tool))
+ (query (urgrep--convert-regexp query regexp-syntax tool-re-syntax))
+ (cmd-fun (urgrep--get-prop 'command-function tool)))
+ ;; Determine whether to search case-sensitively or not.
+ (when (eq case-fold 'inherit)
+ (setq case-fold (if case-fold-search 'smart nil)))
+ (when (eq case-fold 'smart)
+ (setq case-fold (isearch-no-upper-case-p query regexp-syntax)))
+ ;; Build the command arguments.
+ (if cmd-fun
+ (funcall cmd-fun query :tool tool :regexp regexp-syntax
+ :case-fold case-fold :files files :group group
+ :context context :color color)
+ (let* ((executable (urgrep--get-prop 'executable-name tool))
+ (arguments (urgrep--get-prop 'arguments tool)))
+ (setq arguments (cl-substitute executable 'executable arguments))
+ (setq arguments (cl-substitute query 'query arguments))
+ ;; Fill in various options according to the tool's argument syntax.
+ (pcase-dolist (`(,k . ,v) `((regexp . ,tool-re-syntax)
+ (case-fold . ,case-fold)
+ (file-wildcards . ,files)
+ (group . ,group)
+ (context . ,context)
+ (color . ,color)))
+ (let* ((prop (intern (concat (symbol-name k) "-arguments")))
+ (args (urgrep--get-prop-pcase prop tool v)))
+ (setq arguments (cl-substitute args k arguments))))
+ (setq arguments (flatten-list arguments))
+ (mapconcat #'urgrep--maybe-shell-quote-argument arguments " ")))))))
;; urgrep-mode
@@ -944,12 +946,14 @@ future searches."
(case-fold urgrep-case-fold)
(files urgrep-file-wildcards)
(group urgrep-group-matches)
- (context urgrep-context-lines))
+ (context urgrep-context-lines)
+ (directory default-directory))
"Prompt the user for a search query starting with an INITIAL value.
Return a list that can be passed to `urgrep-command' to turn into a shell
-command. TOOL, GROUP, REGEXP, CASE-FOLD, CONTEXT, and FILES are as in
-`urgrep-command'."
- (let* ((urgrep-search-regexp regexp)
+command. TOOL, REGEXP, CASE-FOLD, FILES, GROUP, CONTEXT, and DIRECTORY
+ are as in `urgrep-command'."
+ (let* ((default-directory directory)
+ (urgrep-search-regexp regexp)
(urgrep-case-fold case-fold)
(urgrep-file-wildcards files)
(urgrep-context-lines context)
@@ -962,7 +966,7 @@ command. TOOL, GROUP, REGEXP, CASE-FOLD, CONTEXT, and
FILES are as in
(query (if (equal query "") default query)))
(list query :tool (urgrep-get-tool tool) :regexp urgrep-search-regexp
:case-fold urgrep-case-fold :files urgrep-file-wildcards :group group
- :context urgrep-context-lines)))
+ :context urgrep-context-lines :directory directory)))
(defun urgrep--read-command (command)
"Read a shell command to use for searching, with initial value COMMAND."
@@ -986,8 +990,8 @@ directory."
(t (read-directory-name "In directory: " nil nil t))))
;;;###autoload
-(defun urgrep (query directory &rest rest)
- "Recursively search in DIRECTORY for a given QUERY.
+(defun urgrep (query &rest rest)
+ "Recursively search for a given QUERY.
When called interactively, search in the project's root directory, or
the current directory if there is no current project. With
\\[universal-argument] prefix,
@@ -1006,12 +1010,12 @@ 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.
Type \\[urgrep-set-file-wildcards] to set a wildcard to filter the files
searched."
(interactive
- (let ((directory (urgrep--read-directory current-prefix-arg))
- (full-query (urgrep--read-query nil)))
- (cons (car full-query) (cons directory (cdr full-query)))))
+ (let ((directory (urgrep--read-directory current-prefix-arg)))
+ (urgrep--read-query nil :directory directory)))
(let* ((full-query (cons query rest))
(command (apply #'urgrep-command full-query))
- (tool (urgrep-get-tool (cadr (cl-member :tool full-query)))))
+ (tool (urgrep-get-tool (cadr (cl-member :tool full-query))))
+ (directory (cadr (cl-member :directory full-query))))
(urgrep--start command full-query tool directory)))
;;;###autoload
@@ -1021,14 +1025,11 @@ Type \\[urgrep-set-file-wildcards] to set a wildcard to
filter the files searche
When called interactively, this behaves like `urgrep', but allows you
to edit the command before running it."
(interactive
- (let ((directory (urgrep--read-directory current-prefix-arg))
- (query (urgrep--read-query nil)))
+ (let* ((directory (urgrep--read-directory current-prefix-arg))
+ (query (urgrep--read-query nil :directory directory)))
(list (urgrep--read-command (apply #'urgrep-command query))
directory (cadr (cl-member :tool query)))))
- (let ((tool (urgrep-get-tool tool))
- (default-directory (if directory (expand-file-name directory)
- default-directory)))
- (urgrep--start command command tool)))
+ (urgrep--start command command (urgrep-get-tool tool) directory))
;;;###autoload
(defun eshell/urgrep (&rest args)
- [elpa] externals/urgrep c26ff9b22b 029/115: Add note about grep issues on MS Windows, (continued)
- [elpa] externals/urgrep c26ff9b22b 029/115: Add note about grep issues on MS Windows, ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep 6f50ef99d3 032/115: Remove urgrep--to-command, ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep 3599ad1a56 033/115: Update comment, ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep ba2b01b91b 042/115: Remove no-longer-needed `post-arguments', ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep 3643c933c4 055/115: Add support for ugrep, ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep 0de93bfdb9 068/115: Fix use of wgrep on long urgrep results, ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep e2e8898ab2 074/115: Update copyright, ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep 0c966b2001 075/115: Ensure `default-directory' stays in sync, ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep c15be33112 076/115: Wrap shell argument quoting with `with-connection-local-variables`, ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep e63c6c5173 089/115: Add link to wgrep package and clarify the README, ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep 61478da305 077/115: Improve reliability of running urgrep over Tramp,
ELPA Syncer <=
- [elpa] externals/urgrep 77fcfc1916 090/115: Use `push` instead of `add-to-list`, ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep 559b2c07cd 091/115: Add a unit test for getting the preferred tool on multiple hosts, ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep fe13a3cbb5 081/115: Fix project-root call on Emacs 27, ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep f2c87e7520 080/115: Improve robustness of tests for grep command generation, ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep b03a3d84ec 098/115: Add `suffix` argument to `urgrep--get-prop(-pcase)?`, ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep eb5191bfd5 097/115: Update copyright year, ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep 43c82e84ec 082/115: Add CI for Emacs 27.1, ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep 3082d89bd9 099/115: Add support for abbreviating the command in urgrep buffers, ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep b5b426e9ca 084/115: Fix hiding excessive part of rgrep command in Emacs 28, ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep 56acdfe434 087/115: Improve how we wait for urgrep to finish in tests, ELPA Syncer, 2023/05/10