26Chapter2 • Working With Editors
2.2.4Language Modes
Emacs recognizes a number of different programming language files based on their exten-
sions. When you load a recognized source code file, Emacs will assume certain defaults and
enter the appropriate mode for editing that file.
For example, when you load a file with a .c extension for editing, Emacs sets the appropri-
ate mode and enables commands used to automatically and manually indent code, quickly move
though functions and insert comments.
When a language mode is on, Emacs can automatically indent code as you type. To turn
this mode on, type
^C^A
. The same command is used to turn this mode back off.
With this mode active, auto-indenting takes place when certain characters are entered from
the keyboard. These characters are the semi-colon, curly braces, and under certain circum-
stances, the comma and colon.
For example, if auto-indent (or technically
c-toggle-auto-state
) is on and the following
code is typed into the buffer:
void main ( int argc, char **argv) { while (
it will be formatted by Emacs as follows:
void main ( int argc, char **argv)
{
while (
Table 2-9 shows some of the common C-mode commands.
Table2-9 C-mode Commands
ActionCommand
ESC ;Insert comment
ESC ^AGo to top of function
ESC ^EGo to bottom of function
ESC ^HMark function
{Insert bracket and return
}Return and insert bracket
^C^AToggle Auto-indent mode
^\Auto-indent selected region
Next Page >>
<< Previous Page
Back to the Table of Contents