01.09.2014 Views

The Linux Development Platform Configuring, Using, and ... - Classes

The Linux Development Platform Configuring, Using, and ... - Classes

The Linux Development Platform Configuring, Using, and ... - Classes

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

CH02.fm Page 26 Monday, October 7, 2002 8:09 PM<br />

26 Chapter 2 • Working With Editors<br />

2.2.4 Language Modes<br />

Emacs recognizes a number of different programming language files based on their extensions.<br />

When you load a recognized source code file, Emacs will assume certain defaults <strong>and</strong><br />

enter the appropriate mode for editing that file.<br />

For example, when you load a file with a .c extension for editing, Emacs sets the appropriate<br />

mode <strong>and</strong> enables comm<strong>and</strong>s used to automatically <strong>and</strong> manually indent code, quickly move<br />

though functions <strong>and</strong> insert comments.<br />

When a language mode is on, Emacs can automatically indent code as you type. To turn<br />

this mode on, type ^C^A. <strong>The</strong> same comm<strong>and</strong> is used to turn this mode back off.<br />

With this mode active, auto-indenting takes place when certain characters are entered from<br />

the keyboard. <strong>The</strong>se characters are the semi-colon, curly braces, <strong>and</strong> under certain circumstances,<br />

the comma <strong>and</strong> colon.<br />

For example, if auto-indent (or technically c-toggle-auto-state) is on <strong>and</strong> the following<br />

code is typed into the buffer:<br />

void main ( int argc, char **argv) { while (<br />

it will be formatted by Emacs as follows:<br />

void main ( int argc, char **argv)<br />

{<br />

while (<br />

Table 2-9 shows some of the common C-mode comm<strong>and</strong>s.<br />

Table 2-9 C-mode Comm<strong>and</strong>s<br />

Action<br />

ESC ;<br />

ESC ^A<br />

ESC ^E<br />

ESC ^H<br />

Comm<strong>and</strong><br />

Insert comment<br />

Go to top of function<br />

Go to bottom of function<br />

Mark function<br />

{ Insert bracket <strong>and</strong> return<br />

} Return <strong>and</strong> insert bracket<br />

^C^A<br />

Toggle Auto-indent mode<br />

^\ Auto-indent selected region

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!