12.11.2 Creating and Deleting Buffer-Local Bindings:
Making a variable buffer-local within a
let
-binding for that variable does not work reliably, unless the buffer in which you do this is not current either on entry to or exit from thelet
.
So I test an example (in which the buffer is not current either on entry to or exit from the let
) in the *scratch*
buffer:
(setq number 0)
(with-current-buffer "*Messages*"
(let (number)
(with-current-buffer "*scratch*"
(make-local-variable 'number)
(setq number 1))))
number
;; ==> 0
;; Still, it returns the default value.
It seems that I did not understand what the manual said correctly.
I wonder what the manual mean by "work reliably",
can anyone give me an example that meets the conditions following "unless" and an opposite example that cannot "work reliably"?
Then the manual continued:
This is because
let
does not distinguish between different kinds of bindings; it knows only which variable the binding was made for.
But according to another example in 12.11.1 Introduction to Buffer-Local Variables:
(setq foo 'g)
(set-buffer "a")
(make-local-variable 'foo)
(setq foo 'a)
(let ((foo 'temp))
(set-buffer "b")
foo)
;; ==> g
let
seems to distinguish ...
I know that making a variable buffer-local within a let
-binding may not be a good coding convention, but since the manual mentioned it, I just want to figure it out.