Variable: c-hanging-braces-alist

c-hanging-braces-alist is a customizable and buffer-local variable defined in cc-vars.el.gz.

Documentation

Controls the insertion of newlines before and after braces when the auto-newline feature is active. This variable contains an association list with elements of the following form:
(SYNTACTIC-SYMBOL . ACTION).

When a brace (either opening or closing) is inserted, the syntactic context it defines is looked up in this list, and if found, the associated ACTION is used to determine where newlines are inserted. If the context is not found, the default is to insert a newline both before and after the brace.

SYNTACTIC-SYMBOL can be statement-cont, brace-list-intro, inexpr-class-open, inexpr-class-close, and any of the *-open and
*-close symbols. See c-offsets-alist for details, except for
inexpr-class-open and inexpr-class-close, which doesn't have any corresponding symbols there. Those two symbols are used for the opening and closing braces, respectively, of anonymous inner classes in Java.

ACTION can be either a function symbol or a list containing any combination of the symbols before or after. If the list is empty, no newlines are inserted either before or after the brace.

When ACTION is a function symbol, the function is called with a two arguments: the syntactic symbol for the brace and the buffer position at which the brace was inserted. The function must return a list as described in the preceding paragraph. Note that during the call to the function, the variable c-syntactic-context is set to the entire syntactic context for the brace line.

This is a style variable. Apart from the valid values described above, it can be set to the symbol set-from-style. In that case, it takes its value from the style system (see c-default-style and c-style-alist) when a CC Mode buffer is initialized. Otherwise, the value set here overrides the style system (there is a variable c-old-style-variable-behavior that changes this, though).

Probably introduced at or before Emacs version 19.23.

Source Code

;; Defined in /usr/src/emacs/lisp/progmodes/cc-vars.el.gz
(defcustom-c-stylevar c-hanging-braces-alist '((brace-list-open)
					       (brace-entry-open)
					       (statement-cont)
					       (substatement-open after)
					       (block-close . c-snug-do-while)
					       (extern-lang-open after)
					       (namespace-open after)
					       (module-open after)
					       (composition-open after)
					       (inexpr-class-open after)
					       (inexpr-class-close before)
					       (arglist-cont-nonempty))
  "Controls the insertion of newlines before and after braces
when the auto-newline feature is active.  This variable contains an
association list with elements of the following form:
\(SYNTACTIC-SYMBOL . ACTION).

When a brace (either opening or closing) is inserted, the syntactic
context it defines is looked up in this list, and if found, the
associated ACTION is used to determine where newlines are inserted.
If the context is not found, the default is to insert a newline both
before and after the brace.

SYNTACTIC-SYMBOL can be statement-cont, brace-list-intro,
inexpr-class-open, inexpr-class-close, and any of the *-open and
*-close symbols.  See `c-offsets-alist' for details, except for
inexpr-class-open and inexpr-class-close, which doesn't have any
corresponding symbols there.  Those two symbols are used for the
opening and closing braces, respectively, of anonymous inner classes
in Java.

ACTION can be either a function symbol or a list containing any
combination of the symbols `before' or `after'.  If the list is empty,
no newlines are inserted either before or after the brace.

When ACTION is a function symbol, the function is called with a two
arguments: the syntactic symbol for the brace and the buffer position
at which the brace was inserted.  The function must return a list as
described in the preceding paragraph.  Note that during the call to
the function, the variable `c-syntactic-context' is set to the entire
syntactic context for the brace line."
  :type
  `(set ,@(mapcar
	   (lambda (elt)
	     `(cons :format "%v"
		    ,(c-constant-symbol elt 24)
		    (choice :format "%[Choice%] %v"
			    :value (before after)
			    (set :menu-tag "Before/after"
				 :format "Newline  %v brace\n"
				 (const :format "%v,  " before)
				 (const :format "%v " after))
			    (function :menu-tag "Function"
				      :format "Run function: %v"))))
	   '(defun-open defun-close
	      class-open class-close
	      inline-open inline-close
	      block-open block-close
	      statement-cont substatement-open statement-case-open
	      brace-list-open brace-list-close
	      brace-list-intro brace-entry-open
	      extern-lang-open extern-lang-close
	      namespace-open namespace-close
	      module-open module-close
	      composition-open composition-close
	      inexpr-class-open inexpr-class-close
	      arglist-cont-nonempty)))
    :group 'c)