emacs-diffs
[Top][All Lists]
Advanced

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

master aadcb906095: Handle local default directory in connection-local-v


From: Michael Albinus
Subject: master aadcb906095: Handle local default directory in connection-local-value
Date: Sun, 7 Jan 2024 06:40:04 -0500 (EST)

branch: master
commit aadcb906095e8588ed6302920bf835df20ab320f
Author: Michael Albinus <michael.albinus@gmx.de>
Commit: Michael Albinus <michael.albinus@gmx.de>

    Handle local default directory in connection-local-value
    
    * lisp/files-x.el (connection-local-p, connection-local-value):
    Handle local `default-directory'.
    
    * test/lisp/files-x-tests.el (files-x-test-connection-local-value):
    Extend test.
---
 lisp/files-x.el            | 27 +++++++++++++++++----------
 test/lisp/files-x-tests.el | 43 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 60 insertions(+), 10 deletions(-)

diff --git a/lisp/files-x.el b/lisp/files-x.el
index fccb2fa4a9f..f70be5f7ff3 100644
--- a/lisp/files-x.el
+++ b/lisp/files-x.el
@@ -929,19 +929,23 @@ earlier in the `setq-connection-local'.  The return value 
of the
 ;;;###autoload
 (defmacro connection-local-p (variable &optional application)
   "Non-nil if VARIABLE has a connection-local binding in `default-directory'.
+`default-directory' must be a remote file name.
 If APPLICATION is nil, the value of
 `connection-local-default-application' is used."
   (declare (debug (symbolp &optional form)))
   (unless (symbolp variable)
     (signal 'wrong-type-argument (list 'symbolp variable)))
-  `(let (connection-local-variables-alist file-local-variables-alist)
-     (hack-connection-local-variables
-      (connection-local-criteria-for-default-directory ,application))
-     (and (assq ',variable connection-local-variables-alist) t)))
+  `(let ((criteria
+          (connection-local-criteria-for-default-directory ,application))
+         connection-local-variables-alist file-local-variables-alist)
+     (when criteria
+       (hack-connection-local-variables criteria)
+       (and (assq ',variable connection-local-variables-alist) t))))
 
 ;;;###autoload
 (defmacro connection-local-value (variable &optional application)
   "Return connection-local VARIABLE for APPLICATION in `default-directory'.
+`default-directory' must be a remote file name.
 If APPLICATION is nil, the value of
 `connection-local-default-application' is used.
 If VARIABLE does not have a connection-local binding, the return
@@ -949,12 +953,15 @@ value is the default binding of the variable."
   (declare (debug (symbolp &optional form)))
   (unless (symbolp variable)
     (signal 'wrong-type-argument (list 'symbolp variable)))
-  `(let (connection-local-variables-alist file-local-variables-alist)
-     (hack-connection-local-variables
-      (connection-local-criteria-for-default-directory ,application))
-     (if-let ((result (assq ',variable connection-local-variables-alist)))
-         (cdr result)
-       ,variable)))
+  `(let ((criteria
+          (connection-local-criteria-for-default-directory ,application))
+         connection-local-variables-alist file-local-variables-alist)
+     (if (not criteria)
+         ,variable
+       (hack-connection-local-variables criteria)
+       (if-let ((result (assq ',variable connection-local-variables-alist)))
+           (cdr result)
+         ,variable))))
 
 ;;;###autoload
 (defun path-separator ()
diff --git a/test/lisp/files-x-tests.el b/test/lisp/files-x-tests.el
index a2f16d5ae35..528467a5641 100644
--- a/test/lisp/files-x-tests.el
+++ b/test/lisp/files-x-tests.el
@@ -553,6 +553,49 @@ If it's not initialized yet, initialize it."
         (should-not (boundp 'remote-shell-file-name))
         (should (string-equal (symbol-value 'remote-null-device) "null"))))
 
+    ;; `connection-local-value' and `connection-local-p' care about a
+    ;; local default directory.
+    (with-temp-buffer
+      (let ((enable-connection-local-variables t)
+           (default-directory temporary-file-directory)
+           (remote-null-device "null"))
+        (should-not connection-local-variables-alist)
+        (should-not (local-variable-p 'remote-shell-file-name))
+        (should-not (local-variable-p 'remote-null-device))
+        (should-not (boundp 'remote-shell-file-name))
+        (should (string-equal (symbol-value 'remote-null-device) "null"))
+
+        ;; The recent variable values are used.
+        (should-not (connection-local-p remote-shell-file-name))
+        ;; `remote-shell-file-name' is not defined, so we get an error.
+        (should-error
+         (connection-local-value remote-shell-file-name) :type 'void-variable)
+        (should-not (connection-local-p remote-null-device))
+        (should
+         (string-equal
+          (connection-local-value remote-null-device) remote-null-device))
+        (should-not (connection-local-p remote-lazy-var))
+
+        ;; Run with a different application.
+        (should-not
+         (connection-local-p
+          remote-shell-file-name (cadr files-x-test--application)))
+        ;; `remote-shell-file-name' is not defined, so we get an error.
+        (should-error
+         (connection-local-value
+          remote-shell-file-name (cadr files-x-test--application))
+         :type 'void-variable)
+        (should-not
+         (connection-local-p
+          remote-null-device (cadr files-x-test--application)))
+        (should
+         (string-equal
+          (connection-local-value
+           remote-null-device (cadr files-x-test--application))
+          remote-null-device))
+        (should-not
+         (connection-local-p remote-lazy-var (cadr 
files-x-test--application)))))
+
     ;; Cleanup.
     (custom-set-variables
      `(connection-local-profile-alist ',clpa now)



reply via email to

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