summaryrefslogtreecommitdiff
path: root/devdocs/elisp/connection-local-variables.html
blob: af242bcf8e45396f96bf882c6e0e1525de719d00 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
 <h3 class="section">Connection Local Variables</h3>  <p>Connection-local variables provide a general mechanism for different variable settings in buffers with a remote connection. They are bound and set depending on the remote connection a buffer is dedicated to. </p> <dl> <dt id="connection-local-set-profile-variables">Function: <strong>connection-local-set-profile-variables</strong> <em>profile variables</em>
</dt> <dd>
<p>This function defines a set of variable settings for the connection <var>profile</var>, which is a symbol. You can later assign the connection profile to one or more remote connections, and Emacs will apply those variable settings to all process buffers for those connections. The list in <var>variables</var> is an alist of the form <code>(<var>name</var> . <var>value</var>)</code>. Example: </p> <div class="example"> <pre class="example">(connection-local-set-profile-variables
  'remote-bash
  '((shell-file-name . "/bin/bash")
    (shell-command-switch . "-c")
    (shell-interactive-switch . "-i")
    (shell-login-switch . "-l")))
</pre>

<pre class="example">(connection-local-set-profile-variables
  'remote-ksh
  '((shell-file-name . "/bin/ksh")
    (shell-command-switch . "-c")
    (shell-interactive-switch . "-i")
    (shell-login-switch . "-l")))
</pre>

<pre class="example">(connection-local-set-profile-variables
  'remote-null-device
  '((null-device . "/dev/null")))
</pre>
</div> </dd>
</dl> <dl> <dt id="connection-local-profile-alist">Variable: <strong>connection-local-profile-alist</strong>
</dt> <dd><p>This alist holds the connection profile symbols and the associated variable settings. It is updated by <code>connection-local-set-profile-variables</code>. </p></dd>
</dl> <dl> <dt id="connection-local-set-profiles">Function: <strong>connection-local-set-profiles</strong> <em>criteria &amp;rest profiles</em>
</dt> <dd>
<p>This function assigns <var>profiles</var>, which are symbols, to all remote connections identified by <var>criteria</var>. <var>criteria</var> is a plist identifying a connection and the application using this connection. Property names might be <code>:application</code>, <code>:protocol</code>, <code>:user</code> and <code>:machine</code>. The property value of <code>:application</code> is a symbol, all other property values are strings. All properties are optional; if <var>criteria</var> is <code>nil</code>, it always applies. Example: </p> <div class="example"> <pre class="example">(connection-local-set-profiles
  '(:application 'tramp :protocol "ssh" :machine "localhost")
  'remote-bash 'remote-null-device)
</pre>

<pre class="example">(connection-local-set-profiles
  '(:application 'tramp :protocol "sudo"
    :user "root" :machine "localhost")
  'remote-ksh 'remote-null-device)
</pre>
</div> <p>If <var>criteria</var> is <code>nil</code>, it applies for all remote connections. Therefore, the example above would be equivalent to </p> <div class="example"> <pre class="example">(connection-local-set-profiles
  '(:application 'tramp :protocol "ssh" :machine "localhost")
  'remote-bash)
</pre>

<pre class="example">(connection-local-set-profiles
  '(:application 'tramp :protocol "sudo"
    :user "root" :machine "localhost")
  'remote-ksh)
</pre>

<pre class="example">(connection-local-set-profiles
  nil 'remote-null-device)
</pre>
</div> <p>Any connection profile of <var>profiles</var> must have been already defined by <code>connection-local-set-profile-variables</code>. </p>
</dd>
</dl> <dl> <dt id="connection-local-criteria-alist">Variable: <strong>connection-local-criteria-alist</strong>
</dt> <dd><p>This alist contains connection criteria and their assigned profile names. The function <code>connection-local-set-profiles</code> updates this list. </p></dd>
</dl> <dl> <dt id="hack-connection-local-variables">Function: <strong>hack-connection-local-variables</strong> <em>criteria</em>
</dt> <dd>
<p>This function collects applicable connection-local variables associated with <var>criteria</var> in <code>connection-local-variables-alist</code>, without applying them. Example: </p> <div class="example"> <pre class="example">(hack-connection-local-variables
  '(:application 'tramp :protocol "ssh" :machine "localhost"))
</pre>

<pre class="example">connection-local-variables-alist
     ⇒ ((null-device . "/dev/null")
        (shell-login-switch . "-l")
        (shell-interactive-switch . "-i")
        (shell-command-switch . "-c")
        (shell-file-name . "/bin/bash"))
</pre>
</div> </dd>
</dl> <dl> <dt id="hack-connection-local-variables-apply">Function: <strong>hack-connection-local-variables-apply</strong> <em>criteria</em>
</dt> <dd><p>This function looks for connection-local variables according to <var>criteria</var>, and immediately applies them in the current buffer. </p></dd>
</dl> <dl> <dt id="with-connection-local-variables">Macro: <strong>with-connection-local-variables</strong> <em>&amp;rest body</em>
</dt> <dd>
<p>All connection-local variables, which are specified by <code>default-directory</code>, are applied. </p> <p>After that, <var>body</var> is executed, and the connection-local variables are unwound. Example: </p> <div class="example"> <pre class="example">(connection-local-set-profile-variables
  'remote-perl
  '((perl-command-name . "/usr/local/bin/perl")
    (perl-command-switch . "-e %s")))
</pre>

<pre class="example">(connection-local-set-profiles
  '(:application 'tramp :protocol "ssh" :machine "remotehost")
  'remote-perl)
</pre>

<pre class="example">(let ((default-directory "/ssh:remotehost:/working/dir/"))
  (with-connection-local-variables
    do something useful))
</pre>
</div> </dd>
</dl> <dl> <dt id="enable-connection-local-variables">Variable: <strong>enable-connection-local-variables</strong>
</dt> <dd><p>If <code>nil</code>, connection-local variables are ignored. This variable shall be changed temporarily only in special modes. </p></dd>
</dl><div class="_attribution">
  <p class="_attribution-p">
    Copyright &copy; 1990-1996, 1998-2022 Free Software Foundation, Inc. <br>Licensed under the GNU GPL license.<br>
    <a href="https://www.gnu.org/software/emacs/manual/html_node/elisp/Connection-Local-Variables.html" class="_attribution-link">https://www.gnu.org/software/emacs/manual/html_node/elisp/Connection-Local-Variables.html</a>
  </p>
</div>