12.2 Macros with semicolons

Macros which needn’t (or mustn’t) be followed by a semicolon when you invoke them, macros with semicolons, are very common. These can cause CC Mode to parse the next line wrongly as a statement-cont (see Function Symbols) and thus mis-indent it. At the top level, a macro invocation before a defun start can cause, for example, c-beginning-of-defun (C-M-a) not to find the correct start of the current function.

You can prevent these by specifying which macros have semicolons. It doesn’t matter whether or not such a macro has a parameter list:

User Option: c-macro-names-with-semicolon

This buffer-local variable specifies which macros have semicolons. After setting its value, you need to call c-make-macro-with-semi-re for it to take effect. It should be set to one of these values:

nil

There are no macros with semicolons.

a list of strings

Each string is the name of a macro with a semicolon. Only valid #define names are allowed here. For example, to set the default value, you could write the following into your .emacs:

(setq c-macro-names-with-semicolon
      '("Q_OBJECT" "Q_PROPERTY" "Q_DECLARE" "Q_ENUMS"))
a regular expression

This matches each symbol which is a macro with a semicolon. It must not match any string which isn’t a valid #define name. For example:

(setq c-macro-names-with-semicolon
      "\\<\\(CLEAN_UP_AND_RETURN\\|Q_[[:upper:]]+\\)\\>")
Function: c-make-macro-with-semi-re

Call this (non-interactive) function, which sets internal variables, each time you change the value of c-macro-names-with-semicolon after the major mode function has run. It takes no arguments, and its return value has no meaning. This function is called by CC Mode’s initialization code, after the mode hooks have run.