Emacs has specialized major modes for various programming languages. See Major Modes. A programming language major mode typically specifies the syntax of expressions, the customary rules for indentation, how to do syntax highlighting for the language, and how to find the beginning or end of a function definition. It often customizes or provides facilities for compiling and debugging programs as well.
Ideally, Emacs should provide a major mode for each programming
language that you might want to edit; if it doesn't have a mode for
your favorite language, you can contribute one. But often the mode
for one language can serve for other syntactically similar languages.
The major mode for language l is called l
and you can select it by typing M-x l-mode <RET>.
See Choosing Modes.
In most programming languages, indentation should vary from line to line to illustrate the structure of the program. So the major modes for programming languages arrange for <TAB> to update the indentation of the current line (see Program Indent). They also rebind <DEL> to treat a tab as if it were the equivalent number of spaces; this lets you delete one column of indentation without worrying whether the whitespace consists of spaces or tabs. Use C-b C-d to delete a tab character before point, in these modes.
Separate manuals are available for the modes for Ada (see), C/C++/Objective C/Java/Corba IDL/Pike/AWK (see ) and the IDLWAVE modes (see ). For Fortran mode, see Fortran.
Turning on a major mode runs a normal hook called the mode
hook, which is the value of a Lisp variable. Each major mode has a
mode hook, and the hook's name is always made from the mode command's
name by adding ‘-hook’. For example, turning on C mode runs the
c-mode-hook, while turning on Lisp mode runs the hook
lisp-mode-hook. The purpose of the mode hook is to give you a
place to set up customizations for that major mode. See Hooks.