Subject: bug#347 closed by Chong Yidong <[email-masked]> (Re: C mode asks twice about local variables)

From: [email-masked] (Emacs bug Tracking System)

This is an automatic notification regarding your bug report
which was filed against the emacs package:

#343: C mode asks twice about local variables

It has been closed by Chong Yidong <[email-masked]>.

Their explanation is attached below along with your original report.
If this explanation is unsatisfactory and you have not received a
better one in a separate message then please contact Chong Yidong <[email-masked]> by
replying to this email.

-- 
343: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=343
Emacs Bug Tracking System
Contact [email-masked] with problems
>From [email-masked] Thu Jul 31 07:14:56 2008
From: Chong Yidong <[email-masked]>
To: [email-masked], [email-masked]
Subject: Re: C mode asks twice about local variables
Date: Thu, 31 Jul 2008 10:14:42 -0400

I believe this is now fixed in the trunk.  We'll leave it unfixed in the
branch, since the fix involves the hack-local-variables code and needs
to be tested thoroughly.

>From [email-masked] Sun Jun  1 10:00:40 2008
Date: Sun, 1 Jun 2008 17:21:44 +0000
To: Glenn Morris <[email-masked]>
Cc: [email-masked], [email-masked]
Subject: Re: C mode asks twice about local variables
From: Alan Mackenzie <[email-masked]>

Hi, Glenn,

On Sat, May 31, 2008 at 06:51:35PM -0400, Glenn Morris wrote:

> This applies in Emacs 22.2 and CVS trunk.

> emacs -Q lib-src/etags.c

>     The local variables list in etags.c
>     contains values that may not be safe (*).

>     Do you want to apply it?  You can type
>     y  -- to apply the local variables list.
>     n  -- to ignore the local variables list.
>     !  -- to apply the local variables list, and permanently mark these
>     values (*) as safe (in the future, they will be set automatically.)

>     indent-tabs-mode: t
>     tab-width: 8
>     fill-column: 79
>   * c-font-lock-extra-types: ("FILE" "bool" "language" "linebuffer" "fdesc" "node" "regexp")
>     c-file-style: "gnu"

> If I answer `y', nothing happens. I have to press `y' a second time.

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.

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.

Simply marking all pertinent variables as "safe" is not the right fix,
because they aren't: some can contain arbitrary functions.

Emacs doesn't really have the requisite hooks here:
`before-hack-local-variables-hook' and `after-hack-local-variables-hook'
would let the problem be fixed (rather than kludged), but it kind of
feels like overkill.

If Emacs were not to rebind the do-you-want-to-apply-it variable inside
hack-local-variables, that would allow the kludge to work.

Suggestions and helpful comments would be appreciated here.

-- 
Alan Mackenzie (Nuremberg, Germany).