emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/urgrep 4cf7ef1381: Allow setting the search tool on the


From: ELPA Syncer
Subject: [elpa] externals/urgrep 4cf7ef1381: Allow setting the search tool on the fly
Date: Thu, 10 Aug 2023 03:58:55 -0400 (EDT)

branch: externals/urgrep
commit 4cf7ef13811febc7642593c85970b1a5e9fd2030
Author: Jim Porter <jporterbugs@gmail.com>
Commit: Jim Porter <jporterbugs@gmail.com>

    Allow setting the search tool on the fly
---
 NEWS.md   |  2 ++
 README.md |  1 +
 urgrep.el | 26 +++++++++++++++++++++++---
 3 files changed, 26 insertions(+), 3 deletions(-)

diff --git a/NEWS.md b/NEWS.md
index 175c7b5f55..0b6e08182b 100644
--- a/NEWS.md
+++ b/NEWS.md
@@ -5,6 +5,8 @@
 ### New features
 - Add support for toggling whether to search in hidden files (`M-s h` in the
   search prompt, or `urgrep-search-hidden-files` globally)
+- Allow setting the search tool to use on the fly when reading the query
+  (`M-s t` in the search prompt)
 
 ### Breaking changes
 - `urgrep-run-command` now takes `directory` and `tool` as optional keys
diff --git a/README.md b/README.md
index 4a537d580d..479a9b3b6a 100644
--- a/README.md
+++ b/README.md
@@ -44,6 +44,7 @@ Isearch-like key bindings to let you modify the search's 
behavior:
 | <kbd>M-s</kbd> <kbd>C</kbd> | Set number of lines of context²          |
 | <kbd>M-s</kbd> <kbd>B</kbd> | Set number of lines of leading context²  |
 | <kbd>M-s</kbd> <kbd>A</kbd> | Set number of lines of trailing context² |
+| <kbd>M-s</kbd> <kbd>t</kbd> | Set the search tool                      |
 
 > 1. Prompts with a recursive minibuffer<br>
 > 2. With a numeric prefix argument, set immediately; otherwise, use a 
 > recursive
diff --git a/urgrep.el b/urgrep.el
index 4a69071fa7..ad055d98d0 100644
--- a/urgrep.el
+++ b/urgrep.el
@@ -973,6 +973,7 @@ rerunning the search."
 (defvar urgrep-command-history nil "History list for urgrep commands.")
 (defvar-local urgrep--search-default nil
   "The default query for a urgrep search, used to update the prompt.")
+(defvar urgrep--minibuffer-tool)
 
 (defun urgrep--search-default ()
   "Return the default thing to search for.
@@ -1015,6 +1016,23 @@ indicates the default query, if any."
   ;; was at the beginning of the editable text.
   (if (< (point) (minibuffer-prompt-end)) (goto-char (minibuffer-prompt-end))))
 
+(defun urgrep-set-tool (tool)
+  "Set the TOOL to use for the current search.
+TOOL should be a symbol corresponding to one of the keys in
+`urgrep-tools'."
+  (interactive
+   (let* ((enable-recursive-minibuffers t)
+          (tool-string (completing-read
+                        (format-prompt "Tool" (car urgrep--minibuffer-tool))
+                        (mapcar (lambda (i) (symbol-name (car i)))
+                                urgrep-tools)
+                        nil 'require-match nil nil
+                        (symbol-name (car urgrep--minibuffer-tool)))))
+     (list (unless (string= tool-string "") (intern tool-string)))))
+  (when tool
+    (setq urgrep--minibuffer-tool (urgrep-get-tool tool))
+    (message "using %s" tool)))
+
 (defun urgrep-toggle-regexp ()
   "Toggle whether or not to use regexps for the search query.
 Within the `urgrep' search prompt, this sets the value only for the
@@ -1106,7 +1124,8 @@ future searches."
   "M-s h" #'urgrep-toggle-search-hidden-files
   "M-s C" #'urgrep-set-context
   "M-s B" #'urgrep-set-before-context
-  "M-s A" #'urgrep-set-after-context)
+  "M-s A" #'urgrep-set-after-context
+  "M-s t" #'urgrep-set-tool)
 
 (cl-defun urgrep--read-query (initial &key tool (regexp urgrep-search-regexp)
                                       (case-fold urgrep-case-fold)
@@ -1118,7 +1137,8 @@ future searches."
 Return a list that can be passed to `urgrep-command' to turn into
 a shell command. TOOL, REGEXP, CASE-FOLD, FILES, GROUP, and
 CONTEXT are as in `urgrep-command'."
-  (let* ((urgrep-search-regexp regexp)
+  (let* ((urgrep--minibuffer-tool (urgrep-get-tool tool))
+         (urgrep-search-regexp regexp)
          (urgrep-case-fold case-fold)
          (urgrep-search-hidden-files hidden)
          (urgrep-file-wildcards files)
@@ -1130,7 +1150,7 @@ CONTEXT are as in `urgrep-command'."
                   (read-from-minibuffer prompt initial urgrep-minibuffer-map 
nil
                                         'urgrep-search-history default)))
          (query (if (equal query "") default query)))
-    (list query :tool (urgrep-get-tool tool) :regexp urgrep-search-regexp
+    (list query :tool urgrep--minibuffer-tool :regexp urgrep-search-regexp
           :case-fold urgrep-case-fold :hidden urgrep-search-hidden-files
           :files urgrep-file-wildcards :group group
           :context urgrep-context-lines)))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]