7

Beginner question:

In OSX 10.6.8, Aquamacs has many buffer modes. My .tex files open in TeX mode, but I would like to open them in LaTeX mode. I can change the Mode with "Change Buffer Mode", but even after a "save" or a "save as", the old mode remains.

How can I change the mode once for all? (The question also pertains to standard emacs, I guess).

1
  • There isn't a "Save" or "Save As..." in Aquamacs. Just to clarify, do you mean "Save Buffer"/"Save Buffer As..." or "Save Session As..."? Feb 20, 2015 at 9:11

3 Answers 3

7

In addition to Andrew Swann's specific answer for TeX files, the more general way to set the mode by file extension is to put a new entry (or adapt the existing one) in the auto-mode-alist.

From the manual:

This variable contains an association list of file name patterns (regular expressions) and corresponding major mode commands. Usually, the file name patterns test for suffixes, such as ‘.el’ and ‘.c’, but this need not be the case. An ordinary element of the alist looks like (regexp . mode-function).

For example,

      (("\\`/tmp/fol/" . text-mode)
       ("\\.texinfo\\'" . texinfo-mode)
       ("\\.texi\\'" . texinfo-mode)
       ("\\.el\\'" . emacs-lisp-mode)
       ("\\.c\\'" . c-mode)
       ("\\.h\\'" . c-mode)
       ...)

So one would ordinarily make a permanent change to the list with something like:

(add-to-list 'auto-mode-alist '("\\.tex\\'" . latex-mode))

Note the backslashes, which escape special characters.

The alist works because the first matching value in the list will be used. You can therefore add to the front of the list regardless of the original contents for that file type, and your new value will be used.

6

You can customize the variable tex-default-mode to e.g. latex-mode.

This is actually the default value in tex-mode.el, so either you have a variable setting/customization overriding that, perhaps set by aquamacs or you have an old installation of emacs.

3

You can also use file local variables: put %-*- mode: latex -*- as the first line into your file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.