diff options
author | Alan Mackenzie <acm@muc.de> | 2023-04-14 16:37:33 +0000 |
---|---|---|
committer | Alan Mackenzie <acm@muc.de> | 2023-04-14 16:37:33 +0000 |
commit | dc842a71ed035dab1115f2e67d35dd07410e18be (patch) | |
tree | 61d9c45eaa61e6e6efd10bf4fd7520aacf397c1d /doc/misc | |
parent | 7974a9349fc59a79b420f54cda9878792e69a239 (diff) | |
download | emacs-dc842a71ed035dab1115f2e67d35dd07410e18be.tar.gz |
Improve C++ concept indentation.
This fixes bug #62386.
* lisp/progmodes/cc-engine.el (c-forward-over-compound-identifier): Don't
move forward over whitespace following the identifier.
(c-forward-primary-expression): Add parameter stop-at-end meaning don't move
forward over whitespace after the construct when non-nil. Don't recognise a
primary expression when an open brace follows a parenthesized expression.
(c-forward-constraint-clause): Extracted from c-forward-c++-requires-clause.
Add parameter stop-at-end as above.
(c-forward-c++-requires-clause): New stop-at-end parameter as above. Call the
new function c-forward-constraint-clause.
(c-forward-concept-fragment, c-looking-at-concept)
(c-in-requires-or-at-end-of-clause, c-c++-vsemi-p): New functions.
(c-guess-basic-syntax): New CASE 5A.7: "defun" open in a requires expression.
CASE 5F: Close of a non-class declaration level block: Move to earlier in the
function.
CASE 5D: Also check for being in or at end of a constraint.
New CASE 20: A C++ requires sub-clause.
New CASE 16G: The closing brace of a requires clause.
New CASE 17J: First "statement" inside a requires "function".
(c-forward-primary-expression, c-forward-declarator, c-forward-decl-or-cast-1)
(c-looking-at-or-maybe-in-bracelist): Amend the method of detecting end of
symbol "requires" (aka c-fun-name-substitute-key).
* lisp/progmodes/cc-fonts.el (c-get-fontification-context): Amend the method
of detecting end of symbol "requires".
* lisp/progmodes/cc-langs.el (c-at-vsemi-p-fn): Change the C++ entry to
c-c++-vsemi-p.
(c-fun-name-substitute-key): Change to an unadorned regexp.
* lisp/progmodes/cc-vars.el (c-offsets-alist): Add new syntactic symbol
constraint-cont.
* doc/misc/cc-mode.texi (Syntactic Symbols): Add an entry for contraint-cont.
(Constraint Symbols): New node under Syntactic Symbols.
Diffstat (limited to 'doc/misc')
-rw-r--r-- | doc/misc/cc-mode.texi | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/doc/misc/cc-mode.texi b/doc/misc/cc-mode.texi index 3a808619868..71bf3fcee4a 100644 --- a/doc/misc/cc-mode.texi +++ b/doc/misc/cc-mode.texi @@ -330,6 +330,7 @@ Syntactic Symbols * Multiline Macro Symbols:: * Objective-C Method Symbols:: * Java Symbols:: +* Constraint Symbols:: * Statement Block Symbols:: * K&R Symbols:: @@ -4234,6 +4235,9 @@ The first line in a ``topmost'' definition. @ref{Function Symbols}. Topmost definition continuation lines. This is only used in the parts that aren't covered by other symbols such as @code{func-decl-cont} and @code{knr-argdecl}. @ref{Function Symbols}. +@item constraint-cont +Continuation line of a topmost C++20 concept or requires clause. +@ref{Constraint Symbols}. @item annotation-top-cont Topmost definition continuation lines where all previous items are annotations. @ref{Java Symbols}. @@ -4397,6 +4401,7 @@ Java. @ref{Java Symbols}. * Multiline Macro Symbols:: * Objective-C Method Symbols:: * Java Symbols:: +* Constraint Symbols:: * Statement Block Symbols:: * K&R Symbols:: @end menu @@ -5071,6 +5076,39 @@ syntax due to it being a continuation of a variable declaration where preceding the declaration is an annotation. @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! +@node Constraint Symbols +@subsection C++ Constraint Symbols +@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +The C++20 standard introduced the notion of @dfn{concepts} and +@dfn{requirements}, a typical instance of which looks something like +this: + +@example + 1: template <typename T> + 2: requires + 3: requires (T t) @{ + 4: @{ ++t; @} + 5: @} + 6: && std::is_integral<T> + 7: int foo(); +@end example + +@ssindex constraint-cont +Line 1 is assigned the familiar @code{topmost-intro}. Line 2 gets +@code{topmost-intro-cont}, being the keyword which introduces a +@dfn{requires clause}. Lines 3, 6, and 7 are assigned the syntax +@code{constraint-cont}, being continuations of the requires clause +started on line 2. Lines 4 and 5 get the syntaxes +@code{defun-block-intro} and @code{defun-close}, being analyzed as +though part of a function. + +Note that the @code{requires} on Line 3 begins a @dfn{requires +expression}, not a a requires clause, hence its components are not +assigned @code{constraint-cont}. See +@url{https://en.cppreference.com/w/cpp/language/requires}. + +@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! @node Statement Block Symbols @subsection Statement Block Symbols @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |