In C-mode and C++mode the key bindings defined by Smac are:
\_
indent\_
line function.
\_
indent\_
line function. It may be necessary to type
tab after some characters modifying the line context (for
instance after case).
c\_
insert\_
blink\_
matched\_
char\_
and\_
indent.
\_
indent\_
line.
#, }
, space, tab and newline, or whose
first two characters are not //
or /*
, and
whose previous line last char (before newline) is not
\
. Obviously the beginning of the buffer is also
considered to be a definition beginning. Made by the function
goto\_
beginning\_
of\_
c\_
definition.
{,(,[
or "
it goes after the corresponding },),]
or "
, else it goes to the end of the
following word. A word contains alphabetic characters,
digits and underscore. Made by the forward\_
c\_
form
function.
\_
c\_
form function.
\_
next\_
c\_
form function.
delete\_
previous\_
c\_
form.
\_
indent\_
region function.
Indentation is parameterized by the following global variables:
\_
indent\_
in\_
comment (default
value 3)
\_
indent\_
in\_
string (default
value 0)
\_
indent\_
in\_
parenthesis
(default value 1)
\_
indent\_
in\_
bracket (default
value 1)
\_
indent\_
in\_
brace (default
value 2)
\_
indent\_
in\_
statement (default
value 2)
\_
arg\_
decl\_
indent (default
value 4)
The indentation rules for an empty line, for instance when you type a return at the end of a line, are (take a deep breath):
/*
' position plus the
absolute value of c\_
indent\_
in\_
comment. A
comment begins with `/*
' and ends with `*/
',
and a C++ comment with `//
' and ends at the end of
line.
\_
indent\_
in\_
string is less than 0 the
indentation is the string beginning position minus c\_
indent\_
in\_
string (so plus its absolute
value), otherwise indentation equals c\_
indent\_
in\_
string.
\_
indent\_
in\_
parenthesis.
\_
indent\_
in\_
bracket.
{}
), all depends
on the previous character (skipping space, tab,
newline and comments):
\_
indent\_
in\_
brace.
`.'
or `;'
, indentation
is set to the previous expression indentation.
\_
indent\_
in\_
statement.
\_
indent\_
in\_
statement.
\_
arg\_
decl\_
indent because it is probably
the parameters of a function written with the old
syntax.
`;'
, indentation is set to
previous expression indentation.
\_
indent\_
in\_
statement,
elsewhere 0.
The indentation rules, when you indent a non empty line (for
instance when you reindent a line with a tab) depend on
the first character(s) (jumping space, tab, newline and
comments) (cheer up !
, we're almost there):
#
', indentation is set to 0.
*
' and the next character is
`/
', so you close a comment, indentation is set
to the indentation of the `/*
'
`:'
, indentation is set to the
indentation of the corresponding `?'
.
As you can see, it is rather complicated, nevertheless some cases are not taken into account and need braces. For instance it is the case for nested if like:
are poorly indented:
but the indentation is correct with braces:
Of course the quantity of code interpreted by Smac when you type a simple return is rather disturbing, but don't be afraid, Smac is a good boy.