GNU bug report logs - #347
C mode asks twice about local variables

Previous Next

Packages: cc-mode, emacs;

Reported by: Alan Mackenzie <acm <at> muc.de>

Date: Sun, 1 Jun 2008 17:10:04 UTC

Severity: normal

Merged with 343

Done: Chong Yidong <cyd <at> stupidchicken.com>

Bug is archived. No further changes may be made.

Full log


Message #32 received at submit <at> emacsbugs.donarmstrong.com (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Alan Mackenzie <acm <at> muc.de>
Cc: Glenn Morris <rgm <at> gnu.org>, 347 <at> debbugs.gnu.org,
        bug-cc-mode <at> gnu.org, bug-gnu-emacs <at> gnu.org
Subject: Re: bug#347: C mode asks twice about local variables
Date: Mon, 09 Jun 2008 11:18:28 -0400
>> > Yes.  This needs fixing, somehow.
>> 
>> > The way this happens is that in a C file's local variables list, there
>> > are two "special" variables, e.g. `c-file-style'.
>> 
>> > When 
>> 
>> >     c-basic-offset: 11
>> >     c-file-style: "k&r"
>> 
>> > occurs in the local variable list, this triggers a hook function
>> > which calls (c-set-style "k&r").  The hook is
>> > hack-local-variables-hook.  The problem is that this c-set-style call
>> > will overwrite the explicit value for c-basic-offset.  The explicit
>> > value MUST take precedence here.
 
>> Can you try and call `c-file-style' with some extra "don't override"
>> (when called from that hack-local-variables-hook) argument so that any
>> variable that already has a buffer-local binding will not be
>> overridden?

Any comment about this suggestion?

>> > My solution was to call hack-local-variables a second time from
>> > within the hook function, first having deleted any occurrences of
>> > `mode', `c-file-style' etc. from the Local Variables.  This kludge
>> > worked reasonably well until the handling of
>> > safe/dangerous-local-variables was changed for Emacs 22.

>> How 'bout wrapping the call inside (let ((enable-local-variables
>> :safe))?

> I've been thinking this over.  It's not the right solution.  For a start,
> the second call to `hack-local-variables' is in itself a kludge.

I'd tend to agree, but "kludge" fixes the problem, it's still better
than the current "same kludge + problem".

> More importantly, the value ":safe" is non-portable (to earlier Emacsen,
> or to the other one),

Non-portability might indeed be a problem (tho, it's obviously "your"
problem rather than mine), but introducing a new hook in Emacs-23 won't
help you there, so it's not relevant to this discussion.

> and doesn't feel at all safe.

But I don't see why you don't consider it safe: it is really meant to be
safe, so if there's any doubt about it, we should very much address it.

> (defvar before-hack-local-variables-hook nil
[...]
> What do you think?

I'm not thrilled.  You might convince me at some point, but the kludge
doesn't look nearly as bad when compared to this hook.


        Stefan





This bug report was last modified 15 years and 114 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.