Dumb emacs question

When I open a Perl file in Emacs, it goes into Perl mode. When I open a C file, it goes into C mode. This is really cool. But I want to force Emacs to load some specific modes when other extensions are used. (This doesn’t need to be automatic, I just want to be able to press a button and load whatever mode I want.)

So what rediculous combination of keys do I have to press to make this happen?


What you want to do is to change the major mode.
Depending on your settings (in ~/.emacs) this is done more or less automatically when you open a file, but can also be changed explicitly. Eg. to change to C-mode, try M-x c-mode.
(M-x == meta-x, depending on your terminal this could mean meta, alt, or the windows key, and x)

For a introduction to writing your own major modes, look at the GNU Elisp manual.

To make it automatic, you have to modify your .emacs file. Apparently something like this should work if added to the end of that file, but I haven’t tried it personally. You have to modify it to your tastes of course.

(setq auto-mode-alist (append '(
                ("\\.cc$"   . c++-mode)
                ("\\.h$"    . c++-mode)
                ("\\.c$"    . c-mode)
                ("\\.tex$"  . latex-mode)
                ("\\.txt$"  . text-mode)
        ) auto-mode-alist))

FYI, that shouldn’t be double-spaced if it is. Stupid Netscape.