Subject: bug#10604: 23.2; variable lookup: make-local-variable interaction with with-temp-buffer

From: Trey Jackson <[email-masked]>
Date: Wed, 25 Jan 2012 13:15:29 -0800

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
[email-masked]