aboutsummaryrefslogtreecommitdiffstats
path: root/doc
diff options
context:
space:
mode:
authorAlan Mackenzie2011-10-27 20:34:23 +0000
committerAlan Mackenzie2011-10-27 20:34:23 +0000
commit536610a433e6edc0b3f831272c4e0424ebebee46 (patch)
treefcb6f43d840d6fd67d20b64ba4e510ddee34ae45 /doc
parent86c606818495d9411fd5d6b1477f9a097eb18020 (diff)
downloademacs-536610a433e6edc0b3f831272c4e0424ebebee46.tar.gz
emacs-536610a433e6edc0b3f831272c4e0424ebebee46.zip
Amend to indent and fontify macros "which include their own semicolon"
correctly, using the "virtual semicolon" mechanism. cc-defs.el: Update "virtual semicolon" comments. cc-engine.el (c-crosses-statement-barrier-p): Recoded to scan one line at at time rather than having \n and \r explicitly in c-stmt-delim-chars (for some modes, e.g. AWK). (c-forward-label): Amend for virtual semicolons. (c-at-macro-vsemi-p, c-macro-vsemi-status-unknown-p): New functions cc-fonts.el (c-font-lock-declarations): Take account of the new C macros. cc-langs.el (c-at-vsemi-p-fn, c-vsemi-status-unknown-p-fn): move to earlier in the file. (c-opt-cpp-symbol, c-line-comment-start-regexp): New language variables. (c-opt-cpp-macro-define): Make into a full language variable. (c-stmt-delim-chars, c-stmt-delim-chars-with-comma): Special value for AWK Mode (including \n, \r) removed, no longer needed. cc-mode.el (c-mode, c++-mode, objc-mode): Invoke c-make-macro-with-semi-re. cc-vars.el (c-macro-with-semi-re, c-macro-names-with-semicolon): New variables. (c-make-macro-with-semi-re): New function cc-mode.texi (Indentation Commands): Mention "macros with semicolons". (Other Special Indentations): Add an xref to "Macros with ;". (Customizing Macros): Add stuff about syntax in macros. Add an xref to "Macros with ;". (Macros with ;): New page.
Diffstat (limited to 'doc')
-rw-r--r--doc/misc/cc-mode.texi97
1 files changed, 97 insertions, 0 deletions
diff --git a/doc/misc/cc-mode.texi b/doc/misc/cc-mode.texi
index a9339162666..4cc7f351c2e 100644
--- a/doc/misc/cc-mode.texi
+++ b/doc/misc/cc-mode.texi
@@ -341,6 +341,11 @@ Line-Up Functions
341* Comment Line-Up:: 341* Comment Line-Up::
342* Misc Line-Up:: 342* Misc Line-Up::
343 343
344Customizing Macros
345
346* Macro Backslashes::
347* Macros with ;::
348
344@end detailmenu 349@end detailmenu
345@end menu 350@end menu
346 351
@@ -655,6 +660,10 @@ expression, to some statements, or perhaps to whole functions, the
655syntactic recognition can be wrong. @ccmode{} manages to figure it 660syntactic recognition can be wrong. @ccmode{} manages to figure it
656out correctly most of the time, though. 661out correctly most of the time, though.
657 662
663Some macros, when invoked, ''have their own semicolon''. To get the
664next line indented correctly, rather than as a continuation line,
665@xref{Macros with ;}.
666
658Reindenting large sections of code can take a long time. When 667Reindenting large sections of code can take a long time. When
659@ccmode{} reindents a region of code, it is essentially equivalent to 668@ccmode{} reindents a region of code, it is essentially equivalent to
660hitting @key{TAB} on every line of the region. 669hitting @key{TAB} on every line of the region.
@@ -6550,6 +6559,9 @@ custom line-up function associated with it.
6550@section Other Special Indentations 6559@section Other Special Indentations
6551@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 6560@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
6552 6561
6562To configure macros which you invoke without a terminating @samp{;},
6563see @xref{Macros with ;}.
6564
6553Here are the remaining odds and ends regarding indentation: 6565Here are the remaining odds and ends regarding indentation:
6554 6566
6555@defopt c-label-minimum-indentation 6567@defopt c-label-minimum-indentation
@@ -6601,6 +6613,13 @@ functions to this hook, not remove them. @xref{Style Variables}.
6601@cindex preprocessor directives 6613@cindex preprocessor directives
6602@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 6614@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
6603 6615
6616Preprocessor macros in C, C++, and Objective C (introduced by
6617@code{#define}) have a syntax different from the main language---for
6618example, a macro declaration is not terminated by a semicolon, and if
6619it is more than a line long, line breaks in it must be escaped with
6620backslashes. @ccmode{} has some commands to manipulate these, see
6621@ref{Macro Backslashes}.
6622
6604Normally, the lines in a multi-line macro are indented relative to 6623Normally, the lines in a multi-line macro are indented relative to
6605each other as though they were code. You can suppress this behavior 6624each other as though they were code. You can suppress this behavior
6606by setting the following user option: 6625by setting the following user option:
@@ -6612,6 +6631,28 @@ is @code{nil}, all lines inside macro definitions are analyzed as
6612@code{cpp-macro-cont}. 6631@code{cpp-macro-cont}.
6613@end defopt 6632@end defopt
6614 6633
6634Because a macro can expand into anything at all, near where one is
6635invoked @ccmode{} can only indent and fontify code heuristically.
6636Sometimes it gets it wrong. Usually you should try to design your
6637macros so that they ''look like ordinary code'' when you invoke them.
6638However, one situation is so common that @ccmode{} handles it
6639specially: that is when certain macros needn't (or mustn't) be
6640followed by a @samp{;}. You need to configure @ccmode{} to handle
6641these macros properly, see @ref{Macros with ;}.
6642
6643@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
6644@menu
6645* Macro Backslashes::
6646* Macros with ;::
6647@end menu
6648
6649@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
6650@node Macro Backslashes, Macros with ;, Custom Macros, Custom Macros
6651@comment node-name, next, previous, up
6652@section Customizing Macro Backslashes
6653@cindex #define
6654@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
6655
6615@ccmode{} provides some tools to help keep the line continuation 6656@ccmode{} provides some tools to help keep the line continuation
6616backslashes in macros neat and tidy. Their precise action is 6657backslashes in macros neat and tidy. Their precise action is
6617customized with these variables: 6658customized with these variables:
@@ -6654,6 +6695,62 @@ get aligned only when you explicitly invoke the command
6654@end defopt 6695@end defopt
6655 6696
6656@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 6697@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
6698@node Macros with ;, , Macro Backslashes, Custom Macros
6699@comment node-name, next, previous, up
6700@section Macros with semicolons
6701@cindex macros with semicolons
6702@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
6703Macros which needn't (or mustn't) be followed by a semicolon when you
6704invoke them, @dfn{macros with semicolons}, are very common. These can
6705cause @ccmode{} to parse the next line wrongly as a
6706@code{statement-cont} (@pxref{Function Symbols}) and thus mis-indent
6707it.
6708
6709You can prevent this by specifying which macros have semicolons. It
6710doesn't matter whether or not such a macro has a parameter list:
6711
6712@defopt c-macro-names-with-semicolon
6713@vindex macro-names-with-semicolon (c-)
6714This buffer-local variable specifies which macros have semicolons.
6715After setting its value, you need to call
6716@code{c-make-macro-with-semi-re} for it to take effect. It should be
6717set to one of these values:
6718
6719@table @asis
6720@item nil
6721There are no macros with semicolons.
6722@item a list of strings
6723Each string is the name of a macro with a semicolon. Only valid
6724@code{#define} names are allowed here. For example, to set the
6725default value, you could write the following into your @file{.emacs}:
6726
6727@example
6728(setq c-macro-names-with-semicolon
6729 '("Q_OBJECT" "Q_PROPERTY" "Q_DECLARE" "Q_ENUMS"))
6730@end example
6731
6732@item a regular expression
6733This matches each symbol which is a macro with a semicolon. It must
6734not match any string which isn't a valid @code{#define} name. For
6735example:
6736
6737@example
6738(setq c-macro-names-with-semicolon
6739 "\\<\\(CLEAN_UP_AND_RETURN\\|Q_[[:upper:]]+\\)\\>")
6740@end example
6741@end table
6742@end defopt
6743
6744@defun c-make-macro-with-semi-re
6745@findex make-macro-with-semi-re (c-)
6746Call this (non-interactive) function, which sets internal variables,
6747each time you change the value of
6748@code{c-macro-names-with-semicolon}. It takes no arguments, and its
6749return value has no meaning. This function is called by @ccmode{}'s
6750initialization code.
6751@end defun
6752
6753@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
6657@node Odds and Ends, Sample .emacs File, Custom Macros, Top 6754@node Odds and Ends, Sample .emacs File, Custom Macros, Top
6658@comment node-name, next, previous, up 6755@comment node-name, next, previous, up
6659@chapter Odds and Ends 6756@chapter Odds and Ends