# c(9)

[Home] [Commands] [Variables] [Macro-Dev] [Glossary]

## SYNOPSIS

C, C++ - C and C++ programming language templates

## FILES

hkc.emf - C programming language hook definition
hkcpp.emf - C++ programming language hook definition

c.etf - C programming language template file
h.etf - C programming language header template file
cpp.etf - C++ programming language template file
hpp.etf - C++ programming language header template file

## EXTENSIONS

.c, .h, .def - ANSI C
.cpp, .cc, .hpp, .rc .C (UNIX only) - C++ programming language
.l - LEX
.y - YACC
.i - C (or C++) pre-processed file (i.e. output from pre-processor).
.rc - Microsoft Developer resource file.

## MAGIC STRINGS

-*- c -*-

Recognized by GNU and MicroEmacs. Denotes a 'C' programming type file, may be used in .c, .def and .h files.

-*- c++ -*-

Recognized by GNU and MicroEmacs. Denotes a C++ programming type file, may be used in .c, .def and .h files.

## DESCRIPTION

The C and C++ file type templates offer the most sophisticated editing features within the MicroEmacs 2009 environment.

General Editing

On creating a new file, a new header is automatically included into the file. time(2m) is by default enabled, allowing the modification time-stamp to be maintained in the header.

Hilighting

The hilighting features allow commands, variables, logical, preprocessor definitions, comments, strings and characters of the language to be differentiated and rendered in different colors.

Auto Layout

The C-Mode indentation mode of indent(2) performs automatic layout of the text.

restyle-region(3) and restyle-buffer(3) are available to reformat (re-layout) selected sections of the buffer, or the whole buffer, respectively.

Comments may be formatted using `esc o`, which reformats the comments according to the current fill paragraph. If a comment commences with `/***...` then the comment is automatically formatted to a box. If the comment commentces with `/**` then the comment is assumed to be a Java Doc comment.

Tags

A C-tags file may be generated within the editor using the Tools -> C Tools -> Create Tag File. find-tag(2) takes the user to the file using the tag information.

On invoking the tag generator then the user is presented with a dialog box which specifies the generation option of the tags file. The base directory of the tags file search and tagging options may be specified to locate all of the definitions within the code space.

The tags file is extremely useful where the user is dealing with inherited source code spread over multiple directories. Generation of a recursive tag file with all searching options enabled allows labels to be located extremely rapidly (certainly faster than IDE environments).

Folding and Information Hiding

Generic folding is enabled within the C and C++ files. The folds occur about braces {...} located on the left-hand margin. collapse-all(3) (un)folds all regions in the file, collapse-current(3) (un)folds the current region. Note that folding does not operate on K&R style code.

The Tools -> C Tools menu allows `#define`'s to be evaluated within the buffer. Where the state of a `#if` is established to be false (using the `#define` information) then the disabled region of code is grayed out indicating which regions of the code are active.

Working Environment

compile(3) may be invoked to rebuild the source, the user is prompted to save any files.

rcs-file(2) is automatically invoked if an RCS file is detected, the normal check-in/out operations may be performed through the editor.

Short Cuts

The short cut keys used within the buffer are:-

C-c C-c - Comment out the current line.
C-c C-d - Uncomment the current line.
C-c C-e - Comment to the end of the line with stars (*).
A-C-i - Restyle the current region.
esc q - Format a comment.
esc o - Format a comment.
f2 - (un)fold the current region
f3 - (un)fold all regions

Additional Commands

A number of additional commands are available as follows:-

- c-slashify(3) - Append backslash to end of lines of region.
- c-deslashify(3) - Remove backslash to end of lines of region.
- c-to-cpp-convert(3) - Convert a C file to C++
- c-hash-eval(3) - Evaluate C/C++ `#define`s.
- c-hash-del(3) - Remove C/C++ `#define` evaluation.
- c-hash-set-define(3) - Set a C/C++ `#define`.
- c-hash-unset-define(3) - Unset a C/C++ `#define`

## NOTES

If the default language is C++, rather than 'C' the order of the file hooks should be over-ridden in the users local setup, using:-

    add-file-hook ".c "                                  fhook-c
    add-file-hook ".cc .cpp .hpp .rc .h .def .l .y .i"   fhook-cpp

This defaults all .h and .def files etc. to be C++ rather than C.

The hilighting is typically extended using a file myc.emf (or mycpp.emf) i.e. to include the usual extended types of int32 etc, myc.emf might be defined as:-

    hilight .hilight.c 1 "uint8"    .scheme.type
    hilight .hilight.c 1 "int8"     .scheme.type
    hilight .hilight.c 1 "uint16"   .scheme.type
    hilight .hilight.c 1 "int16"    .scheme.type
    hilight .hilight.c 1 "uint32"   .scheme.type
    hilight .hilight.c 1 "int32"    .scheme.type
    hilight .hilight.c 1 "float32"  .scheme.type
    hilight .hilight.c 1 "float64"  .scheme.type

## BUGS

The 'C' and 'C++' templates have been throughly used, there are no known issues with the templates.

The .rc hilighting is a little bogus and should not really be mapped onto .cpp. Do not attept to re-style.

## SEE ALSO

c-deslashify(3), c-slashify(3), c-to-cpp-convert(3), collapse-all(3), collapse-current(3), compile(3), ctags(3f), find-tag(2), rcs-file(2), restyle-buffer(3), restyle-region(3), time(2m).

Supported File Types

(c) Copyright JASSPA 2009
Last Modified: 2009/08/29
Generated On: 2009/10/12

</HMTL>