changeset 37861:829203873c2d

Add something for variable aliases.
author Gerd Moellmann <gerd@gnu.org>
date Mon, 21 May 2001 12:47:04 +0000
parents fc297b7bb8bb
children a852a87500d2
files lispref/variables.texi
diffstat 1 files changed, 40 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/lispref/variables.texi	Mon May 21 12:40:16 2001 +0000
+++ b/lispref/variables.texi	Mon May 21 12:47:04 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
 
@@ -1653,6 +1654,45 @@
   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
+
+  When maintaining Lisp programs, it is sometimes useful to make two
+variables synonyms for each other, so that both variables invariably
+refer to the same value.  When a program variable slightly changes
+meaning, or when a variable name was chosen badly to begin with, it is
+desirable to rename that variable.  For compatibility with older
+versions of the program it is also desirable to not break code that
+uses the original variable name.  This can be done with
+@code{defvaralias}.
+
+@defun defvaralias old-name new-name
+This function defines the symbol @var{old-name} as a variable alias
+for symbol @var{new-name}.  Subsequently, retrieving the value of
+@var{old-name} returns the value of @var{new-name}, and changing the
+value of @var{old-name} changes the value of @var{new-name}.
+@end defun
+
+@defun indirect-variable name
+This function returns the variable at the end of the variable chain
+of @var{name}.  If @var{name} is not a symbol or if @var{name}
+is not a variable alias, @var{name} is returned unchanged.
+@end defun
+
+@example
+(defvaralias 'foo '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