;;;###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
(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 ()
(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)