unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#7767: 23.2.91; file-local-variables-alist should have the permanent-local property
@ 2011-01-01  4:12 Alex Harsanyi
  2011-01-01 19:38 ` Stefan Monnier
  0 siblings, 1 reply; 4+ messages in thread
From: Alex Harsanyi @ 2011-01-01  4:12 UTC (permalink / raw)
  To: 7767

Here is a scenario that illustrates the problem.  Save the following
into a file named hello.cc:

----------
#include <iostream>

int main()
{
  std::cout << "Hello World\n";
}

/*
  Local Variables:
  mode: c++
  compile-command: "g++ -o hello hello.cc"
  End:
*/
----------

After visiting this file in Emacs, and typing M-x compile RET, I expect
the default compilation command to be the one set in the local variables
section of the file.  Instead it is "make -k" which is the default one
for the  `compile-command' variable.

I tried to debug the problem and it seems that `hack-local-variables'
will collect the local variables into `file-local-variables-alist' than
run the hook `before-hack-local-variables-hook' which containts the
function `c-before-hack-hook'.

`c-before-hack-hook' will see the `mode' variable and call `c++-mode'
which than will call `kill-all-local-variables' setting
`file-local-variables-alist' to nil so that the remaining variables are
not processed.

Adding the `permanent-local' property to `file-local-variables-alist'
seems to fix the problem.

Note that the problem does not seem too occur if the mode is set to 'c',
but it does for 'c++' and 'python'.  I'm not sure why this is.

This happens both on the trunk and on the emacs-23 branch.


In GNU Emacs 23.2.91.1 (x86_64-apple-darwin10.5.0, NS apple-appkit-1038.35)
of 2010-12-31 on karinji-2.local
Windowing system distributor `Apple', version 10.3.1038
configured using `configure  '--with-ns''

Important settings:
  value of $LC_ALL: nil
  value of $LC_COLLATE: nil
  value of $LC_CTYPE: nil
  value of $LC_MESSAGES: nil
  value of $LC_MONETARY: nil
  value of $LC_NUMERIC: nil
  value of $LC_TIME: nil
  value of $LANG: en_AU.UTF-8
  value of $XMODIFIERS: nil
  locale-coding-system: utf-8-unix
  default enable-multibyte-characters: t

Major mode: C++/l

Minor modes in effect:
  tooltip-mode: t
  mouse-wheel-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  line-number-mode: t
  transient-mark-mode: t
  abbrev-mode: t

Recent input:
C-x C-f ~ / P r o <tab> h e <tab> <return> M-x c o 
m p i l e <return> C-g M-x r e p o r t - e m <tab> 
<return> C-g C-h f h a c k <tab> l o <tab> <return> 
<help-echo> <help-echo> <help-echo> <down-mouse-1> 
<mouse-2> <help-echo> <wheel-down> <wheel-down> <double-wheel-down> 
<down-mouse-1> <mouse-1> C-v C-v C-v C-v <down-mouse-1> 
<mouse-movement> <mouse-movement> <drag-mouse-1> s-w 
M-w <help-echo> <down-mouse-1> <mouse-1> M-x <up> 
<return>

Recent messages:
For information about GNU Emacs and the GNU system, type C-h C-a.
Quit [2 times]
Type C-x 1 to delete the help window.
uncompressing files.el.gz...done
Loading vc-bzr...done
call-interactively: Attempt to delete the sole visible or iconified frame

Load-path shadows:
None found.

Features:
(shadow sort mail-extr message ecomplete rfc822 mml mml-sec
password-cache mm-decode mm-bodies mm-encode mailcap mail-parse rfc2231
rfc2047 rfc2045 qp ietf-drums mailabbrev nnheader gnus-util netrc
time-date mm-util mail-prsvr gmm-utils wid-edit mailheader canlock
hashcash mail-utils vc-bzr sha1 hex-util jka-compr find-func help-mode
view help-fns emacsbug compile comint ring cc-mode cc-fonts cc-menus
cc-cmds cc-styles cc-align cc-engine cc-vars cc-defs regexp-opt tooltip
ediff-hook vc-hooks lisp-float-type mwheel ns-win easymenu tool-bar dnd
fontset image fringe lisp-mode register page menu-bar rfn-eshadow timer
select scroll-bar mldrag mouse jit-lock font-lock syntax facemenu
font-core frame cham georgian utf-8-lang misc-lang vietnamese tibetan
thai tai-viet lao korean japanese hebrew greek romanian slovak czech
european ethiopic indian cyrillic chinese case-table epa-hook
jka-cmpr-hook help simple abbrev loaddefs button minibuffer faces
cus-face files text-properties overlay md5 base64 format env code-pages
mule custom widget hashtable-print-readable backquote
make-network-process dbusbind ns multi-tty emacs)





^ permalink raw reply	[flat|nested] 4+ messages in thread

* bug#7767: 23.2.91; file-local-variables-alist should have the permanent-local property
  2011-01-01  4:12 bug#7767: 23.2.91; file-local-variables-alist should have the permanent-local property Alex Harsanyi
@ 2011-01-01 19:38 ` Stefan Monnier
  2011-01-01 23:26   ` Alex Harsanyi
  0 siblings, 1 reply; 4+ messages in thread
