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
|
<h3 class="section">Variable Aliases</h3> <p>It is sometimes useful to make two variables synonyms, so that both variables always have the same value, and changing either one also changes the other. Whenever you change the name of a variable—either because you realize its old name was not well chosen, or because its meaning has partly changed—it can be useful to keep the old name as an <em>alias</em> of the new one for compatibility. You can do this with <code>defvaralias</code>. </p> <dl> <dt id="defvaralias">Function: <strong>defvaralias</strong> <em>new-alias base-variable &optional docstring</em>
</dt> <dd>
<p>This function defines the symbol <var>new-alias</var> as a variable alias for symbol <var>base-variable</var>. This means that retrieving the value of <var>new-alias</var> returns the value of <var>base-variable</var>, and changing the value of <var>new-alias</var> changes the value of <var>base-variable</var>. The two aliased variable names always share the same value and the same bindings. </p> <p>If the <var>docstring</var> argument is non-<code>nil</code>, it specifies the documentation for <var>new-alias</var>; otherwise, the alias gets the same documentation as <var>base-variable</var> has, if any, unless <var>base-variable</var> is itself an alias, in which case <var>new-alias</var> gets the documentation of the variable at the end of the chain of aliases. </p> <p>This function returns <var>base-variable</var>. </p>
</dd>
</dl> <p>Variable aliases are convenient for replacing an old name for a variable with a new name. <code>make-obsolete-variable</code> declares that the old name is obsolete and therefore that it may be removed at some stage in the future. </p> <dl> <dt id="make-obsolete-variable">Function: <strong>make-obsolete-variable</strong> <em>obsolete-name current-name when &optional access-type</em>
</dt> <dd>
<p>This function makes the byte compiler warn that the variable <var>obsolete-name</var> is obsolete. If <var>current-name</var> is a symbol, it is the variable’s new name; then the warning message says to use <var>current-name</var> instead of <var>obsolete-name</var>. If <var>current-name</var> is a string, this is the message and there is no replacement variable. <var>when</var> should be a string indicating when the variable was first made obsolete (usually a version number string). </p> <p>The optional argument <var>access-type</var>, if non-<code>nil</code>, should specify the kind of access that will trigger obsolescence warnings; it can be either <code>get</code> or <code>set</code>. </p>
</dd>
</dl> <p>You can make two variables synonyms and declare one obsolete at the same time using the macro <code>define-obsolete-variable-alias</code>. </p> <dl> <dt id="define-obsolete-variable-alias">Macro: <strong>define-obsolete-variable-alias</strong> <em>obsolete-name current-name &optional when docstring</em>
</dt> <dd>
<p>This macro marks the variable <var>obsolete-name</var> as obsolete and also makes it an alias for the variable <var>current-name</var>. It is equivalent to the following: </p> <div class="example"> <pre class="example">(defvaralias <var>obsolete-name</var> <var>current-name</var> <var>docstring</var>)
(make-obsolete-variable <var>obsolete-name</var> <var>current-name</var> <var>when</var>)
</pre>
</div> <p>This macro evaluates all its parameters, and both <var>obsolete-name</var> and <var>current-name</var> should be symbols, so a typical usage would look like: </p> <div class="lisp"> <pre class="lisp">(define-obsolete-variable-alias 'foo-thing 'bar-thing "27.1")
</pre>
</div> </dd>
</dl> <dl> <dt id="indirect-variable">Function: <strong>indirect-variable</strong> <em>variable</em>
</dt> <dd>
<p>This function returns the variable at the end of the chain of aliases of <var>variable</var>. If <var>variable</var> is not a symbol, or if <var>variable</var> is not defined as an alias, the function returns <var>variable</var>. </p> <p>This function signals a <code>cyclic-variable-indirection</code> error if there is a loop in the chain of symbols. </p>
</dd>
</dl> <div class="example"> <pre class="example">(defvaralias 'foo 'bar)
(indirect-variable 'foo)
⇒ bar
(indirect-variable 'bar)
⇒ bar
(setq bar 2)
bar
⇒ 2
</pre>
<pre class="example">foo
⇒ 2
</pre>
<pre class="example">(setq foo 0)
bar
⇒ 0
foo
⇒ 0
</pre>
</div><div class="_attribution">
<p class="_attribution-p">
Copyright © 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/Variable-Aliases.html" class="_attribution-link">https://www.gnu.org/software/emacs/manual/html_node/elisp/Variable-Aliases.html</a>
</p>
</div>
|