[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Interesting problem: eval-after-load and local variables

From: Michael Heerdegen
Subject: Re: Interesting problem: eval-after-load and local variables
Date: Thu, 18 Oct 2012 06:09:10 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.2.50 (gnu/linux)

"Sebastien Vauban" <> writes:

> > Actually, I think the file local variables are applied and then
> > overridden by
> > the eval-after-load form (but only for the first file that you save).
> Your explanation must be right. But my question was more general, in
> the sense: is this the behavior one would expect?  Or *should local
> vars triumph over the setq done in the eval-after-load?*

This is absolutely what one would expect.  Whenever a variable x has a
buffer local binding in a buffer b, and you eval (setq x foo) while b is
current, this _always_ sets the local binding of x in b.
`eval-after-load' isn't special here in any regard.  It's just the fact
that you let it eval a setq form with a current buffer that has already
local bindings.

So, setq is the wrong function for you to use in such a context.  If you
want to set the default value of a variable, _always_ use setq-default
when the variable may already have local bindings in effect.

> > or use setq-default in the eval-after-load form as suggested by Michael.
> Can I use setq-default with whichever var?  I guess not. But am I right?

Of course you can.  `setq' and `setq-default' both accept any symbol.
The difference is just that

  - setq sets the default value if no buffer local binding is currently
    in effect, else, it sets the local binding

  - setq-default always sets the default binding

In addition, there is a special case of variables that are automatically
buffer-local when they are set in any fashion.

You should really read the chapters Variables > Buffer-Local Variables
and > File Local Variables in the Elisp manual.  It describes it much


reply via email to

[Prev in Thread] Current Thread [Next in Thread]