Skip to main content

49.2.6 Per-Connection Local Variables

Most 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 shell to be applied when calling shell – it might be /bin/bash on your local machine, and /bin/ksh on a remote machine.

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 Safe 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-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-ksh)

This code declares two different profiles, remote-ksh and remote-bash. The profile remote-ksh is 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.