[email protected] writes:

> 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...

make-local-variable also makes the variable buffer-local.
In fact, defvar-local is simply a macro that expands to
(progn (defvar var value docstring) (make-variable-buffer-local 'var))

So, using your example will work exactly the same

(set (make-local-variable 'yant/test2) 23)
yant/test2 ; => 23
(let ((yant/test2 42)) (buffer-local-value 'yant/test2 (current-buffer))) ; => 
23
(let ((yant/test2 42)) (with-temp-buffer (buffer-local-value 'yant/test2 
(current-buffer)))) ; => 1


-- 
Ihor Radchenko // yantar92,
Org mode maintainer,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>

Reply via email to