# HG changeset patch # User Gerd Moellmann # Date 1002274723 0 # Node ID 9b87a63bcb36e5c0c6f0d71ff5d2bb5bef703a92 # Parent d16a58a98f400a19fdb1ab62f056672f81badfc2 (Variable Aliases): New node. diff -r d16a58a98f40 -r 9b87a63bcb36 lispref/variables.texi --- a/lispref/variables.texi Fri Oct 05 09:37:17 2001 +0000 +++ b/lispref/variables.texi Fri Oct 05 09:38:43 2001 +0000 @@ -41,6 +41,7 @@ * Buffer-Local Variables:: Variable values in effect only in one buffer. * Frame-Local Variables:: Variable values in effect only in one frame. * Future Local Variables:: New kinds of local values we might add some day. +* Variable Aliases:: Variables that are aliases for other variables. * File Local Variables:: Handling local variable lists in files. @end menu @@ -1654,6 +1655,48 @@ If sufficient application is found for either of these two kinds of local bindings, we will provide it in a subsequent Emacs version. +@node Variable Aliases +@section Variable Aliases + + 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 @emph{alias} of the new one for +compatibility. You can do this with @code{defvaralias}. + +@defmacro defvaralias alias-var base-var +This function defines the symbol @var{alias-var} as a variable alias +for symbol @var{base-var}. This means that retrieving the value of +@var{alias-var} returns the value of @var{base-var}, and changing the +value of @var{alias-var} changes the value of @var{base-var}. +@end defmacro + +@defun indirect-variable variable +This function returns the variable at the end of the chain of aliases +of @var{variable}. If @var{variable} is not a symbol, or if @var{variable} is +not defined as an alias, the function returns @var{variable}. +@end defun + +@example +(defvaralias 'foo 'bar) +(indirect-variable 'foo) + @result{} bar +(indirect-variable 'bar) + @result{} bar +(setq bar 2) +bar + @result{} 2 +foo + @result{} 2 +(setq foo 0) +bar + @result{} 0 +foo + @result{} 0 +@end example + @node File Local Variables @section File Local Variables