Custom Brace and Colon Hanging
Advanced Customizations
Other Special Indentations
You can also customize the insertion of newlines after semi-colons and
commas, when the auto-newline minor mode is enabled (see Minor Modes). This is controlled by the variable
c-hanging-semi&comma-criteria
, which contains a list of functions
that are called in the order they appear. Each function is called with
zero arguments, and is expected to return one of the following values:
nil
--- A newline is inserted, and no more functions from the
list are called.
stop
--- No more functions from the list are called, but no
newline is inserted.
nil
--- No determination is made, and the next function in the
list is called.
If every function in the list is called without a determination being
made, then no newline is added. The default value for this variable is a
list containing a single function which inserts newlines only after
semi-colons which do not appear inside parenthesis lists (i.e. those
that separate for
-clause statements).
Here's an example of a criteria function, provided by CC Mode, that
will prevent newlines from being inserted after semicolons when there is
a non-blank following line. Otherwise, it makes no determination. To
use, add this to the front of the c-hanging-semi&comma-criteria
list.
(defun c-semi&comma-no-newlines-before-nonblanks () (save-excursion (if (and (eq last-command-char ?\;) (zerop (forward-line 1)) (not (looking-at "^[ \t]*$"))) 'stop nil)))
The default value of c-hanging-semi&comma-criteria
is a list
containing just the function c-semi&comma-inside-parenlist
, which
suppresses newlines after semicolons inside parenthesis lists
(e.g. for
-loops). In addition to
c-semi&comma-no-newlines-before-nonblanks
described above,
CC Mode also comes with the criteria function
c-semi&comma-no-newlines-for-oneline-inliners
, which suppresses
newlines after semicolons inside one-line inline method definitions
(i.e. in C++ or Java).