GNU bug report logs - #10604
23.2; variable lookup: make-local-variable interaction with with-temp-buffer

Previous Next

Package: emacs;

Reported by: Trey Jackson <trey_jackson <at> mentor.com>

Date: Wed, 25 Jan 2012 21:52:01 UTC

Severity: normal

Tags: wontfix

Merged with 3467

Found in version 23.2

Done: Lars Ingebrigtsen <larsi <at> gnus.org>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Trey Jackson <trey_jackson <at> mentor.com>
Cc: 10604 <at> debbugs.gnu.org
Subject: bug#10604: 23.2; variable lookup: make-local-variable interaction with with-temp-buffer
Date: Wed, 25 Jan 2012 21:11:54 -0500
tags 10604 wontfix
thanks

> Switch to *scratch*, and do the following:
> (defun func (my-var)
>   (with-temp-buffer
>     (message my-var)))
> C-j

> (func "z")
> C-j
> ; no problem, works as expected
> (make-local-variable 'my-var)
> C-j
> (func "z")
> C-j
> ; ERROR with the stack trace

> Debugger entered--Lisp error: (void-variable my-var)

Yes, that's how dynamic-scoping and buffer-local bindings interact.
Another way to trigger the problem:

   (progn
    (make-local-variable 'my-var)
    (let ((my-var 1))
      (with-temp-buffer
       (message my-var)))

of course, it's the same because `let' works the same as the binding
done for function arguments.

Maybe there is a way to define the interaction of buffer-local bindings
and dynamically scoped vars in a way that doesn't suffer from this
problem, but it's probably going to suffer from other problems instead,
and it's highly unlikely to be compatible with existing code, so
you're better learning to live with it (the way to do that is to
usually avoid such interactions like the plague: either let-bind or
buffer-local but not both, tho sometimes you can't avoid combining
them).


        Stefan




This bug report was last modified 9 years and 198 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.