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

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

[elpa] externals/urgrep 4eb854c070 2/4: Respect buffer-local values of `


From: ELPA Syncer
Subject: [elpa] externals/urgrep 4eb854c070 2/4: Respect buffer-local values of `urgrep-preferred-tools`
Date: Fri, 10 Nov 2023 18:58:52 -0500 (EST)

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

    Respect buffer-local values of `urgrep-preferred-tools`
---
 NEWS.md         |  3 ++-
 urgrep-tests.el | 10 ++++++++
 urgrep.el       | 72 +++++++++++++++++++++++++++++----------------------------
 3 files changed, 49 insertions(+), 36 deletions(-)

diff --git a/NEWS.md b/NEWS.md
index 7143f502b4..ceab95e0c2 100644
--- a/NEWS.md
+++ b/NEWS.md
@@ -2,7 +2,8 @@
 
 ## v0.3.0 (in progress)
 
-No changes yet
+### Bug fixes
+- Respect buffer-local values of `urgrep-preferred-tools`
 
 ---
 
diff --git a/urgrep-tests.el b/urgrep-tests.el
index 0faebe61db..f005b54ef2 100644
--- a/urgrep-tests.el
+++ b/urgrep-tests.el
@@ -668,6 +668,16 @@ joined to compare against COMMAND."
       (should (equal (urgrep--get-prop 'executable-name tool) "/usr/bin/ag"))
       (should (equal urgrep--cached-tool tool)))))
 
+(ert-deftest urgrep-tests/get-tool/preferred-buffer-local ()
+  (cl-letf (((symbol-function #'executable-find) #'always))
+    (let* ((urgrep--cached-tool)
+           (urgrep-preferred-tools '(ag grep)))
+      (should (equal (car (urgrep-get-tool)) 'ag))
+      (with-temp-buffer
+        (setq-local urgrep-preferred-tools '(ripgrep))
+        (should (equal (car (urgrep-get-tool)) 'ripgrep)))
+      (should (equal (car (urgrep-get-tool)) 'ag)))))
+
 (ert-deftest urgrep-tests/get-tool/key ()
   (cl-letf (((symbol-function #'executable-find) #'always))
     (let* ((urgrep--cached-tool)
diff --git a/urgrep.el b/urgrep.el
index 65c926f259..f6e9f68bda 100644
--- a/urgrep.el
+++ b/urgrep.el
@@ -524,40 +524,39 @@ each tool, possibly modified with the executable path 
defined in
   "Get the preferred urgrep tool from `urgrep-tools'.
 This caches the default tool per-host in `urgrep--host-defaults'."
   (with-connection-local-variables
-   (or urgrep--cached-tool
-       (let ((vc-backend-name)
-             (saw-vc-tool-p nil))
-         (cl-loop
-          for tool iter-by (urgrep--iter-tools) do
-          (let ((tool-executable (urgrep--get-prop 'executable-name tool))
-                (tool-vc-backend (urgrep--get-prop 'vc-backend tool)))
-            (setq saw-vc-tool-p (or saw-vc-tool-p tool-vc-backend))
-            ;; Cache the VC backend name if we need it.
-            (when-let (((and tool-vc-backend (not vc-backend-name)))
-                       (proj (project-current)))
-              (setq vc-backend-name (vc-responsible-backend
-                                     (project-root proj))))
-            ;; If we find the executable (and it's for the right VC backend, if
-            ;; relevant), cache it and then return it.
-            (when (and (seq-every-p (lambda (i) (executable-find i t))
-                                    (ensure-list tool-executable))
-                       (or (not tool-vc-backend)
-                           (string= vc-backend-name tool-vc-backend)))
-              ;; So long as we didn't examine a VC-specific tool, we can cache
-              ;; this result for future calls, since the result will always be
-              ;; the same.  If we *did* see a VC-specific tool, this host will
-              ;; use different tools for different directories, so we can't
-              ;; cache anything.
-              (unless saw-vc-tool-p
-                (setq urgrep--cached-tool tool)
-                (when (file-remote-p default-directory)
-                  (connection-local-set-profile-variables
-                   (urgrep-connection-local-profile)
-                   `((urgrep--cached-tool . ,urgrep--cached-tool)))
-                  (connection-local-set-profiles
-                   (connection-local-criteria-for-default-directory)
-                   (urgrep-connection-local-profile))))
-              (cl-return tool))))))))
+   (let ((use-cache (equal urgrep-preferred-tools
+                           (default-value 'urgrep-preferred-tools)))
+         vc-backend-name)
+     (if (and urgrep--cached-tool use-cache)
+         urgrep--cached-tool
+       (cl-loop
+        for tool iter-by (urgrep--iter-tools) do
+        (let ((tool-executable (urgrep--get-prop 'executable-name tool))
+              (tool-vc-backend (urgrep--get-prop 'vc-backend tool)))
+          ;; If we see a VC-specific tool, this host might use different tools
+          ;; for different directories, so we can't cache anything.
+          (setq use-cache (and use-cache (not tool-vc-backend)))
+          ;; Cache the VC backend name if we need it.
+          (when-let (((and tool-vc-backend (not vc-backend-name)))
+                     (proj (project-current)))
+            (setq vc-backend-name (vc-responsible-backend
+                                   (project-root proj))))
+          ;; If we find the executable (and it's for the right VC backend, if
+          ;; relevant), cache it if possible and then return it.
+          (when (and (seq-every-p (lambda (i) (executable-find i t))
+                                  (ensure-list tool-executable))
+                     (or (not tool-vc-backend)
+                         (string= vc-backend-name tool-vc-backend)))
+            (when use-cache
+              (setq urgrep--cached-tool tool)
+              (when (file-remote-p default-directory)
+                (connection-local-set-profile-variables
+                 (urgrep-connection-local-profile)
+                 `((urgrep--cached-tool . ,urgrep--cached-tool)))
+                (connection-local-set-profiles
+                 (connection-local-criteria-for-default-directory)
+                 (urgrep-connection-local-profile))))
+            (cl-return tool))))))))
 
 (defun urgrep-get-tool (&optional tool)
   "Get the urgrep tool for TOOL.
@@ -1185,12 +1184,15 @@ CONTEXT are as in `urgrep-command'.
 In addition, you can pass DEFAULT to specify the default search
 query.  If nil, guess the default based on the current region or
 point."
+  ;; Get the tool in the current buffer, in case `urgrep-preferred-tools' has a
+  ;; buffer-local value.
+  (setq tool (urgrep-get-tool tool))
   ;; Run this in a temporary buffer to make sure that none of the dynamic
   ;; variables below that we let-bind have buffer-local bindings.  If they did,
   ;; we wouldn't be able to retrieve the values for them that we set from 
inside
   ;; the minibuffer.
   (with-temp-buffer
-    (let* ((urgrep-current-tool (urgrep-get-tool tool))
+    (let* ((urgrep-current-tool tool)
            (urgrep-search-regexp regexp)
            (urgrep-case-fold case-fold)
            (urgrep-search-hidden-files hidden)



reply via email to

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