/[emacs]/emacs/lispref/variables.texi
ViewVC logotype

Diff of /emacs/lispref/variables.texi

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.30 by monnier, Tue Feb 12 19:33:46 2002 UTC revision 1.31 by kfstorm, Mon May 13 19:04:27 2002 UTC
# Line 1185  be changed with @code{setq} in any buffe Line 1185  be changed with @code{setq} in any buffe
1185  with @code{setq-default}.  with @code{setq-default}.
1186    
1187    @strong{Warning:} When a variable has buffer-local values in one or    @strong{Warning:} When a variable has buffer-local values in one or
1188  more buffers, you can get Emacs very confused by binding the variable  more buffers, binding the variable with @code{let} and changing to a
1189  with @code{let}, changing to a different current buffer in which a  different current buffer in which a different binding is in
1190  different binding is in effect, and then exiting the @code{let}.  This  effect, and then exiting the @code{let}, the variable may not be
1191  can scramble the values of the buffer-local and default bindings.  restored to the value it had before the @code{let}.
1192    
1193    To preserve your sanity, avoid using a variable in that way.  If you    To preserve your sanity, avoid using a variable in that way.  If you
1194  use @code{save-excursion} around each piece of code that changes to a  use @code{save-excursion} around each piece of code that changes to a
# Line 1197  different current buffer, you will not h Line 1197  different current buffer, you will not h
1197    
1198  @example  @example
1199  @group  @group
1200  (setq foo 'b)  (setq foo 'g)
1201  (set-buffer "a")  (set-buffer "a")
1202  (make-local-variable 'foo)  (make-local-variable 'foo)
1203  @end group  @end group
1204  (setq foo 'a)  (setq foo 'a)
1205  (let ((foo 'temp))  (let ((foo 'temp))
1206      ;; foo @result{} 'temp  ; @r{let binding in buffer @samp{a}}
1207    (set-buffer "b")    (set-buffer "b")
1208      ;; foo @result{} 'g     ; @r{the global value since foo is not local in @samp{b}}
1209    @var{body}@dots{})    @var{body}@dots{})
1210  @group  @group
1211  foo @result{} 'a      ; @r{The old buffer-local value from buffer @samp{a}}  foo @result{} 'a        ; @r{we are still in buffer @samp{b}, but exiting the let}
1212                 ;   @r{is now the default value.}                   ; @r{restored the local value in buffer @samp{a}}
1213  @end group  @end group
1214  @group  @group
1215  (set-buffer "a")  (set-buffer "a") ; @r{This can be seen here:}
1216  foo @result{} 'temp   ; @r{The local @code{let} value that should be gone}  foo @result{} 'a        ; @r{we are back to the local value in buffer @samp{a}}
                ;   @r{is now the buffer-local value in buffer @samp{a}.}  
1217  @end group  @end group
1218  @end example  @end example
1219    

Legend:
Removed from v.1.30  
changed lines
  Added in v.1.31

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26