emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] master d602785: Fix chaotic indentation of C++ lambda. Enh


From: Alan Mackenzie
Subject: [Emacs-diffs] master d602785: Fix chaotic indentation of C++ lambda. Enhance documentation thereof
Date: Sun, 19 Mar 2017 13:13:51 -0400 (EDT)

branch: master
commit d602785139c57274e835e7b56305d42e72a28b0d
Author: Alan Mackenzie <address@hidden>
Commit: Alan Mackenzie <address@hidden>

    Fix chaotic indentation of C++ lambda.  Enhance documentation thereof
    
    * lisp/progmodes/cc-engine.el (c-looking-at-inexpr-block): qualify an
    invocation of c-on-identifier with a check we're not at the _end_ of an
    identifier.
    
    * doc/misc/cc-mode.texi: (Tex title page): Remove @subtitlefont because the
    perl versions of texi2dvi haven't implemented it.
    (Syntactic Symbols): Note that `inlambda' is also used in C++ Mode, not just
    in Pike Mode.
    (Statement Block Symbols): Add a section illustrating a C++ lambda function.
    (FAQ): Add a question about "excessive" indentation of the contents of a C++
    lambda function, and how to get rid of it.
---
 doc/misc/cc-mode.texi       | 35 +++++++++++++++++++++++++++++++++--
 lisp/progmodes/cc-engine.el |  3 ++-
 2 files changed, 35 insertions(+), 3 deletions(-)

diff --git a/doc/misc/cc-mode.texi b/doc/misc/cc-mode.texi
index 14981c9..a29873b 100644
--- a/doc/misc/cc-mode.texi
+++ b/doc/misc/cc-mode.texi
@@ -4255,8 +4255,8 @@ Analogous to the above, but for CORBA CIDL 
@code{composition} blocks.
 C++ template argument list continuations.  @ref{Class Symbols}.
 @item inlambda
 Analogous to @code{inclass} syntactic symbol, but used inside lambda
-(i.e., anonymous) functions.  Only used in Pike mode.  @ref{Statement
-Block Symbols}.
+(i.e., anonymous) functions.  Used in C++ and Pike modes.
address@hidden Block Symbols}.
 @item lambda-intro-cont
 Lines continuing the header of a lambda function, i.e., between the
 @code{lambda} keyword and the function body.  Only used in Pike mode.
@@ -4993,6 +4993,21 @@ symbols they'd get in a normal block.  Therefore, the 
indentation put on
 indentation.  An @code{inexpr-statement} syntactic element doesn't
 contain an anchor position.
 
+C++11's lambda expressions involve a block inside a statement.  For
+example:
+
address@hidden
+ 1:  std::for_each(someList.begin(), someList.end(), [&total](int x) @{
+ 2:                                                     total += x;
+ 3:                                                 @});
address@hidden example
+
+Here a lambda expressions begins at the open bracket on line 1 and
+ends at the closing brace on line 3.  Line 2, in addition to the
+familiar @code{defun-block-intro} syntactic element, is also prefixed
+by an @code{inlambda} element, which is typically used to indent the
+entire lambda expression to under the opening bracket.
+
 In Pike code, there are a few other situations where blocks occur inside
 statements, as illustrated here:
 
@@ -7161,6 +7176,22 @@ too, add this to your @code{c-initialization-hook}:
 @xref{Getting Started}.  This was a very common question.
 
 @item
address@hidden do I stop my C++ lambda expressions being indented way over
+to the right?}
+
+Change the offset associated with @code{inlambda} from its default,
+the function @code{c-lineup-inexpr-block}, to 0.  For example, if you
+are setting offsets in a hook function you might include the following
+line:
+
address@hidden
+(c-set-offset 'inlambda 0)
address@hidden example
+
+For details of the different ways you can make this setting,
address@hidden Basics}.
+
address@hidden
 @emph{How do I stop my code jumping all over the place when I type?}
 
 Deactivate ``electric minor mode'' with @kbd{C-c C-l}.  @xref{Getting
diff --git a/lisp/progmodes/cc-engine.el b/lisp/progmodes/cc-engine.el
index a5ade09..bdc77dc 100644
--- a/lisp/progmodes/cc-engine.el
+++ b/lisp/progmodes/cc-engine.el
@@ -10661,7 +10661,8 @@ comment at the start of cc-engine.el for more info."
                       (progn
                         (c-backward-token-2 1 nil lim)
                         (and
-                         (not (c-on-identifier))
+                         (not (and (c-on-identifier)
+                                   (looking-at c-symbol-chars)))
                          (not (looking-at c-opt-op-identifier-prefix)))))))
            (cons 'inlambda bracket-pos))
           ((and c-recognize-paren-inexpr-blocks



reply via email to

[Prev in Thread] Current Thread [Next in Thread]