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.
This commit is contained in:
parent
f866c85ac4
commit
aadcb90609
2 changed files with 60 additions and 10 deletions
|
@ -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 ()
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Add table
Reference in a new issue