From: Stefan Monnier @ 2011-01-01 19:38 UTC (permalink / raw)
  To: Alex Harsanyi; +Cc: 7767

> I tried to debug the problem and it seems that `hack-local-variables'
> will collect the local variables into `file-local-variables-alist' than
> run the hook `before-hack-local-variables-hook' which containts the
> function `c-before-hack-hook'.
> `c-before-hack-hook' will see the `mode' variable and call `c++-mode'
> which than will call `kill-all-local-variables' setting
> `file-local-variables-alist' to nil so that the remaining variables are
> not processed.

It sounds like cc-mode does something odd here.

> Adding the `permanent-local' property to `file-local-variables-alist'
> seems to fix the problem.

My first impression is rather that this would work around the problem
introduced by cc-mode.  So I'd first want to make sure that cc-mode has
a good reason to call c++-mode from before-hack-local-variables-hook.

> This happens both on the trunk and on the emacs-23 branch.

Alan, could you enlighten us?


        Stefan





^ permalink raw reply	[flat|nested] 4+ messages in thread

* bug#7767: 23.2.91; file-local-variables-alist should have the permanent-local property
  2011-01-01 19:38 ` Stefan Monnier
@ 2011-01-01 23:26   ` Alex Harsanyi
  2011-01-02  3:58     ` Stefan Monnier
  0 siblings, 1 reply; 4+ messages in thread
From: Alex Harsanyi @ 2011-01-01 23:26 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: 7767


On 2 Jan 2011, at 3:38 AM, Stefan Monnier wrote:

>> I tried to debug the problem and it seems that `hack-local-variables'
>> will collect the local variables into `file-local-variables-alist' than
>> run the hook `before-hack-local-variables-hook' which containts the
>> function `c-before-hack-hook'.
>> `c-before-hack-hook' will see the `mode' variable and call `c++-mode'
>> which than will call `kill-all-local-variables' setting
>> `file-local-variables-alist' to nil so that the remaining variables are
>> not processed.
> 
> It sounds like cc-mode does something odd here.

On further investigation, this only happens when the mode setting 
changes the mode of the file.  That is, a file named "hello.c" with a 
"mode: c++" setting.  It does not happen otherwise, because 
`hack-one-local-variable' will not enable a major mode if it is 
already set for the file.

However, `c-before-hack-hook' does enable the mode itself via a call to 
`hack-one-local-variable'.

Best Regards,
Alex.





^ permalink raw reply	[flat|nested] 4+ messages in thread

* bug#7767: 23.2.91; file-local-variables-alist should have the permanent-local property
  2011-01-01 23:26   ` Alex Harsanyi
@ 2011-01-02  3:58     ` Stefan Monnier
  0 siblings, 0 replies; 4+ messages in thread
From: Stefan Monnier @ 2011-01-02  3:58 UTC (permalink / raw)
  To: Alex Harsanyi; +Cc: 7767

close 7767
thanks

>>> I tried to debug the problem and it seems that `hack-local-variables'
>>> will collect the local variables into `file-local-variables-alist' than
>>> run the hook `before-hack-local-variables-hook' which containts the
>>> function `c-before-hack-hook'.
>>> `c-before-hack-hook' will see the `mode' variable and call `c++-mode'
>>> which than will call `kill-all-local-variables' setting
>>> `file-local-variables-alist' to nil so that the remaining variables are
>>> not processed.
>> 
>> It sounds like cc-mode does something odd here.

> On further investigation, this only happens when the mode setting 
> changes the mode of the file.  That is, a file named "hello.c" with a 
> "mode: c++" setting.  It does not happen otherwise, because 
> `hack-one-local-variable' will not enable a major mode if it is 
> already set for the file.

> However, `c-before-hack-hook' does enable the mode itself via a call to 
> `hack-one-local-variable'.

On further investigation, I see that in modes other than cc-mode,
a similar problem appears: the mode is set properly and the local
variables are set correctly, but file-local-variables-alist ends up nil
in the buffer (including when hack-local-variables-hook is run), which
is not right.

More specifically, it's the same bug that manifests itself differently
because in the non-cc case, the file-local-variables-alist gets set to
nil a bit later, more specifically it's set right after reading
file-local-variables-alist to set up the loop that calls
hack-one-local-variable.

So, I agree with your original analysis and have installed the change
below to the emacs-23 branch.  Thank you,


        Stefan


=== modified file 'lisp/files.el'
--- lisp/files.el	2010-12-04 21:45:17 +0000
+++ lisp/files.el	2011-01-02 03:47:28 +0000
@@ -2788,6 +2788,7 @@
 specified.  The actual value in the buffer may differ from VALUE,
 if it is changed by the major or minor modes, or by the user.")
 (make-variable-buffer-local 'file-local-variables-alist)
+(put 'file-local-variables-alist 'permanent-local t)
 
 (defvar dir-local-variables-alist nil
   "Alist of directory-local variable settings in the current buffer.






^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2011-01-02  3:58 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-01-01  4:12 bug#7767: 23.2.91; file-local-variables-alist should have the permanent-local property Alex Harsanyi
2011-01-01 19:38 ` Stefan Monnier
2011-01-01 23:26   ` Alex Harsanyi
2011-01-02  3:58     ` Stefan Monnier

Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).