Path: utzoo!mnetor!uunet!seismo!sundc!pitstop!sun!decwrl!labrea!agate!pasteur!ames!ll-xn!mit-eddie!bu-cs!bucsb!jbw From: jbw@bucsb.UUCP (Joe Wells) Newsgroups: comp.emacs Subject: Re: scope rules for "let" Message-ID: <1482@bucsb.UUCP> Date: 27 Feb 88 19:34:22 GMT References: <3292@arthur.cs.purdue.edu> Reply-To: jbw@bucsb.bu.edu (Joe Wells) Followup-To: comp.emacs Organization: Boston Univ Comp. Sci. Lines: 51 Keywords: lambda binding Summary: emacs lambda binding bug In article <3292@arthur.cs.purdue.edu> narten@cs.purdue.EDU (Thomas Narten) writes: >I have buffer that is readonly for keystrokes, but is made writable by >functions operating on the buffer. I want the default to be readonly, >with explicit action required to make the buffer write only. >(let (buffer-read-only) > /* muck with the buffer */ > > ) Right in here is where the problem occurs. If you use (set-buffer ...) inside of the "let", and you don't switch back to the original buffer before exiting the "let", you get the error. >I want the buffer-read-only variable to be nil only during the >invocation of "let", reverting to its non-nil value upon exit. This is >apparently not taking place. I find that the buffer-read-only is being >left set to nil. Actually the "t" value of buffer-read-only is being restored ... in a different buffer! >I conclude that "let" is not doing what I want. What I would like is >for let to push the variables onto the symbol table stack, and use >dynamic scope rules to have all subsequent references to the variables >with those name find the "recent" bindings. When "let" exits, I would >expect the temporary binding of those variables to pop off of the >stack and the previous meanings be restored. > >Why does the above not work? "buffer-read-only" is a buffer-local variable. GNU Emacs does not properly undo lambda bindings of buffer-local variables when you switch buffers while in the context of the lambda binding. You have two options until this bug is fixed: 1) Don't use "let" to temporarily override the value of buffer-local variables. 2) Make sure you always exit a "let" with the same current buffer as you entered it. BTW, the GNU Emacs function "shrink-window-if-larger-than-buffer" in electric.el makes this mistake. I found out the hard way, when buffer-file-name was being zapped, and I couldn't save my file ... >Thomas Narten >narten@cs.purdue.edu or {ihnp4, allegra}!purdue!narten Joe Wells jbw@bucsf.bu.edu