Next: , Previous: , Up: Top   [Index]


3 Getting Started

If you got this version of CC Mode with Emacs or XEmacs, it should work just fine right out of the box. Note however that you might not have the latest CC Mode release and might want to upgrade your copy (see below).

You should probably start by skimming through the entire chapter Commands to get an overview of CC Mode’s capabilities.

After trying out some commands, you may dislike some aspects of CC Mode’s default configuration. Here is an outline of how to change some of the settings that newcomers to CC Mode most often want to change:

c-basic-offset

This Lisp variable holds an integer, the number of columns CC Mode indents nested code. To set this value to 6, customize c-basic-offset or put this into your .emacs:

(setq c-basic-offset 6)
The (indentation) style

The basic “shape” of indentation created by CC Mode—by default, this is gnu style (except for Java and AWK buffers). A list of the available styles and their descriptions can be found in Built-in Styles. A complete specification of the CC Mode style system, including how to create your own style, can be found in the chapter Styles. To set your style to linux, either customize c-default-style or put this into your .emacs:

(setq c-default-style '((java-mode . "java")
                        (awk-mode . "awk")
                        (other . "linux")))
Electric Indentation

Normally, when you type “punctuation” characters such as ‘;’ or ‘{’, CC Mode instantly reindents the current line. This can be disconcerting until you get used to it. To disable electric indentation in the current buffer, type C-c C-l. Type the same thing to enable it again. To have electric indentation disabled by default, put the following into your .emacs file2:

(setq-default c-electric-flag nil)

Details of this and other similar “Minor Modes” appear in the section Minor Modes.

Making the RET key indent the new line

The standard Emacs binding for RET just adds a new line. If you want it to reindent the new line as well, rebind the key. Note that the action of rebinding would fail if the pertinent keymap didn’t yet exist—we thus need to delay the action until after CC Mode has been loaded. Put the following code into your .emacs:

(defun my-make-CR-do-indent ()
  (define-key c-mode-base-map "\C-m" 'c-context-line-break))
(add-hook 'c-initialization-hook 'my-make-CR-do-indent)

This example demonstrates the use of a very powerful CC Mode (and Emacs) facility, the hook. The use of CC Mode’s hooks is described in CC Hooks.

All these settings should occur in your .emacs before any CC Mode buffers get loaded—in particular, before any call of desktop-read.

As you get to know the mode better, you may want to make more ambitious changes to your configuration. For this, you should start reading the chapter Config Basics.

If you are upgrading an existing CC Mode installation, please see the README file for installation details. In particular, if you are going to be editing AWK files, README describes how to configure your (X)Emacs so that CC Mode will supersede the obsolete awk-mode.el which might have been supplied with your (X)Emacs. CC Mode might not work with older versions of Emacs or XEmacs. See the CC Mode release notes at http://cc-mode.sourceforge.net for the latest information on Emacs version and package compatibility (see Updating CC Mode).

Command: c-version

You can find out what version of CC Mode you are using by visiting a C file and entering M-x c-version RET. You should see this message in the echo area:

Using CC Mode version 5.XX

where ‘XX’ is the minor release number.


Footnotes

(2)

There is no “easy customization” facility for making this change.


Next: , Previous: , Up: Top   [Index]