Previous: Per-Directory Local Variables, Up: Variables [Contents][Index]
51.2.6 Per-Connection Local VariablesMost of the variables reflect the situation on the local machine. Often, they must use a different value when you operate in buffers with a remote default directory. Think about the behavior when calling shell
– on your local machine, you might use /bin/bash and rely on termcap, but on a remote machine, it may be /bin/ksh and terminfo.
This can be accomplished with connection-local variables. Directory and file local variables override connection-local variables. Unsafe connection-local variables are handled in the same way as unsafe file-local variables (see Safety of File Variables).
Connection-local variables are declared as a group of variables/value pairs in a profile, using the connection-local-set-profile-variables
function. The function connection-local-set-profiles
activates profiles for a given criteria, identifying a remote machine:
(connection-local-set-profile-variables 'remote-terminfo '((system-uses-terminfo . t) (comint-terminfo-terminal . "dumb-emacs-ansi"))) (connection-local-set-profile-variables 'remote-ksh '((shell-file-name . "/bin/ksh") (shell-command-switch . "-c"))) (connection-local-set-profile-variables 'remote-bash '((shell-file-name . "/bin/bash") (shell-command-switch . "-c"))) (connection-local-set-profiles '(:application tramp :machine "remotemachine") 'remote-terminfo 'remote-ksh)
This code declares three different profiles, remote-terminfo
, remote-ksh
, and remote-bash
. The profiles remote-terminfo
and remote-ksh
are applied to all buffers which have a remote default directory matching the regexp "remotemachine"
as host name. Such a criteria can also discriminate for the properties :protocol
(this is the Tramp method) or :user
(a remote user name). The nil
criteria matches all buffers with a remote default directory.
Be careful when declaring different profiles with the same variable, and setting these profiles to criteria which could match in parallel. It is unspecified which variable value is used then.
Be also careful when setting connection-local variables in a buffer, which changes its major mode afterwards. Because all buffer-local variables will be killed when changing the major mode, the connection-local variable’s value would be lost. You can prevent this by setting the respective variable’s permanent-local
symbol property to non-nil
.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4