[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/urgrep 9949a5b296 094/115: Use connection-local variabl
|
From: |
ELPA Syncer |
|
Subject: |
[elpa] externals/urgrep 9949a5b296 094/115: Use connection-local variables for caching the tool to use for each host |
|
Date: |
Wed, 10 May 2023 03:00:48 -0400 (EDT) |
branch: externals/urgrep
commit 9949a5b296928db0b771ab21f8ce3b216c715a84
Author: Jim Porter <jporterbugs@gmail.com>
Commit: Jim Porter <jporterbugs@gmail.com>
Use connection-local variables for caching the tool to use for each host
---
urgrep-tests.el | 26 +++++++++---------
urgrep.el | 81 +++++++++++++++++++++++++++++++++++----------------------
2 files changed, 63 insertions(+), 44 deletions(-)
diff --git a/urgrep-tests.el b/urgrep-tests.el
index 31c16d23e0..4b04268d09 100644
--- a/urgrep-tests.el
+++ b/urgrep-tests.el
@@ -487,54 +487,54 @@ joined to compare against COMMAND."
(ert-deftest urgrep-tests/get-tool/default ()
(cl-letf (((symbol-function #'executable-find) #'always))
- (let* ((urgrep--host-defaults)
+ (let* ((urgrep--cached-tool)
(tool (urgrep-get-tool)))
(should (equal (car tool) 'ugrep))
(should (equal (urgrep--get-prop 'executable-name tool) "ugrep"))
- (should (equal urgrep--host-defaults `((localhost . ,tool)))))))
+ (should (equal urgrep--cached-tool tool)))))
(ert-deftest urgrep-tests/get-tool/default-cached ()
(cl-letf (((symbol-function #'executable-find) #'always))
(let* ((ag (assq 'ag urgrep-tools))
- (urgrep--host-defaults `((localhost . ,ag)))
+ (urgrep--cached-tool ag)
(tool (urgrep-get-tool)))
(should (equal (car tool) 'ag))
(should (equal (urgrep--get-prop 'executable-name tool) "ag"))
- (should (equal urgrep--host-defaults `((localhost . ,ag)))))))
+ (should (equal urgrep--cached-tool ag)))))
(ert-deftest urgrep-tests/get-tool/preferred ()
(cl-letf (((symbol-function #'executable-find) #'always))
- (let* ((urgrep--host-defaults)
+ (let* ((urgrep--cached-tool)
(urgrep-preferred-tools '(ag grep))
(tool (urgrep-get-tool)))
(should (equal (car tool) 'ag))
(should (equal (urgrep--get-prop 'executable-name tool) "ag"))
- (should (equal urgrep--host-defaults `((localhost . ,tool)))))))
+ (should (equal urgrep--cached-tool tool)))))
(ert-deftest urgrep-tests/get-tool/preferred-cons ()
(cl-letf (((symbol-function #'executable-find) #'always))
- (let* ((urgrep--host-defaults)
+ (let* ((urgrep--cached-tool)
(urgrep-preferred-tools '((ag . "/usr/bin/ag")))
(tool (urgrep-get-tool)))
(should (equal (car tool) 'ag))
(should (equal (urgrep--get-prop 'executable-name tool) "/usr/bin/ag"))
- (should (equal urgrep--host-defaults `((localhost . ,tool)))))))
+ (should (equal urgrep--cached-tool tool)))))
(ert-deftest urgrep-tests/get-tool/key ()
(cl-letf (((symbol-function #'executable-find) #'always))
- (let* ((urgrep--host-defaults)
+ (let* ((urgrep--cached-tool)
(tool (urgrep-get-tool 'ag)))
(should (equal (car tool) 'ag))
(should (equal (urgrep--get-prop 'executable-name tool) "ag"))
- (should (equal urgrep--host-defaults nil)))))
+ (should (equal urgrep--cached-tool nil)))))
(ert-deftest urgrep-tests/get-tool/cons ()
(cl-letf (((symbol-function #'executable-find) #'always))
- (let* ((urgrep--host-defaults)
+ (let* ((urgrep--cached-tool)
(tool (urgrep-get-tool '(goofy (executable-name . "gf")))))
(should (equal (car tool) 'goofy))
(should (equal (urgrep--get-prop 'executable-name tool) "gf"))
- (should (equal urgrep--host-defaults nil)))))
+ (should (equal urgrep--cached-tool nil)))))
(ert-deftest urgrep-tests/get-tool/remote-host ()
(skip-unless (urgrep-tests/remote-accessible-p))
@@ -545,7 +545,7 @@ joined to compare against COMMAND."
(connection-local-set-profiles
(connection-local-criteria-for-default-directory) 'urgrep-test-ripgrep))
(cl-letf (((symbol-function #'executable-find) #'always)
- (urgrep--host-defaults nil))
+ (urgrep--cached-tool nil))
;; Get the preferred tool on the local host.
(let ((tool (with-connection-local-variables (urgrep-get-tool))))
(should (equal (car tool) 'ugrep))
diff --git a/urgrep.el b/urgrep.el
index 1cce781064..9f4afd767f 100644
--- a/urgrep.el
+++ b/urgrep.el
@@ -344,10 +344,22 @@ and the path of the executable."
,tool-choice (string :tag "Path")))))))
:group 'urgrep)
-(defvar urgrep--host-defaults nil
- "Default urgrep values for each known host.
-This is an alist of host symbols (`localhost' or a Tramp host) and
-the default tool to use on that host.")
+(defvar urgrep--cached-tool nil
+ "The cached urgrep tool to use.
+This value is connection-local.")
+
+(connection-local-set-profile-variables
+ 'urgrep-connection-local-profile
+ '((urgrep--cached-tool . nil)))
+
+(connection-local-set-profiles
+ '(:application tramp)
+ 'urgrep-connection-local-profile)
+
+(defsubst urgrep-connection-local-profile ()
+ "Get a connection-local profile name for urgrep."
+ (intern (concat "urgrep-connection-local-profile-"
+ (or (file-remote-p default-directory) "local"))))
(defun urgrep--get-prop (prop tool)
"Get the property PROP from TOOL, or nil if PROP is undefined."
@@ -379,33 +391,40 @@ each tool, possibly modified with the executable path
defined in
(defun urgrep--get-default-tool ()
"Get the preferred urgrep tool from `urgrep-tools'.
This caches the default tool per-host in `urgrep--host-defaults'."
- (if-let ((host-id (intern (or (file-remote-p default-directory)
"localhost")))
- (cached-tool (alist-get host-id urgrep--host-defaults)))
- 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
- (urgrep--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 (executable-find tool-executable t)
- (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
- (push (cons host-id tool) urgrep--host-defaults))
- (cl-return tool)))))))
+ (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
+ (urgrep--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 (executable-find tool-executable t)
+ (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))))))))
(defun urgrep-get-tool (&optional tool)
"Get the urgrep tool for TOOL.
- [elpa] externals/urgrep 3dde21c501 047/115: Add `urgrep-setup-hook', (continued)
- [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
- [elpa] externals/urgrep a9c1a98ea6 052/115: Prompt for directory first with 'C-u C-u M-x urgrep', ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep 3002fdf731 054/115: Add support for specifying executable path in 'urgrep-preferred-tools', ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep 55b0030cf9 061/115: Improve regexes to match result/context lines, ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep f354b44121 059/115: Always filter filenames in 'urgrep-filter', ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep 9e1f4da53b 070/115: Reorder keyword arguments to be more logical, ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep 0687d9e867 073/115: Update copyright, ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep ce07e97d37 088/115: Allow ANSI escapes for matches to end just after a newline, ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep dbb2c2caeb 095/115: Wrap some docstring lines with "\", ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep 9949a5b296 094/115: Use connection-local variables for caching the tool to use for each host,
ELPA Syncer <=
- [elpa] externals/urgrep 569c52f504 083/115: Allow overriding EMACS during tests, ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep d479dc5ad6 104/115: Remove unnecessary/wrong Git grep color settings, ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep d0012b9fcb 112/115: Tweak tests so they only work around Emacs bug#58265 on older versions, ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep 392e4bcb98 008/115: Don't inherit from compilation-minor-mode to avoid its menu, ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep c7a3cc5b30 015/115: Be less aggressive with shell-quoting on MS Windows, ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep bfab29d1d7 014/115: Add support for searches starting with "-", ELPA Syncer, 2023/05/10
- [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