Info Node: (ccmode)Customizing Semi-colons and Commas
(ccmode)Customizing Semi-colons and Commas
Customizing Semi-colons and Commas
----------------------------------
You can also customize the insertion of newlines after semi-colons
and commas, when the auto-newline minor mode is enabled (Note:Minor
Modes). This is controlled by the style 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:
* non-`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 function `c-semi&comma-inside-parenlist' is what prevents
newlines from being inserted inside the parenthesis list of `for'
statements. 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).