1 To: vim_dev@googlegroups.com
4 From: Bram Moolenaar <Bram@moolenaar.net>
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
11 Problem: Cannot influence the indent inside a namespace.
12 Solution: Add the "N" 'cino' parameter. (Konstantin Lepa)
13 Files: runtime/doc/indent.txt, src/misc1.c, src/testdir/test3.in,
17 *** ../mercurial/vim73/runtime/doc/indent.txt 2011-04-28 19:01:26.000000000 +0200
18 --- runtime/doc/indent.txt 2011-05-25 14:35:37.000000000 +0200
21 used CTRL-T or CTRL-D.
24 ! The 'cinoptions' option sets how Vim performs indentation. In the list below,
25 "N" represents a number of your choice (the number can be negative). When
26 there is an 's' after the number, Vim multiplies the number by 'shiftwidth':
27 "1s" is 'shiftwidth', "2s" is two times 'shiftwidth', etc. You can use a
28 ! decimal point, too: "-0.5s" is minus half a 'shiftwidth'. The examples below
29 ! assume a 'shiftwidth' of 4.
31 >N Amount added for "normal" indent. Used after a line that should
32 increase the indent (lines starting with "if", an opening brace,
33 etc.). (default 'shiftwidth').
35 used CTRL-T or CTRL-D.
38 ! The 'cinoptions' option sets how Vim performs indentation. The value after
39 ! the option character can be one of these (N is any number):
41 ! -N indent N spaces to the left
42 ! Ns N times 'shiftwidth spaces
43 ! -Ns N times 'shiftwidth spaces to the left
46 "N" represents a number of your choice (the number can be negative). When
47 there is an 's' after the number, Vim multiplies the number by 'shiftwidth':
48 "1s" is 'shiftwidth', "2s" is two times 'shiftwidth', etc. You can use a
49 ! decimal point, too: "-0.5s" is minus half a 'shiftwidth'.
50 ! The examples below assume a 'shiftwidth' of 4.
52 >N Amount added for "normal" indent. Used after a line that should
53 increase the indent (lines starting with "if", an opening brace,
54 etc.). (default 'shiftwidth').
62 eN Add N to the prevailing indent inside a set of braces if the
63 opening brace at the End of the line (more precise: is not the
64 first character in a line). This is useful if you want a
72 nN Add N to the prevailing indent for a statement after an "if",
73 "while", etc., if it is NOT inside a set of braces. This is
74 useful if you want a different indent when there is no '{'
82 fN Place the first opening brace of a function or other block in
83 column N. This applies only for an opening brace that is not
84 inside other braces and is at the start of the line. What comes
89 int foo; int foo; int foo;
92 {N Place opening braces N characters from the prevailing indent.
93 This applies only for opening braces that are inside other
102 }N Place closing braces N characters from the matching opening
112 ^N Add N to the prevailing indent inside a set of braces if the
113 opening brace is in column 0. This can specify a different
114 indent for whole of a function (some may like to set it to a
122 LN Controls placement of jump labels. If N is negative, the label
123 will be placed at column 1. If N is non-negative, the indent of
124 the label will be the prevailing indent minus N. (default -1).
132 :N Place case labels N characters from the indent of the switch().
133 (default 'shiftwidth').
142 =N Place statements occurring after a case label N characters from
143 the indent of the label. (default 'shiftwidth').
148 case 11: case 11: a = a + 1;
149 a = a + 1; b = b + 1;
152 lN If N != 0 Vim will align with a case label instead of the
153 statement after it in the same line.
162 bN If N != 0 Vim will align a final "break" with the case label,
163 so that case..break looks like a sort of block. (default: 0).
164 When using 1, consider adding "0=break" to 'cinkeys'.
172 gN Place C++ scope declarations N characters from the indent of the
173 block they are in. (default 'shiftwidth'). A scope declaration
174 can be "public:", "protected:" or "private:".
182 hN Place statements occurring after a C++ scope declaration N
183 characters from the indent of the label. (default
188 public: public: a = a + 1;
189 a = a + 1; b = b + 1;
192 + NN Indent inside C++ namespace N characters extra compared to a
193 + normal block. (default 0).
196 + namespace { namespace {
197 + void function(); void function();
200 + namespace my namespace my
202 + void function(); void function();
206 pN Parameter declarations for K&R-style function declarations will
207 be indented N characters from the margin. (default
213 char b; char b; char b;
216 tN Indent a function return type declaration N characters from the
217 margin. (default 'shiftwidth').
226 iN Indent C++ base class declarations and constructor
227 initializations, if they start in a new line (otherwise they
228 are aligned at the right side of the ':').
232 a = b + 9 * a = b + 9 *
236 cN Indent comment lines after the comment opener, when there is no
237 other text with which to align, N characters from the comment
238 opener. (default 3). See also |format-comments|.
246 CN When N is non-zero, indent comment lines by the amount specified
247 with the c flag above even if there is other text behind the
248 comment opener. (default 0).
253 < (Example uses ":set comments& comments-=s1:/* comments^=s0:/*")
256 /N Indent comment lines N characters extra. (default 0).
259 /* comment */ /* comment */
263 (N When in unclosed parentheses, indent N characters from the line
264 with the unclosed parentheses. Add a 'shiftwidth' for every
265 unclosed parentheses. When N is 0 or the unclosed parentheses
269 (c2 || c3)) (c2 || c3))
273 uN Same as (N, but for one level deeper. (default 'shiftwidth').
279 && (c22345 && (c22345
283 UN When N is non-zero, do not ignore the indenting specified by
284 ( or u in case that the unclosed parentheses is the first
285 non-white character in its line. (default 0).
293 wN When in unclosed parentheses and N is non-zero and either
294 using "(0" or "u0", respectively, or using "U0" and the unclosed
295 parentheses is the first non-white character in its line, line
303 WN When in unclosed parentheses and N is non-zero and either
304 using "(0" or "u0", respectively and the unclosed parentheses is
305 the last non-white character in its line and it is not the
309 a_short_line(argument, a_short_line(argument,
310 argument); argument);
313 mN When N is non-zero, line up a line starting with a closing
314 parentheses with the first character of the line with the
315 matching opening parentheses. (default 0).
323 MN When N is non-zero, line up a line starting with a closing
324 parentheses with the first character of the previous line.
331 ! *java-cinoptions* *java-indenting*
332 jN Indent java anonymous classes correctly. The value 'N' is
333 currently unused but must be non-zero (e.g. 'j1'). 'j1' will
334 indent for example the following code snippet correctly: >
339 ! *java-cinoptions* *java-indenting* *cino-j*
340 jN Indent java anonymous classes correctly. The value 'N' is
341 currently unused but must be non-zero (e.g. 'j1'). 'j1' will
342 indent for example the following code snippet correctly: >
348 ! *javascript-cinoptions* *javascript-indenting*
349 JN Indent JavaScript object declarations correctly by not confusing
350 them with labels. The value 'N' is currently unused but must be
351 non-zero (e.g. 'J1'). >
356 ! *javascript-cinoptions* *javascript-indenting* *cino-J*
357 JN Indent JavaScript object declarations correctly by not confusing
358 them with labels. The value 'N' is currently unused but must be
359 non-zero (e.g. 'J1'). >
364 The defaults, spelled out in full, are:
365 ! cinoptions=>s,e0,n0,f0,{0,}0,^0,L-1,:s,=s,l0,b0,gs,hs,ps,ts,is,+s,
366 c3,C0,/0,(2s,us,U0,w0,W0,m0,j0,J0,)20,*70,#0
368 Vim puts a line in column 1 if:
372 The defaults, spelled out in full, are:
373 ! cinoptions=>s,e0,n0,f0,{0,}0,^0,L-1,:s,=s,l0,b0,gs,hs,N0,ps,ts,is,+s,
374 c3,C0,/0,(2s,us,U0,w0,W0,m0,j0,J0,)20,*70,#0
376 Vim puts a line in column 1 if:
377 *** ../mercurial/vim73/src/misc1.c 2011-05-25 13:33:59.000000000 +0200
378 --- src/misc1.c 2011-05-25 14:57:31.000000000 +0200
382 static int corr_ind_maxparen __ARGS((int ind_maxparen, pos_T *startpos));
383 static int find_last_paren __ARGS((char_u *l, int start, int end));
384 static int find_match __ARGS((int lookfor, linenr_T ourscope, int ind_maxparen, int ind_maxcomment));
385 + static int cin_is_cpp_namespace __ARGS((char_u *));
387 static int ind_hash_comment = 0; /* # starts a comment */
392 return (*(s = cin_skipcomment(s + i)) == ':' && s[1] != ':');
395 + /* Maximum number of lines to search back for a "namespace" line. */
396 + #define FIND_NAMESPACE_LIM 20
399 + * Recognize a "namespace" scope declaration.
402 + cin_is_cpp_namespace(s)
406 + int has_name = FALSE;
408 + s = cin_skipcomment(s);
409 + if (STRNCMP(s, "namespace", 9) == 0 && (s[9] == NUL || !vim_iswordc(s[9])))
411 + p = cin_skipcomment(skipwhite(s + 9));
414 + if (vim_iswhite(*p))
416 + has_name = TRUE; /* found end of a name */
417 + p = cin_skipcomment(skipwhite(p));
419 + else if (*p == '{')
423 + else if (vim_iswordc(*p))
426 + return FALSE; /* word character after skipping past name */
440 * Return a pointer to the first non-empty non-comment character after a ':'.
441 * Return NULL if not found.
446 int ind_keep_case_label = 0;
449 + * handle C++ namespace
451 + int ind_cpp_namespace = 0;
462 + int lookfor_cpp_namespace = FALSE;
463 int cont_amount = 0; /* amount for continuation line */
464 int original_line_islabel;
469 case 'J': ind_js = n; break;
470 case 'l': ind_keep_case_label = n; break;
471 case '#': ind_hash_comment = n; break;
472 + case 'N': ind_cpp_namespace = n; break;
479 if (start_brace == BRACE_IN_COL0) /* '{' is in column 0 */
481 amount = ind_open_left_imag;
482 + lookfor_cpp_namespace = TRUE;
484 + else if (start_brace == BRACE_AT_START &&
485 + lookfor_cpp_namespace) /* '{' is at start */
488 + lookfor_cpp_namespace = TRUE;
492 if (start_brace == BRACE_AT_END) /* '{' is at end of line */
494 amount += ind_open_imag;
496 + l = skipwhite(ml_get_curline());
497 + if (cin_is_cpp_namespace(l))
498 + amount += ind_cpp_namespace;
502 /* Compensate for adding ind_open_extra later. */
507 amount += ind_continuation;
509 + else if (lookfor_cpp_namespace)
511 + if (curwin->w_cursor.lnum == ourscope)
514 + if (curwin->w_cursor.lnum == 0
515 + || curwin->w_cursor.lnum
516 + < ourscope - FIND_NAMESPACE_LIM)
519 + l = ml_get_curline();
522 + * If we're in a comment now, skip to the start of the
525 + trypos = find_start_comment(ind_maxcomment);
526 + if (trypos != NULL)
528 + curwin->w_cursor.lnum = trypos->lnum + 1;
529 + curwin->w_cursor.col = 0;
534 + * Skip preprocessor directives and blank lines.
536 + if (cin_ispreproc_cont(&l, &curwin->w_cursor.lnum))
539 + if (cin_is_cpp_namespace(l))
541 + amount += ind_cpp_namespace;
549 else if (lookfor != LOOKFOR_TERM
550 && lookfor != LOOKFOR_CPP_BASECLASS)
552 *** ../mercurial/vim73/src/testdir/test3.in 2011-05-25 13:33:59.000000000 +0200
553 --- src/testdir/test3.in 2011-05-25 14:47:31.000000000 +0200
561 + /* valid namespaces with normal indent */
568 + namespace /* test */
574 + 111111111111111111;
578 + 111111111111111111;
582 + 111111111111111111;
585 + 111111111111111111;
588 + 111111111111111111;
591 + 111111111111111111;
594 + 111111111111111111;
600 + /* invalid namespaces use block indent */
601 + namespace test test2 {
602 + 111111111111111111111;
604 + namespace11111111111 {
612 + 111111111111111111;
614 + namespace test test2
616 + 1111111111111111111;
620 + 111111111111111111;
637 + /* valid namespaces with normal indent */
644 + namespace /* test */
650 + 111111111111111111;
654 + 111111111111111111;
658 + 111111111111111111;
661 + 111111111111111111;
664 + 111111111111111111;
667 + 111111111111111111;
670 + 111111111111111111;
676 + /* invalid namespaces use block indent */
677 + namespace test test2 {
678 + 111111111111111111111;
680 + namespace11111111111 {
688 + 111111111111111111;
690 + namespace test test2
692 + 1111111111111111111;
696 + 111111111111111111;
702 :g/^STARTTEST/.,/^ENDTEST/d
703 :1;/start of AUTO/,$wq! test.out
705 *** ../mercurial/vim73/src/testdir/test3.ok 2011-05-25 13:33:59.000000000 +0200
706 --- src/testdir/test3.ok 2011-05-25 14:48:02.000000000 +0200
714 + /* valid namespaces with normal indent */
721 + namespace /* test */
727 + 111111111111111111;
731 + 111111111111111111;
735 + 111111111111111111;
738 + 111111111111111111;
741 + 111111111111111111;
744 + 111111111111111111;
747 + 111111111111111111;
753 + /* invalid namespaces use block indent */
754 + namespace test test2 {
755 + 111111111111111111111;
757 + namespace11111111111 {
765 + 111111111111111111;
767 + namespace test test2
769 + 1111111111111111111;
773 + 111111111111111111;
786 + /* valid namespaces with normal indent */
793 + namespace /* test */
799 + 111111111111111111;
803 + 111111111111111111;
807 + 111111111111111111;
810 + 111111111111111111;
813 + 111111111111111111;
816 + 111111111111111111;
819 + 111111111111111111;
825 + /* invalid namespaces use block indent */
826 + namespace test test2 {
827 + 111111111111111111111;
829 + namespace11111111111 {
837 + 111111111111111111;
839 + namespace test test2
841 + 1111111111111111111;
845 + 111111111111111111;
850 *** ../vim-7.3.201/src/version.c 2011-05-25 13:33:59.000000000 +0200
851 --- src/version.c 2011-05-25 15:14:20.000000000 +0200
855 { /* Add new patch number below this line */
861 hundred-and-one symptoms of being an internet addict:
862 107. When using your phone you forget that you don't have to use your
865 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\
866 /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
867 \\\ an exciting new programming language -- http://www.Zimbu.org ///
868 \\\ help me help AIDS victims -- http://ICCF-Holland.org ///