On Tue, Nov 04, 2025 at 06:46:39PM +0000, Ihor Radchenko wrote: > <[email protected]> writes: > > >> Then, I should be wrong thinking that let-binding override buffer-local > >> value. > >> buffer-locals + let is tricky. > > > > It's the other way around. > > > > In a fresh buffer, (for convenience in Lisp mode), eval those two in > > sequence: > > > > (set (make-local-variable 'foo) 23) > > > > (let ((foo 42)) > > (message (format "foo is: %S, its buffer-local value is %S" > > foo > > (buffer-local-value 'foo (current-buffer))))) > > > > => foo is: 42, its buffer-local value is 42 > > > > Let bindings shadow buffer-local ones. > > Yes and no. > > (defvar-local yant/test 1) > yant/test ; => 1 > (set 'yant/test 23) > yant/test ; => 23 > (let ((yant/foo 42)) (buffer-local-value 'yant/test (current-buffer))) ; => 23 > (let ((yant/foo 42)) (with-temp-buffer (buffer-local-value 'yant/test > (current-buffer)))) ; => 1 > > In a freshly created buffer, if the buffer is created _inside_ > let-binding, the let override does not hold and default value is > assigned instead. > > It is complicated...
Well, that's the `defvar-local': Define VAR as a buffer-local variable with default value VAL. Like ‘defvar’ but additionally marks the variable as being automatically buffer-local wherever it is set. So any new buffer (the one `with-temp-buffer' is creating) is now automatically born with a buffer-local variable `yant/foo' with (default) value 1... Cheers -- t
signature.asc
Description: PGP signature
