diff options
| author | Alan Mackenzie | 2017-03-19 17:09:27 +0000 |
|---|---|---|
| committer | Alan Mackenzie | 2017-03-19 17:09:27 +0000 |
| commit | d602785139c57274e835e7b56305d42e72a28b0d (patch) | |
| tree | 061f6897800a770e85a5014fc4f4b8bfcafe85fb | |
| parent | 06a796398646fd1a5e17bc7321e12ae8e061e7f7 (diff) | |
| download | emacs-d602785139c57274e835e7b56305d42e72a28b0d.tar.gz emacs-d602785139c57274e835e7b56305d42e72a28b0d.zip | |
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.
| -rw-r--r-- | doc/misc/cc-mode.texi | 35 | ||||
| -rw-r--r-- | 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 14981c9c58b..a29873b03b3 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. | |||
| 4255 | C++ template argument list continuations. @ref{Class Symbols}. | 4255 | C++ template argument list continuations. @ref{Class Symbols}. |
| 4256 | @item inlambda | 4256 | @item inlambda |
| 4257 | Analogous to @code{inclass} syntactic symbol, but used inside lambda | 4257 | Analogous to @code{inclass} syntactic symbol, but used inside lambda |
| 4258 | (i.e., anonymous) functions. Only used in Pike mode. @ref{Statement | 4258 | (i.e., anonymous) functions. Used in C++ and Pike modes. |
| 4259 | Block Symbols}. | 4259 | @ref{Statement Block Symbols}. |
| 4260 | @item lambda-intro-cont | 4260 | @item lambda-intro-cont |
| 4261 | Lines continuing the header of a lambda function, i.e., between the | 4261 | Lines continuing the header of a lambda function, i.e., between the |
| 4262 | @code{lambda} keyword and the function body. Only used in Pike mode. | 4262 | @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 | |||
| 4993 | indentation. An @code{inexpr-statement} syntactic element doesn't | 4993 | indentation. An @code{inexpr-statement} syntactic element doesn't |
| 4994 | contain an anchor position. | 4994 | contain an anchor position. |
| 4995 | 4995 | ||
| 4996 | C++11's lambda expressions involve a block inside a statement. For | ||
| 4997 | example: | ||
| 4998 | |||
| 4999 | @example | ||
| 5000 | 1: std::for_each(someList.begin(), someList.end(), [&total](int x) @{ | ||
| 5001 | 2: total += x; | ||
| 5002 | 3: @}); | ||
| 5003 | @end example | ||
| 5004 | |||
| 5005 | Here a lambda expressions begins at the open bracket on line 1 and | ||
| 5006 | ends at the closing brace on line 3. Line 2, in addition to the | ||
| 5007 | familiar @code{defun-block-intro} syntactic element, is also prefixed | ||
| 5008 | by an @code{inlambda} element, which is typically used to indent the | ||
| 5009 | entire lambda expression to under the opening bracket. | ||
| 5010 | |||
| 4996 | In Pike code, there are a few other situations where blocks occur inside | 5011 | In Pike code, there are a few other situations where blocks occur inside |
| 4997 | statements, as illustrated here: | 5012 | statements, as illustrated here: |
| 4998 | 5013 | ||
| @@ -7161,6 +7176,22 @@ too, add this to your @code{c-initialization-hook}: | |||
| 7161 | @xref{Getting Started}. This was a very common question. | 7176 | @xref{Getting Started}. This was a very common question. |
| 7162 | 7177 | ||
| 7163 | @item | 7178 | @item |
| 7179 | @emph{How do I stop my C++ lambda expressions being indented way over | ||
| 7180 | to the right?} | ||
| 7181 | |||
| 7182 | Change the offset associated with @code{inlambda} from its default, | ||
| 7183 | the function @code{c-lineup-inexpr-block}, to 0. For example, if you | ||
| 7184 | are setting offsets in a hook function you might include the following | ||
| 7185 | line: | ||
| 7186 | |||
| 7187 | @example | ||
| 7188 | (c-set-offset 'inlambda 0) | ||
| 7189 | @end example | ||
| 7190 | |||
| 7191 | For details of the different ways you can make this setting, | ||
| 7192 | @ref{Config Basics}. | ||
| 7193 | |||
| 7194 | @item | ||
| 7164 | @emph{How do I stop my code jumping all over the place when I type?} | 7195 | @emph{How do I stop my code jumping all over the place when I type?} |
| 7165 | 7196 | ||
| 7166 | Deactivate ``electric minor mode'' with @kbd{C-c C-l}. @xref{Getting | 7197 | 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 a5ade09791a..bdc77dc5028 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." | |||
| 10661 | (progn | 10661 | (progn |
| 10662 | (c-backward-token-2 1 nil lim) | 10662 | (c-backward-token-2 1 nil lim) |
| 10663 | (and | 10663 | (and |
| 10664 | (not (c-on-identifier)) | 10664 | (not (and (c-on-identifier) |
| 10665 | (looking-at c-symbol-chars))) | ||
| 10665 | (not (looking-at c-opt-op-identifier-prefix))))))) | 10666 | (not (looking-at c-opt-op-identifier-prefix))))))) |
| 10666 | (cons 'inlambda bracket-pos)) | 10667 | (cons 'inlambda bracket-pos)) |
| 10667 | ((and c-recognize-paren-inexpr-blocks | 10668 | ((and c-recognize-paren-inexpr-blocks |