[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

U.1 Major Modes for Programming Languages

Emacs has specialized major modes for various programming languages. See section R. 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 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-mode, and you can select it by typing M-x l-mode RET. See section R.1 How Major Modes are Chosen.

The existing programming language major modes include Lisp, Scheme (a variant of Lisp) and the Scheme-based DSSSL expression language, Ada, Awk, C, C++, Delphi (Object Pascal), Fortran (free format and fixed format), Icon, IDL (CORBA), IDLWAVE, Java, Metafont (TeX's companion for font creation), Modula2, Objective-C, Octave, Pascal, Perl, Pike, PostScript, Prolog, Simula, Tcl, and VHDL. There is also a major mode for makefiles, called Makefile mode. An alternative mode for Perl is called CPerl mode. Modes are available for the scripting languages of the common GNU and Unix shells, VMS DCL, and MS-DOS/MS-Windows `BAT' files. There are also major modes for editing various sorts of configuration files.

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. 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 section `Ada Mode' in Ada Mode), C/C++/Objective C/Java/Corba IDL (see section `CC Mode' in CC Mode) and the IDLWAVE modes (see section `IDLWAVE' in IDLWAVE User Manual).

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 hook 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 section AD.2.3 Hooks.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

This document was generated on April 2, 2002 using texi2html