From unknown Tue Jun 17 20:08:28 2025 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Mailer: MIME-tools 5.509 (Entity 5.509) Content-Type: text/plain; charset=utf-8 From: bug#347 <347@debbugs.gnu.org> To: bug#347 <347@debbugs.gnu.org> Subject: Status: C mode asks twice about local variables Reply-To: bug#347 <347@debbugs.gnu.org> Date: Wed, 18 Jun 2025 03:08:28 +0000 retitle 347 C mode asks twice about local variables reassign 347 emacs,cc-mode submitter 347 Alan Mackenzie severity 347 normal thanks From acm@muc.de Sun Jun 1 10:00:40 2008 X-Spam-Checker-Version: SpamAssassin 3.2.3-bugs.debian.org_2005_01_02 (2007-08-08) on rzlab.ucr.edu X-Spam-Level: X-Spam-Status: No, score=-4.9 required=4.0 tests=BAYES_00,FOURLA, RCVD_IN_DNSWL_LOW autolearn=ham version=3.2.3-bugs.debian.org_2005_01_02 Received: (at submit) by emacsbugs.donarmstrong.com; 1 Jun 2008 17:00:41 +0000 Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) by rzlab.ucr.edu (8.13.8/8.13.8/Debian-3) with ESMTP id m51H0aFc010877 for ; Sun, 1 Jun 2008 10:00:38 -0700 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1K2qv6-0004Im-6s for bug-gnu-emacs@gnu.org; Sun, 01 Jun 2008 13:00:36 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1K2qv4-0004Ia-Pw for bug-gnu-emacs@gnu.org; Sun, 01 Jun 2008 13:00:35 -0400 Received: from [199.232.76.173] (port=54163 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1K2qv4-0004IX-J7 for bug-gnu-emacs@gnu.org; Sun, 01 Jun 2008 13:00:34 -0400 Received: from colin.muc.de ([193.149.48.1]:4309 helo=mail.muc.de) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1K2qv3-0005sx-U9 for bug-gnu-emacs@gnu.org; Sun, 01 Jun 2008 13:00:34 -0400 Received: (qmail 57706 invoked by uid 3782); 1 Jun 2008 17:00:25 -0000 Received: from acm.muc.de (pD9E50308.dip.t-dialin.net [217.229.3.8]) by colin2.muc.de (tmda-ofmipd) with ESMTP; Sun, 01 Jun 2008 19:00:22 +0200 Received: (qmail 6244 invoked by uid 1000); 1 Jun 2008 17:21:44 -0000 Date: Sun, 1 Jun 2008 17:21:44 +0000 To: Glenn Morris Cc: bug-gnu-emacs@gnu.org, bug-cc-mode@gnu.org Subject: Re: C mode asks twice about local variables Message-ID: <20080601172143.GA5899@muc.de> References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.9i X-Delivery-Agent: TMDA/1.1.5 (Fettercairn) From: Alan Mackenzie X-Primary-Address: acm@muc.de X-detected-kernel: by monty-python.gnu.org: FreeBSD 4.6-4.9 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). From rgm@gnu.org Mon Jun 2 00:56:19 2008 X-Spam-Checker-Version: SpamAssassin 3.2.3-bugs.debian.org_2005_01_02 (2007-08-08) on rzlab.ucr.edu X-Spam-Level: X-Spam-Status: No, score=-7.5 required=4.0 tests=AWL,BAYES_00,ONEWORD, RCVD_IN_DNSWL_MED,VALID_BTS_CONTROL autolearn=ham version=3.2.3-bugs.debian.org_2005_01_02 Received: (at control) by emacsbugs.donarmstrong.com; 2 Jun 2008 07:56:19 +0000 Received: from fencepost.gnu.org (fencepost.gnu.org [140.186.70.10]) by rzlab.ucr.edu (8.13.8/8.13.8/Debian-3) with ESMTP id m527uGMp004850 for ; Mon, 2 Jun 2008 00:56:17 -0700 Received: from rgm by fencepost.gnu.org with local (Exim 4.67) (envelope-from ) id 1K34s2-000242-Sf; Mon, 02 Jun 2008 03:54:22 -0400 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-ID: <18499.42798.793720.866533@fencepost.gnu.org> Date: Mon, 2 Jun 2008 03:54:22 -0400 From: Glenn Morris To: control Subject: #347 X-Attribution: GM X-Mailer: VM (www.wonderworks.com/vm), GNU Emacs (www.gnu.org/software/emacs) X-Hue: black X-Ran: }Y}RX}7f|'XX[Y>)6VZ8D@Vzc!8G5Z\nF)O3UOZ_M[:W&"uU7<|Z$_T|!f\iQD[cVXO(=2 merge 343 347 From monnier@iro.umontreal.ca Mon Jun 2 23:40:45 2008 X-Spam-Checker-Version: SpamAssassin 3.2.3-bugs.debian.org_2005_01_02 (2007-08-08) on rzlab.ucr.edu X-Spam-Level: X-Spam-Status: No, score=-4.3 required=4.0 tests=AWL,BAYES_00,FOURLA, HAS_BUG_NUMBER,RCVD_IN_DNSWL_LOW autolearn=ham version=3.2.3-bugs.debian.org_2005_01_02 Received: (at submit) by emacsbugs.donarmstrong.com; 3 Jun 2008 06:40:45 +0000 Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) by rzlab.ucr.edu (8.13.8/8.13.8/Debian-3) with ESMTP id m536eftc017136 for ; Mon, 2 Jun 2008 23:40:43 -0700 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1K3QCH-0003Vk-9i for bug-gnu-emacs@gnu.org; Tue, 03 Jun 2008 02:40:41 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1K3QCG-0003Um-Mi for bug-gnu-emacs@gnu.org; Tue, 03 Jun 2008 02:40:40 -0400 Received: from [199.232.76.173] (port=39770 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1K3QCG-0003Ub-Bu for bug-gnu-emacs@gnu.org; Tue, 03 Jun 2008 02:40:40 -0400 Received: from mx20.gnu.org ([199.232.41.8]:48780) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1K3QCC-0005kn-Qw; Tue, 03 Jun 2008 02:40:37 -0400 Received: from 206-248-132-168.dsl.teksavvy.com ([206.248.132.168] helo=ceviche.home) by mx20.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1K3QCC-0002WG-2w; Tue, 03 Jun 2008 02:40:36 -0400 Received: by ceviche.home (Postfix, from userid 20848) id 856D4B423C; Tue, 3 Jun 2008 02:40:29 -0400 (EDT) From: Stefan Monnier To: Alan Mackenzie Cc: 347@debbugs.gnu.org, Glenn Morris , bug-cc-mode@gnu.org, bug-gnu-emacs@gnu.org Subject: Re: bug#347: C mode asks twice about local variables Message-ID: References: <20080601172143.GA5899@muc.de> Date: Tue, 03 Jun 2008 02:40:29 -0400 In-Reply-To: <20080601172143.GA5899@muc.de> (Alan Mackenzie's message of "Sun, 1 Jun 2008 17:21:44 +0000") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-detected-kernel: by mx20.gnu.org: Linux 2.6 (newer, 3) X-Greylist: delayed 60755 seconds by postgrey-1.27 at nadesico; Tue, 03 Jun 2008 02:40:35 EDT X-Greylist: delayed 118299 seconds by postgrey-1.27 at nadesico; Tue, 03 Jun 2008 02:40:36 EDT X-detected-kernel: by monty-python.gnu.org: Linux 2.6, seldom 2.4 (older, 4) X-CrossAssassin-Score: 2 > 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? > 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))? > 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. I don't know what you're referring to here. Stefan From acm@muc.de Mon Jun 9 07:14:58 2008 X-Spam-Checker-Version: SpamAssassin 3.2.3-bugs.debian.org_2005_01_02 (2007-08-08) on rzlab.ucr.edu X-Spam-Level: X-Spam-Status: No, score=-7.4 required=4.0 tests=AWL,BAYES_00,FOURLA, HAS_BUG_NUMBER,RCVD_IN_DNSWL_LOW autolearn=ham version=3.2.3-bugs.debian.org_2005_01_02 Received: (at submit) by emacsbugs.donarmstrong.com; 9 Jun 2008 14:14:58 +0000 Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) by rzlab.ucr.edu (8.13.8/8.13.8/Debian-3) with ESMTP id m59EElhr022007 for ; Mon, 9 Jun 2008 07:14:48 -0700 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1K5i91-0000hg-1E for bug-gnu-emacs@gnu.org; Mon, 09 Jun 2008 10:14:47 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1K5i8z-0000gp-1L for bug-gnu-emacs@gnu.org; Mon, 09 Jun 2008 10:14:46 -0400 Received: from [199.232.76.173] (port=47064 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1K5i8y-0000ga-Sr for bug-gnu-emacs@gnu.org; Mon, 09 Jun 2008 10:14:44 -0400 Received: from colin.muc.de ([193.149.48.1]:1465 helo=mail.muc.de) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1K5i8y-0000Up-BR for bug-gnu-emacs@gnu.org; Mon, 09 Jun 2008 10:14:44 -0400 Received: (qmail 64512 invoked by uid 3782); 9 Jun 2008 14:14:42 -0000 Received: from acm.muc.de (pD9E23E6E.dip.t-dialin.net [217.226.62.110]) by colin2.muc.de (tmda-ofmipd) with ESMTP; Mon, 09 Jun 2008 16:14:38 +0200 Received: (qmail 6433 invoked by uid 1000); 9 Jun 2008 14:36:51 -0000 Date: Mon, 9 Jun 2008 14:36:51 +0000 To: Stefan Monnier , Glenn Morris Cc: 347@debbugs.gnu.org, bug-cc-mode@gnu.org, bug-gnu-emacs@gnu.org Subject: Re: bug#347: C mode asks twice about local variables Message-ID: <20080609143651.GA6098@muc.de> References: <20080601172143.GA5899@muc.de> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.9i X-Delivery-Agent: TMDA/1.1.5 (Fettercairn) From: Alan Mackenzie X-Primary-Address: acm@muc.de X-detected-kernel: by monty-python.gnu.org: FreeBSD 4.6-4.9 X-CrossAssassin-Score: 2 Hi, Stefan and Glenn, On Tue, Jun 03, 2008 at 02:40:29AM -0400, Stefan Monnier wrote: > > 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? > > 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. More importantly, the value ":safe" is non-portable (to earlier Emacsen, or to the other one), and doesn't feel at all safe. I'd have to emulate, to some extent, the processing of `enable-local-variables' inside CC Mode code, and this variable gives the distinct feeling of not yet having reached its final definition. And I'd almost certainly get this wrong, either causing lots of bug reports for the failure of LV handling or leaving a security hole for unsafe variables. The right thing is to increase the granularity of control over the Local Variables handling. In particular, to have a new hook called just after parsing the local variables, but before setting them. I think it should look like this: ######################################################################### (defvar before-hack-local-variables-hook nil "Normal hook run before setting a file's local variables. This hook is called only when there is at least one local variable to set. At the time of call, the content of the \"-*-\" line at the top of the buffer and of any \"Local Variables\" section have been parsed, respectively in the two dynamically bound variables `hack-variables-on-prop-line' and `hack-variables-in-list'. Each of these is an alist with elements of the form (VAR . VALUE), VAR being the name of the variable to set and VALUE the raw string representation of its value. The elements are in the same order as in the buffer. A hook function may change the value of either of these alists. Point is at the start of the line with \"Local Variables\", or at the beginning of buffer if there is no such line.") ######################################################################### What do you think? > Stefan -- Alan Mackenzie (Nuremberg, Germany). From monnier@iro.umontreal.ca Mon Jun 9 08:19:04 2008 X-Spam-Checker-Version: SpamAssassin 3.2.3-bugs.debian.org_2005_01_02 (2007-08-08) on rzlab.ucr.edu X-Spam-Level: X-Spam-Status: No, score=-5.9 required=4.0 tests=AWL,BAYES_00,FOURLA, HAS_BUG_NUMBER,RCVD_IN_DNSWL_LOW autolearn=ham version=3.2.3-bugs.debian.org_2005_01_02 Received: (at submit) by emacsbugs.donarmstrong.com; 9 Jun 2008 15:19:04 +0000 Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) by rzlab.ucr.edu (8.13.8/8.13.8/Debian-3) with ESMTP id m59FIwvR005680 for ; Mon, 9 Jun 2008 08:18:59 -0700 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1K5j97-0006nV-OV for bug-gnu-emacs@gnu.org; Mon, 09 Jun 2008 11:18:57 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1K5j94-0006me-BJ for bug-gnu-emacs@gnu.org; Mon, 09 Jun 2008 11:18:57 -0400 Received: from [199.232.76.173] (port=57128 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1K5j94-0006mb-7c for bug-gnu-emacs@gnu.org; Mon, 09 Jun 2008 11:18:54 -0400 Received: from mercure.iro.umontreal.ca ([132.204.24.67]:43070) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1K5j8u-0004mg-IO; Mon, 09 Jun 2008 11:18:44 -0400 Received: from hidalgo.iro.umontreal.ca (hidalgo.iro.umontreal.ca [132.204.27.50]) by mercure.iro.umontreal.ca (Postfix) with ESMTP id 1D5C72CF94C; Mon, 9 Jun 2008 11:18:44 -0400 (EDT) Received: from faina.iro.umontreal.ca (faina.iro.umontreal.ca [132.204.26.177]) by hidalgo.iro.umontreal.ca (Postfix) with ESMTP id 2D41A3FE0; Mon, 9 Jun 2008 11:18:29 -0400 (EDT) Received: by faina.iro.umontreal.ca (Postfix, from userid 20848) id 0F29341BEC; Mon, 9 Jun 2008 11:18:29 -0400 (EDT) From: Stefan Monnier To: Alan Mackenzie Cc: Glenn Morris , 347@debbugs.gnu.org, bug-cc-mode@gnu.org, bug-gnu-emacs@gnu.org Subject: Re: bug#347: C mode asks twice about local variables Message-ID: References: <20080601172143.GA5899@muc.de> <20080609143651.GA6098@muc.de> Date: Mon, 09 Jun 2008 11:18:28 -0400 In-Reply-To: <20080609143651.GA6098@muc.de> (Alan Mackenzie's message of "Mon, 9 Jun 2008 14:36:51 +0000") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-DIRO-MailScanner-Information: Please contact the ISP for more information X-DIRO-MailScanner: Found to be clean X-DIRO-MailScanner-SpamCheck: n'est pas un polluriel, SpamAssassin (score=-2.82, requis 5, autolearn=not spam, ALL_TRUSTED -2.82) X-DIRO-MailScanner-From: monnier@iro.umontreal.ca X-detected-kernel: by monty-python.gnu.org: Linux 2.6 (newer, 3) X-CrossAssassin-Score: 2 >> > 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 From acm@muc.de Mon Jun 9 11:45:44 2008 X-Spam-Checker-Version: SpamAssassin 3.2.3-bugs.debian.org_2005_01_02 (2007-08-08) on rzlab.ucr.edu X-Spam-Level: X-Spam-Status: No, score=-7.6 required=4.0 tests=AWL,BAYES_00,FOURLA, FVGT_m_MULTI_ODD,HAS_BUG_NUMBER,RCVD_IN_DNSWL_LOW autolearn=ham version=3.2.3-bugs.debian.org_2005_01_02 Received: (at submit) by emacsbugs.donarmstrong.com; 9 Jun 2008 18:45:45 +0000 Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) by rzlab.ucr.edu (8.13.8/8.13.8/Debian-3) with ESMTP id m59Ijesa024627 for ; Mon, 9 Jun 2008 11:45:42 -0700 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1K5mNA-00074J-KP for bug-gnu-emacs@gnu.org; Mon, 09 Jun 2008 14:45:40 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1K5mN9-000741-U1 for bug-gnu-emacs@gnu.org; Mon, 09 Jun 2008 14:45:40 -0400 Received: from [199.232.76.173] (port=35187 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1K5mN9-00073w-PO for bug-gnu-emacs@gnu.org; Mon, 09 Jun 2008 14:45:39 -0400 Received: from colin.muc.de ([193.149.48.1]:2657 helo=mail.muc.de) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1K5mN9-000375-CR for bug-gnu-emacs@gnu.org; Mon, 09 Jun 2008 14:45:39 -0400 Received: (qmail 19333 invoked by uid 3782); 9 Jun 2008 18:45:37 -0000 Received: from acm.muc.de (pD9E23E6E.dip.t-dialin.net [217.226.62.110]) by colin2.muc.de (tmda-ofmipd) with ESMTP; Mon, 09 Jun 2008 20:45:34 +0200 Received: (qmail 10324 invoked by uid 1000); 9 Jun 2008 19:07:50 -0000 Date: Mon, 9 Jun 2008 19:07:50 +0000 To: Stefan Monnier Cc: Glenn Morris , 347@debbugs.gnu.org, bug-cc-mode@gnu.org, bug-gnu-emacs@gnu.org Subject: Re: bug#347: C mode asks twice about local variables Message-ID: <20080609190750.GC6098@muc.de> References: <20080601172143.GA5899@muc.de> <20080609143651.GA6098@muc.de> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.9i X-Delivery-Agent: TMDA/1.1.5 (Fettercairn) From: Alan Mackenzie X-Primary-Address: acm@muc.de X-detected-kernel: by monty-python.gnu.org: FreeBSD 4.6-4.9 X-CrossAssassin-Score: 2 Hi, Stefan! On Mon, Jun 09, 2008 at 11:18:28AM -0400, Stefan Monnier wrote: > >> > 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? YUCK!!! ;-) I don't know off-hand what the significance of buffer locality is in CC Mode styles. But trying to get a "don't override" parameter to work would be horrendous. hack-local-variables is actually called after the language hook, isn't it? By that time, the CC Mode style will already have been set, and the pertinent variables will already be buffer local. At least I think so. > >> > 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. What I had in mind was using an (if (boundp 'before-hack-local-variables) ...) to separate out new strategy from old. > > 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. At some stage, maybe, perhaps, another option, single:, will come into being. This will mean "prompt for each non-safe variable individually". Explicitly setting `enable-local-variable' in CC Mode will couple CC Mode very strongly to files.el. That's not a good thing. > > (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. Actually, it's a lot simpler than I expectied. We can use the already read (as in lisp read) version of variables' values and we needn't separate out the "-*-" values from the "Local Variables:" values. In that case, the entire change to `hack-local-variables' would be: (i) Rename `result' to `hack-local-variables-alist'. This variable contains the spec of all local variables as an alist, and would be available to hook functions for manipulation. (ii) Insert this single line of code: ;; We've read all the local variables. Now, return whether the ;; mode is specified (if MODE-ONLY is non-nil), or set the ;; variables (if MODE-ONLY is nil.) (if mode-only result (run-hooks 'before-hack-local-variables-hook) ; <============= NEW LINE (dolist (ignored ignored-local-variables) (setq hack-local-variables-list (assq-delete-all ignored hack-local-variables-alist))) The new hook function in CC Mode (which would supersede the old one for Emacs 23 (?or 22.3?)) would be this: (defun c-before-hack-hook () "Doc string." (let ((stile (cdr (assq 'c-file-style hack-local-variables-list))) (offsets (cdr (assq 'c-file-offsets hack-local-variables-list)))) (when stile (or (stringp stile) (error "....")) (c-set-style stile)) (when offsets (mapc (lambda (langentry) (let ((langelem (car langentry)) (offset (cdr langentry))) (c-set-offset langelem offset))) offsets)))) This would replace ~90 lines of existing code (once Emacs 22 has fallen into desuetude). Oh, and the hook would need documenting in the Elisp manual, but I can manage that. Hey, this is so easy and obviously the right thing. Let's do it! > Stefan -- Alan Mackenzie (Nuremberg, Germany). From rgm@gnu.org Mon Jun 30 17:57:34 2008 X-Spam-Checker-Version: SpamAssassin 3.2.3-bugs.debian.org_2005_01_02 (2007-08-08) on rzlab.ucr.edu X-Spam-Level: X-Spam-Status: No, score=-5.8 required=4.0 tests=AWL,BAYES_00,MISSING_SUBJECT, NOSUBJECT,RCVD_IN_DNSWL_MED autolearn=ham version=3.2.3-bugs.debian.org_2005_01_02 Received: (at control) by emacsbugs.donarmstrong.com; 1 Jul 2008 00:57:34 +0000 Received: from fencepost.gnu.org (fencepost.gnu.org [140.186.70.10]) by rzlab.ucr.edu (8.13.8/8.13.8/Debian-3) with ESMTP id m610vTvE032072 for ; Mon, 30 Jun 2008 17:57:30 -0700 Received: from rgm by fencepost.gnu.org with local (Exim 4.67) (envelope-from ) id 1KDUBF-0008DR-Sr; Mon, 30 Jun 2008 20:57:13 -0400 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-ID: <18537.33001.831109.48725@fencepost.gnu.org> Date: Mon, 30 Jun 2008 20:57:13 -0400 From: Glenn Morris To: control X-Attribution: GM X-Mailer: VM (www.wonderworks.com/vm), GNU Emacs (www.gnu.org/software/emacs) X-Hue: black X-Ran: v;?(b4pp]t{=,w_+9HM*^78%x_(pE^g\/WUl}d-,bzi|U4E=t1U`#j.5bY|[3o_,#";.'L close 239 tags 253 moreinfo severity 267 wishlist tags 284 unreproducible owner 341 Alan Mackenzie owner 343 Alan Mackenzie merge 364 365 tags 366 moreinfo severity 385 minor close 387 tags 390 unreproducible moreinfo tags 393 unreproducible moreinfo close 398 close 405 tags 443 moreinfo From cyd@stupidchicken.com Thu Jul 31 07:14:56 2008 X-Spam-Checker-Version: SpamAssassin 3.2.3-bugs.debian.org_2005_01_02 (2007-08-08) on rzlab.ucr.edu X-Spam-Level: X-Spam-Status: No, score=-2.2 required=4.0 tests=AWL,BAYES_00,RCVD_IN_PBL, RCVD_IN_SORBS_DUL,RDNS_DYNAMIC autolearn=no version=3.2.3-bugs.debian.org_2005_01_02 Received: (at 347-done) by emacsbugs.donarmstrong.com; 31 Jul 2008 14:14:57 +0000 Received: from furry (c-24-63-201-57.hsd1.ma.comcast.net [24.63.201.57]) by rzlab.ucr.edu (8.13.8/8.13.8/Debian-3) with ESMTP id m6VEEmEP018359; Thu, 31 Jul 2008 07:14:49 -0700 Received: by furry (Postfix, from userid 1000) id CF51AC05A; Thu, 31 Jul 2008 10:14:42 -0400 (EDT) From: Chong Yidong To: 343-done@debbugs.gnu.org, 347-done@debbugs.gnu.org Subject: Re: C mode asks twice about local variables Date: Thu, 31 Jul 2008 10:14:42 -0400 Message-ID: <871w1aywbx.fsf@stupidchicken.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii 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 unknown Tue Jun 17 20:08:28 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: $requester Subject: Internal Control Message-Id: bug archived. Date: Thu, 28 Aug 2008 14:24:04 +0000 User-Agent: Fakemail v42.6.9 # A New Hope # A log time ago, in a galaxy far, far away # something happened. # # Magically this resulted in the following # action being taken, but this fake control # message doesn't tell you why it happened # # The action: # bug archived. thanks # This fakemail brought to you by your local debbugs # administrator From debbugs-submit-bounces@debbugs.gnu.org Fri Jan 29 14:06:48 2010 Received: (at control) by debbugs.gnu.org; 29 Jan 2010 19:06:49 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1NawB6-0006Th-CT for submit@debbugs.gnu.org; Fri, 29 Jan 2010 14:06:48 -0500 Received: from fencepost.gnu.org ([140.186.70.10]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1NawB3-0006TR-9S for control@debbugs.gnu.org; Fri, 29 Jan 2010 14:06:47 -0500 Received: from rgm by fencepost.gnu.org with local (Exim 4.69) (envelope-from ) id 1NawAz-0008CX-1L; Fri, 29 Jan 2010 14:06:41 -0500 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-ID: <19299.12736.832508.282592@fencepost.gnu.org> Date: Fri, 29 Jan 2010 14:06:40 -0500 From: Glenn Morris To: control Subject: control X-Attribution: GM X-Mailer: VM (www.wonderworks.com/vm), GNU Emacs (www.gnu.org/software/emacs) X-Hue: blue X-Ran: VO&ud[`?6f;MPwH!mdZU0Da5EQb;q|^:M@[G'\N`mS1c#>^/W4D}F4Lh'i,;0o1zMzi=T& X-Debbugs-No-Ack: yes X-Spam-Score: -4.9 (----) X-Debbugs-Envelope-To: control X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -4.9 (----) noowner 644 noowner 193 noowner 341 noowner 523 noowner 299 noowner 50 unarchive 113 noowner 113 reassign 113 emacs,cc-mode unarchive 512 noowner 512 unarchive 13 noowner 13 reassign 13 emacs,cc-mode unarchive 17 unmerge 17 noowner 16 unarchive 343 noowner 343 reassign 343 emacs,cc-mode unarchive 145 noowner 145 unarchive 45 noowner 45 unarchive 53 noowner 53 From unknown Tue Jun 17 20:08:28 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Sat, 27 Feb 2010 12:24:03 +0000 User-Agent: Fakemail v42.6.9 # A New Hope # A long time ago, in a galaxy far, far away # something happened. # # Magically this resulted in the following # action being taken, but this fake control # message doesn't tell you why it happened # # The action: # bug archived. thanks # This fakemail brought to you by your local debbugs # administrator