[Tex/LaTex] Getting Emacs to choose between LaTeX/ConTeXt mode depending on file

auctexemacs

I have lots of LaTeX files, and my AucTeX has been set up to automatically open up all *.tex files in LaTeX-mode. But more recently I've started using ConTeXt, and for those files (which also end in .tex) I'd like to use ConTeXt-mode. Is there any way of embedding something in the file which will tell Emacs to open up the correct mode?

I can start a file with, for example

-*- mode: context; -*-

which works well, but even if it's the very first line in the file, ConTeXt still parses it and writes it to the output, although it comes way before \starttext.

Does anybody have any better suggestions? I suppose the sensible thing would be to move all ConTeXt files into one directory tree, and set up a .dir-locals.el file in that directory, which would tell Emacs to open up all .tex files using ConTeXt mode. But I'd still like to be able to do it on a file-by-file basis.

FWIW, I'm using Linux.

Thanks!

Best Answer

Can't you simply put a % in front of this line?

I'm using this in the last some lines of my files, for example.

%%% Local Variables: 
%%% mode: latex
%%% TeX-master: "spezialisierung"
%%% End: 

But

% -*- mode: context; -*-

in the first line should work, too.

Related Question