summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Albinus <michael.albinus@gmx.de>2022-03-18 12:25:32 +0100
committerMichael Albinus <michael.albinus@gmx.de>2022-03-18 12:25:32 +0100
commit499f2085fa6fce6c7a2868c8d27d465f43d53f0f (patch)
treec5a77d92b9933a5c9ee38cb6fa2f3d5b97aebaa7
parentce26657b5d7e77d851ed9267d554f4f48e43a0b6 (diff)
downloademacs-499f2085fa6fce6c7a2868c8d27d465f43d53f0f.tar.gz
Make application configurable in 'with-connection-local-variables'
* doc/lispref/variables.texi (Connection Local Variables): Explain 'connection-local-default-application'. * etc/NEWS: Mention 'connection-local-default-application'. * lisp/files-x.el (connection-local-default-application): New variable. (connection-local-criteria-for-default-directory): Use it. (Bug#54405) * test/lisp/files-x-tests.el (files-x-test-with-connection-local-variables): Extend test.
-rw-r--r--doc/lispref/variables.texi31
-rw-r--r--etc/NEWS18
-rw-r--r--lisp/files-x.el14
-rw-r--r--test/lisp/files-x-tests.el18
4 files changed, 72 insertions, 9 deletions
diff --git a/doc/lispref/variables.texi b/doc/lispref/variables.texi
index d991ae9e277..cd39e6b6470 100644
--- a/doc/lispref/variables.texi
+++ b/doc/lispref/variables.texi
@@ -2418,6 +2418,37 @@ are unwound. Example:
@end example
@end defmac
+@defvar connection-local-default-application
+The default application, a symbol, to be applied in
+@code{with-connection-local-variables}. It defaults to @code{tramp},
+but in case you want to overwrite Tramp's settings temporarily, you
+could let-bind it like
+
+@example
+@group
+(connection-local-set-profile-variables
+ 'my-remote-perl
+ '((perl-command-name . "/usr/local/bin/perl5")
+ (perl-command-switch . "-e %s")))
+@end group
+
+@group
+(connection-local-set-profiles
+ '(:application 'my-app :protocol "ssh" :machine "remotehost")
+ 'my-remote-perl)
+@end group
+
+@group
+(let ((default-directory "/ssh:remotehost:/working/dir/")
+ (connection-local-default-application 'my-app))
+ (with-connection-local-variables
+ do something useful))
+@end group
+@end example
+
+This variable must not be changed globally.
+@end defvar
+
@defvar enable-connection-local-variables
If @code{nil}, connection-local variables are ignored. This variable
shall be changed temporarily only in special modes.
diff --git a/etc/NEWS b/etc/NEWS
index e2546bb3ca5..c20d683710d 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -269,12 +269,22 @@ defaults to t, which makes Emacs use the toolkit tooltips. The
existing GTK-specific option 'x-gtk-use-system-tooltips' is now an
alias of this new option.
+** Connection-local variables
+
+++
-** Some connection-local variables are now user options.
+*** Some connection-local variables are now user options.
The variables 'connection-local-profile-alist' and
'connection-local-criteria-alist' are now user options, in order to
make it more convenient to inspect and modify them.
++++
+*** The default connection-local application can be changed temporarily.
+Running 'with-connection-local-variables' defaults to application
+'tramp'. This can be changed by let-binding
+'connection-local-default-application' to another symbol. This is
+useful when running code in a buffer, where Tramp has already set some
+connection local variables.
+
---
** New minor mode 'pixel-scroll-precision-mode'.
When enabled, and if your mouse supports it, you can scroll the
@@ -647,7 +657,7 @@ It narrows to the current node.
+++
*** 'eudc-expansion-overwrites-query' to 'eudc-expansion-save-query-as-kill'.
-Rename 'eudc-expansion-overwrites-query' to
+'eudc-expansion-overwrites-query' is renamed to
'eudc-expansion-save-query-as-kill' to reflect the actual behaviour of
the customization variable.
@@ -933,7 +943,7 @@ the thumbnail file.
** Dired
*** New user option 'dired-mouse-drag-files'.
-If non-nil, dragging filenames with the mouse in a Dired buffer will
+If non-nil, dragging file names with the mouse in a Dired buffer will
initiate a drag-and-drop session allowing them to be opened in other
programs.
@@ -1000,7 +1010,7 @@ and friends.
---
*** Tramp supports abbreviating remote home directories now.
-When calling 'abbreviate-file-name' on a Tramp filename, the result
+When calling 'abbreviate-file-name' on a Tramp file name, the result
will abbreviate the user's home directory, for example by abbreviating
"/ssh:user@host:/home/user" to "/ssh:user@host:~".
diff --git a/lisp/files-x.el b/lisp/files-x.el
index 319bfe05655..0ae9fb076eb 100644
--- a/lisp/files-x.el
+++ b/lisp/files-x.el
@@ -722,14 +722,18 @@ will not be changed."
(copy-tree connection-local-variables-alist)))
(hack-local-variables-apply)))
+(defvar connection-local-default-application 'tramp
+ "Default application in connection-local functions, a symbol.
+This variable must not be changed globally.")
+
(defsubst connection-local-criteria-for-default-directory (&optional application)
"Return a connection-local criteria, which represents `default-directory'.
-If APPLICATION is nil, the symbol `tramp' is used."
+If APPLICATION is nil, `connection-local-default-application' is used."
(when (file-remote-p default-directory)
- `(:application ,(or application 'tramp)
- :protocol ,(file-remote-p default-directory 'method)
- :user ,(file-remote-p default-directory 'user)
- :machine ,(file-remote-p default-directory 'host))))
+ `(:application ,(or application connection-local-default-application)
+ :protocol ,(file-remote-p default-directory 'method)
+ :user ,(file-remote-p default-directory 'user)
+ :machine ,(file-remote-p default-directory 'host))))
;;;###autoload
(defmacro with-connection-local-variables (&rest body)
diff --git a/test/lisp/files-x-tests.el b/test/lisp/files-x-tests.el
index 60787e1cd3d..7ee2f0c1a65 100644
--- a/test/lisp/files-x-tests.el
+++ b/test/lisp/files-x-tests.el
@@ -325,6 +325,9 @@
(should-not (boundp 'remote-shell-file-name))
(should (string-equal (symbol-value 'remote-null-device) "null"))
+ (connection-local-set-profiles
+ files-x-test--application 'remote-bash)
+
(with-connection-local-variables
;; All connection-local variables are set. They apply in
;; reverse order in `connection-local-variables-alist'.
@@ -347,6 +350,21 @@
(should
(string-equal (symbol-value 'remote-shell-file-name) "/bin/ksh"))
(should
+ (string-equal (symbol-value 'remote-null-device) "/dev/null"))
+
+ ;; Run another instance of `with-connection-local-variables'
+ ;; with a different application.
+ (let ((connection-local-default-application (cadr files-x-test--application)))
+ (with-connection-local-variables
+ ;; The proper variable values are set.
+ (should
+ (string-equal (symbol-value 'remote-shell-file-name) "/bin/bash"))
+ (should
+ (string-equal (symbol-value 'remote-null-device) "/dev/null"))))
+ ;; The variable values are reset.
+ (should
+ (string-equal (symbol-value 'remote-shell-file-name) "/bin/ksh"))
+ (should
(string-equal (symbol-value 'remote-null-device) "/dev/null")))
;; Everything is rewound. The old variable values are reset.