aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Albinus2023-12-09 10:13:14 +0100
committerMichael Albinus2023-12-09 10:13:14 +0100
commit1908d2aefb2175875b837bafa1a4f1299a4bdb52 (patch)
tree4f49cdd24b40a119a3515054c589655d1f5de398
parent945aa0e42bc08879a9c979cbffb9b3f50e4945f3 (diff)
downloademacs-1908d2aefb2175875b837bafa1a4f1299a4bdb52.tar.gz
emacs-1908d2aefb2175875b837bafa1a4f1299a4bdb52.zip
New macro connection-local-value
* doc/lispref/variables.texi (Applying Connection Local Variables): Add macro 'connection-local-value'. * etc/NEWS: Add macro 'connection-local-value'. * lisp/files-x.el (connection-local-value): New macro. (path-separator, null-device): Use it. * test/lisp/files-x-tests.el (files-x-test-connection-local-value): New test.
-rw-r--r--doc/lispref/variables.texi6
-rw-r--r--etc/NEWS7
-rw-r--r--lisp/files-x.el19
-rw-r--r--test/lisp/files-x-tests.el61
4 files changed, 90 insertions, 3 deletions
diff --git a/doc/lispref/variables.texi b/doc/lispref/variables.texi
index f575b188fc6..bf5fbe84407 100644
--- a/doc/lispref/variables.texi
+++ b/doc/lispref/variables.texi
@@ -2545,6 +2545,12 @@ profile.
2545This variable must not be changed globally. 2545This variable must not be changed globally.
2546@end defvar 2546@end defvar
2547 2547
2548@defmac connection-local-value symbol &optional application
2549This macro returns the connection-local value of @var{symbol} for
2550@var{application}. If @var{symbol} does not have a connection-local
2551binding, the value is the default binding of the variable.
2552@end defmac
2553
2548@defvar enable-connection-local-variables 2554@defvar enable-connection-local-variables
2549If @code{nil}, connection-local variables are ignored. This variable 2555If @code{nil}, connection-local variables are ignored. This variable
2550shall be changed temporarily only in special modes. 2556shall be changed temporarily only in special modes.
diff --git a/etc/NEWS b/etc/NEWS
index 6e6ada42e46..8f3d8dea2a9 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1641,6 +1641,13 @@ A 5th argument, optional, has been added to
1641'modify-dir-local-variable'. It can be used to specify which 1641'modify-dir-local-variable'. It can be used to specify which
1642dir-locals file to modify. 1642dir-locals file to modify.
1643 1643
1644** Connection local variables
1645
1646+++
1647*** New macro 'connection-local-value'.
1648This macro returns the connection-local value of a variable if any, or
1649its current value.
1650
1644 1651
1645* Changes in Emacs 30.1 on Non-Free Operating Systems 1652* Changes in Emacs 30.1 on Non-Free Operating Systems
1646 1653
diff --git a/lisp/files-x.el b/lisp/files-x.el
index a8d525ec5ff..b2a9cf9bc5e 100644
--- a/lisp/files-x.el
+++ b/lisp/files-x.el
@@ -926,17 +926,30 @@ earlier in the `setq-connection-local'. The return value of the
926 connection-local-profile-name-for-setq))))) 926 connection-local-profile-name-for-setq)))))
927 927
928;;;###autoload 928;;;###autoload
929(defmacro connection-local-value (variable &optional application)
930 "Return connection-local VARIABLE for APPLICATION in `default-directory'.
931If VARIABLE does not have a connection-local binding, the value
932is the default binding of the variable."
933 (unless (symbolp variable)
934 (signal 'wrong-type-argument (list 'symbolp variable)))
935 `(let (connection-local-variables-alist file-local-variables-alist)
936 (hack-connection-local-variables
937 (connection-local-criteria-for-default-directory ,application))
938 (if-let ((result (assq ',variable connection-local-variables-alist)))
939 (cdr result)
940 ,variable)))
941
942;;;###autoload
929(defun path-separator () 943(defun path-separator ()
930 "The connection-local value of `path-separator'." 944 "The connection-local value of `path-separator'."
931 (with-connection-local-variables path-separator)) 945 (connection-local-value path-separator))
932 946
933;;;###autoload 947;;;###autoload
934(defun null-device () 948(defun null-device ()
935 "The connection-local value of `null-device'." 949 "The connection-local value of `null-device'."
936 (with-connection-local-variables null-device)) 950 (connection-local-value null-device))
937 951
938 952
939
940(provide 'files-x) 953(provide 'files-x)
941 954
942;;; files-x.el ends here 955;;; files-x.el ends here
diff --git a/test/lisp/files-x-tests.el b/test/lisp/files-x-tests.el
index 4e14ae68fb8..795d03a071d 100644
--- a/test/lisp/files-x-tests.el
+++ b/test/lisp/files-x-tests.el
@@ -482,5 +482,66 @@ If it's not initialized yet, initialize it."
482 `(connection-local-profile-alist ',clpa now) 482 `(connection-local-profile-alist ',clpa now)
483 `(connection-local-criteria-alist ',clca now)))) 483 `(connection-local-criteria-alist ',clca now))))
484 484
485(ert-deftest files-x-test-connection-local-value ()
486 "Test getting connection-local values."
487
488 (let ((clpa connection-local-profile-alist)
489 (clca connection-local-criteria-alist))
490 (connection-local-set-profile-variables
491 'remote-bash files-x-test--variables1)
492 (connection-local-set-profile-variables
493 'remote-ksh files-x-test--variables2)
494 (connection-local-set-profile-variables
495 'remote-nullfile files-x-test--variables3)
496
497 (connection-local-set-profiles
498 nil 'remote-ksh 'remote-nullfile)
499
500 (connection-local-set-profiles
501 files-x-test--application 'remote-bash)
502
503 (with-temp-buffer
504 ;; We need a remote `default-directory'.
505 (let ((enable-connection-local-variables t)
506 (default-directory "/method:host:")
507 (remote-null-device "null"))
508 (should-not connection-local-variables-alist)
509 (should-not (local-variable-p 'remote-shell-file-name))
510 (should-not (local-variable-p 'remote-null-device))
511 (should-not (boundp 'remote-shell-file-name))
512 (should (string-equal (symbol-value 'remote-null-device) "null"))
513
514 ;; The proper variable values are set.
515 (should
516 (string-equal
517 (connection-local-value remote-shell-file-name) "/bin/ksh"))
518 (should
519 (string-equal
520 (connection-local-value remote-null-device) "/dev/null"))
521
522 ;; Run with a different application.
523 (should
524 (string-equal
525 (connection-local-value
526 remote-shell-file-name (cadr files-x-test--application))
527 "/bin/bash"))
528 (should
529 (string-equal
530 (connection-local-value
531 remote-null-device (cadr files-x-test--application))
532 "/dev/null"))
533
534 ;; The previous bindings haven't changed.
535 (should-not connection-local-variables-alist)
536 (should-not (local-variable-p 'remote-shell-file-name))
537 (should-not (local-variable-p 'remote-null-device))
538 (should-not (boundp 'remote-shell-file-name))
539 (should (string-equal (symbol-value 'remote-null-device) "null"))))
540
541 ;; Cleanup.
542 (custom-set-variables
543 `(connection-local-profile-alist ',clpa now)
544 `(connection-local-criteria-alist ',clca now))))
545
485(provide 'files-x-tests) 546(provide 'files-x-tests)
486;;; files-x-tests.el ends here 547;;; files-x-tests.el ends here