[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
In C mode and related modes, certain printing characters are
"electric"---in addition to inserting themselves, they also reindent
the current line and may insert newlines. This feature is controlled by
the variable c-auto-newline
. The "electric" characters are
{, }, :, #, ;, ,, <,
>, /, *, (, and ).
Electric characters insert newlines only when the auto-newline
feature is enabled (indicated by `/a' in the mode line after the
mode name). This feature is controlled by the variable
c-auto-newline
. You can turn this feature on or off with the
command C-c C-a:
c-toggle-auto-state
). With a
prefix argument, this command turns the auto-newline feature on if the
argument is positive, and off if it is negative.
The colon character is electric because that is appropriate for a single colon. But when you want to insert a double colon in C++, the electric behavior of colon is inconvenient. You can insert a double colon with no reindentation or newlines by typing C-c ::
c-scope-operator
).
The electric # key reindents the line if it appears to be the
beginning of a preprocessor directive. This happens when the value of
c-electric-pound-behavior
is (alignleft)
. You can turn
this feature off by setting c-electric-pound-behavior
to
nil
.
The variable c-hanging-braces-alist
controls the insertion of
newlines before and after inserted braces. It is an association list
with elements of the following form: (syntactic-symbol
. nl-list)
. Most of the syntactic symbols that appear in
c-offsets-alist
are meaningful here as well.
The list nl-list may contain either of the symbols
before
or after
, or both; or it may be nil
. When a
brace is inserted, the syntactic context it defines is looked up in
c-hanging-braces-alist
; if it is found, the nl-list is used
to determine where newlines are inserted: either before the brace,
after, or both. If not found, the default is to insert a newline both
before and after braces.
The variable c-hanging-colons-alist
controls the insertion of
newlines before and after inserted colons. It is an association list
with elements of the following form: (syntactic-symbol
. nl-list)
. The list nl-list may contain either of the
symbols before
or after
, or both; or it may be nil
.
When a colon is inserted, the syntactic symbol it defines is looked up in this list, and if found, the nl-list is used to determine where newlines are inserted: either before the brace, after, or both. If the syntactic symbol is not found in this list, no newlines are inserted.
Electric characters can also delete newlines automatically when the
auto-newline feature is enabled. This feature makes auto-newline more
acceptable, by deleting the newlines in the most common cases where you
do not want them. Emacs can recognize several cases in which deleting a
newline might be desirable; by setting the variable
c-cleanup-list
, you can specify which of these cases that
should happen. The variable's value is a list of symbols, each
describing one case for possible deletion of a newline. Here are the
meaningful symbols, and their meanings:
brace-catch-brace
catch
and condition.
brace-else-brace
else
, but only if there is nothing but white space between
the braces and the else
.
brace-elseif-brace
if
-condition.
empty-defun-braces
defun-close-semi
struct
or similar type
declaration, by placing the semicolon on the same line as the closing
brace. Clean-up occurs when you type the semicolon.
list-close-comma
scope-operator
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |