50.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 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")))

   '(: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.