Subject: bug#22166: 24.5; Mixing up Local Variables declarations

From: Glenn Morris <[email-masked]>
Date: Mon, 14 Dec 2015 11:57:19 -0500

PEDRO ANDRES ARANDA GUTIERREZ wrote:

> <--- cut here
> #include <stdio.h>
>
> int main(int argc,char **argv)
> {
> printf("\
> %%%% Local Variables:\n\
> %%%% mode: LaTeX\n\
> %%%% TeX-PDF-mode: t\n\
> %%%% TeX-master: \"main\"\n\
> %%%% End:\n\
> ")
> }
> <--- cut here
>
> The mode is changed from C mode to LaTEX mode and that should not
> happen.

That's the correct, documented behavior (see "set-auto-mode" in the
Elisp manual). Local Variables lines may have prefixes and suffixes, and
"mode:" override auto-mode-alist. You'll have to disguise the Local
Variables section if you don't want Emacs to act on it in this case. Eg
you could write it out in two chunks, or simply add

/*
^L
/*

at the very end of the file, since Emacs only searches in the last
"page" for Local Variables.