]> git.eshelyaron.com Git - emacs.git/commitdiff
Handle local default directory in connection-local-value
authorMichael Albinus <michael.albinus@gmx.de>
Sun, 7 Jan 2024 11:39:47 +0000 (12:39 +0100)
committerMichael Albinus <michael.albinus@gmx.de>
Sun, 7 Jan 2024 11:39:47 +0000 (12:39 +0100)
* 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
test/lisp/files-x-tests.el

index fccb2fa4a9fd6936b5beb061fcaa84fec86ea1fa..f70be5f7ff3f386f0b8f7a4b41570ad466e209ff 100644 (file)
@@ -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 ()
index a2f16d5ae35a03873421867a6eaef446d2e1e12b..528467a5641405eb9ba19e8c0aa589c4a2c05840 100644 (file)
@@ -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)