unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#10604: 23.2; variable lookup: make-local-variable interaction with with-temp-buffer
@ 2012-01-25 21:15 Trey Jackson
  2012-01-26  2:11 ` Stefan Monnier
  0 siblings, 1 reply; 2+ messages in thread
From: Trey Jackson @ 2012-01-25 21:15 UTC (permalink / raw)
  To: 10604

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)
  (message my-var)
  (progn (message my-var))
  (unwind-protect (progn (message my-var)) (and (buffer-name temp-buffer) (kill-buffer temp-buffer)))
  (save-current-buffer (set-buffer temp-buffer) (unwind-protect (progn ...) (and ... ...)))
  (with-current-buffer temp-buffer (unwind-protect (progn ...) (and ... ...)))
  (let ((temp-buffer ...)) (with-current-buffer temp-buffer (unwind-protect ... ...)))
  (with-temp-buffer (message my-var))
  func("z")
  eval((func "z"))
  eval-last-sexp-1(t)
  eval-last-sexp(t)
  eval-print-last-sexp()
  call-interactively(eval-print-last-sexp nil nil)


First discovered by a SO post: http://stackoverflow.com/questions/9008359/why-does-code-in-with-temp-buffer-complain-about-void-variable-when-parent-buf




In GNU Emacs 23.2.1 (x86_64-unknown-linux-gnu, X toolkit, Xaw3d scroll bars)
 of 2010-05-11 on quartzville
Windowing system distributor `The X.Org Foundation', version 11.0.60801000
Important settings:
  value of $LC_ALL: nil
  value of $LC_COLLATE: nil
  value of $LC_CTYPE: nil
  value of $LC_MESSAGES: nil
  value of $LC_MONETARY: nil
  value of $LC_NUMERIC: nil
  value of $LC_TIME: nil
  value of $LANG: C
  value of $XMODIFIERS: nil
  locale-coding-system: nil
  default enable-multibyte-characters: t

Major mode: Debugger

Minor modes in effect:
  tooltip-mode: t
  mouse-wheel-mode: t
  tool-bar-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  line-number-mode: t
  transient-mark-mode: t

Recent input:
<help-echo> <help-echo> <help-echo> C-x <help-echo> 
b <return> C-y C-p C-e C-j ( f u n c SPC " c <backspace> 
z " ) C-j ( m a k e - l o c a l - v a r M-/ i a b l 
e SPC ' m y - v a r ) C-j ( f u n c SPC " z " ) C-j 
<help-echo> <help-echo> <help-echo> <help-echo> <help-echo> 
M-x r e p o r t SPC e m a c s SPC <tab> <return>

Recent messages:
For information about GNU Emacs and the GNU system, type C-h C-a.
Mark set
z
Scanning for dabbrevs...99%
dabbrev-expand: No dynamic expansion for `make-local-var' found
Entering debugger...

Load-path shadows:
None found.

Features:
(shadow sort mail-extr message sendmail regexp-opt ecomplete rfc822 mml
mml-sec password-cache mm-decode mm-bodies mm-encode mailcap mail-parse
rfc2231 rfc2047 rfc2045 qp ietf-drums mailabbrev nnheader gnus-util
netrc time-date mm-util mail-prsvr gmm-utils wid-edit mailheader canlock
sha1 hex-util hashcash mail-utils emacsbug help-mode easymenu view debug
dabbrev tooltip ediff-hook vc-hooks lisp-float-type mwheel x-win x-dnd
font-setting tool-bar dnd fontset image fringe lisp-mode register page
menu-bar rfn-eshadow timer select scroll-bar mldrag mouse jit-lock
font-lock syntax facemenu font-core frame cham georgian utf-8-lang
misc-lang vietnamese tibetan thai tai-viet lao korean japanese hebrew
greek romanian slovak czech european ethiopic indian cyrillic chinese
case-table epa-hook jka-cmpr-hook help simple abbrev loaddefs button
minibuffer faces cus-face files text-properties overlay md5 base64
format env code-pages mule custom widget hashtable-print-readable
backquote make-network-process font-render-setting x-toolkit x multi-tty
emacs)

-- 
Trey Jackson
trey_jackson@mentor.com





^ permalink raw reply	[flat|nested] 2+ messages in thread

* bug#10604: 23.2; variable lookup: make-local-variable interaction with with-temp-buffer
  2012-01-25 21:15 bug#10604: 23.2; variable lookup: make-local-variable interaction with with-temp-buffer Trey Jackson
@ 2012-01-26  2:11 ` Stefan Monnier
  0 siblings, 0 replies; 2+ messages in thread
From: Stefan Monnier @ 2012-01-26  2:11 UTC (permalink / raw)
  To: Trey Jackson; +Cc: 10604

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





^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2012-01-26  2:11 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-01-25 21:15 bug#10604: 23.2; variable lookup: make-local-variable interaction with with-temp-buffer Trey Jackson
2012-01-26  2:11 ` Stefan Monnier

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).