all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Michael Heerdegen <michael_heerdegen@web.de>
To: help-gnu-emacs@gnu.org
Subject: Re: Interesting problem: eval-after-load and local variables
Date: Thu, 18 Oct 2012 06:09:10 +0200	[thread overview]
Message-ID: <87y5j4wheh.fsf@web.de> (raw)
In-Reply-To: <808vb58pmw.fsf@somewhere.org> (Sebastien Vauban's message of "Wed, 17 Oct 2012 10:32:55 +0200")

"Sebastien Vauban" <wxhgmqzgwmuf@spammotel.com> 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
better.


Michael.



  reply	other threads:[~2012-10-18  4:09 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-16  8:02 Interesting problem: eval-after-load and local variables Sebastien Vauban
2012-10-16  9:18 ` Peter Dyballa
2012-10-16 17:54 ` Michael Heerdegen
2012-10-17  3:23 ` Kevin Rodgers
     [not found] ` <mailman.11151.1350444234.855.help-gnu-emacs@gnu.org>
2012-10-17  8:32   ` Sebastien Vauban
2012-10-18  4:09     ` Michael Heerdegen [this message]
2012-10-18 12:55     ` Kevin Rodgers
2012-10-18 17:46       ` Bob Proulx
     [not found]     ` <mailman.11221.1350564945.855.help-gnu-emacs@gnu.org>
2012-10-19  9:40       ` Sebastien Vauban

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87y5j4wheh.fsf@web.de \
    --to=michael_heerdegen@web.de \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.