www.delorie.com/gnu/docs/emacs/cc-mode_30.html   search  
 
Buy the book!


CC Mode Manual

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

7.5.3 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 (see section 4. 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:

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).


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

  webmaster     delorie software   privacy  
  Copyright 2003   by The Free Software Foundation     Updated Jun 2003