blob: e75de0ffa336eaa241e89d65662b54a25c50e226 [file] [log] [blame]
Bram Moolenaar9e54a0e2006-04-14 20:42:25 +00001/* start of AUTO matically checked vim: set ts=4 : */
Bram Moolenaar071d4272004-06-13 20:20:40 +00002{
3 if (test)
4 cmd1;
5 cmd2;
6}
7
8{
9 if (test)
10 cmd1;
11 else
12 cmd2;
13}
14
15{
16 if (test)
17 {
18 cmd1;
19 cmd2;
20 }
21}
22
23{
24 if (test)
25 {
26 cmd1;
27 else
28 }
29}
30
31{
32 while (this)
33 if (test)
34 cmd1;
35 cmd2;
36}
37
38{
39 while (this)
40 if (test)
41 cmd1;
42 else
43 cmd2;
44}
45
46{
47 if (test)
48 {
49 cmd;
50 }
51
52 if (test)
53 cmd;
54}
55
56{
57 if (test) {
58 cmd;
59 }
60
61 if (test) cmd;
62}
63
64{
65 cmd1;
66 for (blah)
67 while (this)
68 if (test)
69 cmd2;
70 cmd3;
71}
72
73{
74 cmd1;
75 for (blah)
76 while (this)
77 if (test)
78 cmd2;
79 cmd3;
80
81 if (test)
82 {
83 cmd1;
84 cmd2;
85 cmd3;
86 }
87}
88
89
90/* Test for 'cindent' do/while mixed with if/else: */
91
92{
93 do
94 if (asdf)
95 asdfasd;
96 while (cond);
97
98 do
99 if (asdf)
100 while (asdf)
101 asdf;
102 while (asdf);
103}
104
105/* Test for 'cindent' with two ) on a continuation line */
106{
107 if (asdfasdf;asldkfj asdlkfj as;ldkfj sal;d
108 aal;sdkjf ( ;asldfkja;sldfk
109 al;sdjfka ;slkdf ) sa;ldkjfsa dlk;)
110 line up here;
111}
112
113
114/* C++ tests: */
115
116// foo() these three lines should remain in column 0
117// {
118// }
119
120/* Test for continuation and unterminated lines: */
121{
122 i = 99 + 14325 +
123 21345 +
124 21345 +
125 21345 + ( 21345 +
126 21345) +
127 2345 +
128 1234;
129 c = 1;
130}
131
132/*
133 testje for indent with empty line
134
135 here */
136
137{
138 if (testing &&
139 not a joke ||
140 line up here)
141 hay;
142 if (testing &&
143 (not a joke || testing
144 )line up here)
145 hay;
146 if (testing &&
147 (not a joke || testing
148 line up here))
149 hay;
150}
151
152
153{
154 switch (c)
155 {
156 case xx:
157 do
158 if (asdf)
159 do
160 asdfasdf;
161 while (asdf);
162 else
163 asdfasdf;
164 while (cond);
165 case yy:
166 case xx:
167 case zz:
168 testing;
169 }
170}
171
172{
173 if (cond) {
174 foo;
175 }
176 else
177 {
178 bar;
179 }
180}
181
182{
183 if (alskdfj ;alsdkfjal;skdjf (;sadlkfsa ;dlkf j;alksdfj ;alskdjf
184 alsdkfj (asldk;fj
185 awith cino=(0 ;lf this one goes to below the paren with ==
186 ;laksjfd ;lsakdjf ;alskdf asd)
187 asdfasdf;)))
188 asdfasdf;
189}
190
191 int
192func(a, b)
193 int a;
194 int c;
195{
196 if (c1 && (c2 ||
197 c3))
198 foo;
199 if (c1 &&
200 (c2 || c3)
201 )
202}
203
204{
205 while (asd)
206 {
207 if (asdf)
208 if (test)
209 if (that)
210 {
211 if (asdf)
212 do
213 cdasd;
214 while (as
215 df);
216 }
217 else
218 if (asdf)
219 asdf;
220 else
221 asdf;
222 asdf;
223 }
224}
225
226{
227 s = "/*"; b = ';'
228 s = "/*"; b = ';';
229 a = b;
230}
231
232{
233 switch (a)
234 {
235 case a:
236 switch (t)
237 {
238 case 1:
239 cmd;
240 break;
241 case 2:
242 cmd;
243 break;
244 }
245 cmd;
246 break;
247 case b:
248 {
249 int i;
250 cmd;
251 }
252 break;
253 case c: {
254 int i;
255 cmd;
256 }
257 case d: if (cond &&
258 test) { /* this line doesn't work right */
259 int i;
260 cmd;
261 }
262 break;
263 }
264}
265
266{
267 if (!(vim_strchr(p_cpo, CPO_BUFOPTGLOB) != NULL && entering) &&
268 (bp_to->b_p_initialized ||
269 (!entering && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
270 return;
271label :
272 asdf = asdf ?
273 asdf : asdf;
274 asdf = asdf ?
275 asdf: asdf;
276}
277
278/* Special Comments : This function has the added complexity (compared */
279/* : to addtolist) of having to check for a detail */
280/* : texture and add that to the list first. */
281
282char *(array[100]) = {
283 "testje",
284 "foo",
285 "bar",
286}
287
288enum soppie
289{
290 yes = 0,
291 no,
292 maybe
293};
294
295typedef enum soppie
296{
297 yes = 0,
298 no,
299 maybe
300};
301
Bram Moolenaara5285652011-12-14 20:05:21 +0100302static enum
303{
304 yes = 0,
305 no,
306 maybe
307} soppie;
308
Bram Moolenaard999db22013-03-07 13:21:32 +0100309public static enum
310{
311 yes = 0,
312 no,
313 maybe
314} soppie;
315
316static private enum
317{
318 yes = 0,
319 no,
320 maybe
321} soppie;
322
Bram Moolenaar071d4272004-06-13 20:20:40 +0000323{
324 int a,
325 b;
326}
327
328{
329 struct Type
330 {
331 int i;
332 char *str;
333 } var[] =
334 {
335 0, "zero",
336 1, "one",
337 2, "two",
338 3, "three"
339 };
340
341 float matrix[3][3] =
342 {
343 {
344 0,
345 1,
346 2
347 },
348 {
349 3,
350 4,
351 5
352 },
353 {
354 6,
355 7,
356 8
357 }
358 };
359}
360
361{
362 /* blah ( blah */
363 /* where does this go? */
364
365 /* blah ( blah */
366 cmd;
367
368 func(arg1,
369 /* comment */
370 arg2);
371 a;
372 {
373 b;
374 {
375 c; /* Hey, NOW it indents?! */
376 }
377 }
378
379 {
380 func(arg1,
381 arg2,
382 arg3);
383 /* Hey, what am I doing here? Is this coz of the ","? */
384 }
385}
386
387main ()
388{
389 if (cond)
390 {
391 a = b;
392 }
393 if (cond) {
394 a = c;
395 }
396 if (cond)
397 a = d;
398 return;
399}
400
401{
402 case 2: if (asdf &&
403 asdfasdf)
404 aasdf;
405 a = 9;
406 case 3: if (asdf)
407 aasdf;
408 a = 9;
409 case 4: x = 1;
410 y = 2;
411
412label: if (asdf)
413 here;
414
415label: if (asdf &&
416 asdfasdf)
417 {
418 }
419
420label: if (asdf &&
421 asdfasdf) {
422 there;
423 }
424
425label: if (asdf &&
426 asdfasdf)
427 there;
428}
429
430{
431 /*
432 hello with ":set comments= cino=c5"
433 */
434
435 /*
436 hello with ":set comments= cino="
437 */
438}
439
440
441{
442 if (a < b) {
443 a = a + 1;
444 } else
445 a = a + 2;
446
447 if (a)
448 do {
449 testing;
450 } while (asdfasdf);
451 a = b + 1;
452 asdfasdf
453}
454
Bram Moolenaar04d17ae2014-08-06 17:44:14 +0200455{
456 for ( int i = 0;
457 i < 10; i++ )
458 {
459 }
460 i = 0;
461}
462
Bram Moolenaar071d4272004-06-13 20:20:40 +0000463class bob
464{
465 int foo() {return 1;}
466 int bar;
467}
468
469main()
470{
471 while(1)
472 if (foo)
473 {
474 bar;
475 }
476 else {
477 asdf;
478 }
479 misplacedline;
480}
481
482{
483 if (clipboard.state == SELECT_DONE
484 && ((row == clipboard.start.lnum
485 && col >= clipboard.start.col)
486 || row > clipboard.start.lnum))
487}
488
489{
490 if (1) {i += 4;}
491 where_am_i;
492 return 0;
493}
494
495{
496 {
497 } // sdf(asdf
498 if (asdf)
499 asd;
500}
501
502{
503label1:
504label2:
505}
506
507{
508 int fooRet = foo(pBar1, false /*fKB*/,
509 true /*fPTB*/, 3 /*nT*/, false /*fDF*/);
510 f() {
511 for ( i = 0;
512 i < m;
513 /* c */ i++ ) {
514 a = b;
515 }
516 }
517}
518
519{
520 f1(/*comment*/);
521 f2();
522}
523
524{
525 do {
526 if (foo) {
527 } else
528 ;
529 } while (foo);
530 foo(); // was wrong
531}
532
533int x; // no extra indent because of the ;
534void func()
535{
536}
537
538char *tab[] = {"aaa",
539 "};", /* }; */ NULL}
540 int indented;
541{}
542
543char *a[] = {"aaa", "bbb",
544 "ccc", NULL};
545// here
546
547char *tab[] = {"aaa",
548 "xx", /* xx */}; /* asdf */
549int not_indented;
550
551{
552 do {
553 switch (bla)
554 {
555 case 1: if (foo)
556 bar;
557 }
558 } while (boo);
559 wrong;
560}
561
562int foo,
563 bar;
564int foo;
565
566#if defined(foo) \
567 && defined(bar)
568char * xx = "asdf\
569 foo\
570 bor";
571int x;
572
573char *foo = "asdf\
574 asdf\
575 asdf",
576 *bar;
577
578void f()
579{
580#if defined(foo) \
581 && defined(bar)
582 char *foo = "asdf\
583 asdf\
584 asdf",
585 *bar;
586 {
587 int i;
588 char *foo = "asdf\
589 asdf\
590 asdf",
591 *bar;
592 }
593#endif
594}
595#endif
596
597int y; // comment
598// comment
599
600// comment
601
602{
603 Constructor(int a,
604 int b ) : BaseClass(a)
605 {
606 }
607}
608
609void foo()
610{
611 char one,
612 two;
613 struct bla piet,
614 jan;
615 enum foo kees,
616 jannie;
617 static unsigned sdf,
618 krap;
619 unsigned int piet,
620 jan;
621 int
622 kees,
623 jan;
624}
625
626{
627 t(int f,
628 int d); // )
629 d();
630}
631
632Constructor::Constructor(int a,
633 int b
634 ) :
635 BaseClass(a,
636 b,
637 c),
638 mMember(b),
639{
640}
641
642Constructor::Constructor(int a,
643 int b ) :
644 BaseClass(a)
645{
646}
647
648Constructor::Constructor(int a,
649 int b ) /*x*/ : /*x*/ BaseClass(a),
Bram Moolenaar7fc904b2006-04-13 20:37:35 +0000650 member(b)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000651{
652}
653
654class CAbc :
655 public BaseClass1,
656 protected BaseClass2
657{
658 int Test() { return FALSE; }
659 int Test1() { return TRUE; }
660
661 CAbc(int a, int b ) :
662 BaseClass(a)
663 {
664 switch(xxx)
665 {
666 case abc:
667 asdf();
668 break;
669
670 case 999:
671 baer();
672 break;
673 }
674 }
675
676 public: // <-- this was incoreectly indented before!!
677 void testfall();
678 protected:
679 void testfall();
680};
681
682class CAbc : public BaseClass1,
Bram Moolenaar7fc904b2006-04-13 20:37:35 +0000683 protected BaseClass2
Bram Moolenaar071d4272004-06-13 20:20:40 +0000684{
685};
686
687static struct
688{
689 int a;
690 int b;
691} variable[COUNT] =
692{
693 {
694 123,
695 456
696 },
697 {
698 123,
699 456
700 }
701};
702
703static struct
704{
705 int a;
706 int b;
707} variable[COUNT] =
708{
709 { 123, 456 },
710 { 123, 456 }
711};
712
713void asdf() /* ind_maxparen may cause trouble here */
714{
715 if ((0
716 && 1
717 && 1
718 && 1
719 && 1
720 && 1
721 && 1
722 && 1
723 && 1
724 && 1
725 && 1
726 && 1
727 && 1
728 && 1
729 && 1
730 && 1
731 && 1
732 && 1
733 && 1
734 && 1
735 && 1
736 && 1
737 && 1
738 && 1
739 && 1
740 && 1)) break;
741}
742
Bram Moolenaar18144c82006-04-12 21:52:12 +0000743foo()
744{
745 a = cond ? foo() : asdf
746 + asdf;
747
748 a = cond ?
749 foo() : asdf
750 + asdf;
751}
752
753int main(void)
754{
755 if (a)
756 if (b)
757 2;
758 else 3;
759 next_line_of_code();
760}
761
Bram Moolenaar7fc904b2006-04-13 20:37:35 +0000762barry()
763{
764 Foo::Foo (int one,
765 int two)
766 : something(4)
767 {}
768}
769
770barry()
771{
772 Foo::Foo (int one, int two)
773 : something(4)
774 {}
775}
776
777Constructor::Constructor(int a,
778 int b
779 ) :
780 BaseClass(a,
781 b,
782 c),
783 mMember(b)
784{
785}
Bram Moolenaar9e54a0e2006-04-14 20:42:25 +0000786int main ()
787{
788 if (lala)
789 do
790 ++(*lolo);
791 while (lili
792 && lele);
793 lulu;
794}
Bram Moolenaar7fc904b2006-04-13 20:37:35 +0000795
Bram Moolenaar9e54a0e2006-04-14 20:42:25 +0000796int main ()
797{
798 switch (c)
799 {
800 case 'c': if (cond)
801 {
802 }
803 }
804}
805
806main()
807{
808 (void) MyFancyFuasdfadsfnction(
809 argument);
810}
811
812main()
813{
814 char foo[] = "/*";
815 /* as
816 df */
817 hello
818}
Bram Moolenaared38b0a2011-05-25 15:16:18 +0200819
820/* valid namespaces with normal indent */
821namespace
822{
823 {
824 111111111111;
825 }
826}
827namespace /* test */
828{
829 11111111111111111;
830}
831namespace // test
832{
833 111111111111111111;
834}
835namespace
836{
837 111111111111111111;
838}
839namespace test
840{
841 111111111111111111;
842}
843namespace{
844 111111111111111111;
845}
846namespace test{
847 111111111111111111;
848}
849namespace {
850 111111111111111111;
851}
852namespace test {
853 111111111111111111;
854 namespace test2 {
855 22222222222222222;
856 }
857}
858
859/* invalid namespaces use block indent */
860namespace test test2 {
861 111111111111111111111;
862}
863namespace11111111111 {
864 111111111111;
865}
866namespace() {
867 1111111111111;
868}
869namespace()
870{
871 111111111111111111;
872}
873namespace test test2
874{
875 1111111111111111111;
876}
877namespace111111111
878{
879 111111111111111111;
880}
881
Bram Moolenaar071d4272004-06-13 20:20:40 +0000882/* end of AUTO */
883
884
885{
886
887/* this is
888 * a real serious
889 * about life, the
890 * universe, and the
891 * rest important big
892 * comment
893 */
894 /* insert " about life, the universe, and the rest" after "serious" */
895}
896
897
898{
899 /*
900 * Testing for comments, without 'cin' set
901 */
902about life
903
904/*
905* what happens here?
906*/
907there
908
909 /*
910 the end of the comment, try inserting a line below */
911line
912
913 /* how about
914hello
915 this one */
916}
917
918
919{
920 var = this + that + vec[0] * vec[0]
921 + vec[1] * vec[1]
922 + vec2[2] * vec[2];
923}
924
925
926{
927 asdf asdflkajds f;
928 if (tes & ting) {
929 asdf asdf asdf ;
930 asdfa sdf asdf;
931 }
932 testing1;
933 if (tes & ting)
934 {
935 asdf asdf asdf ;
936 asdfa sdf asdf;
937 }
938 testing2;
939}
940
941
942main ( int first_par, /*
943 * Comment for
944 * first par
945 */
946 int second_par /*
947 * Comment for
948 * second par
949 */
950 )
951{
952 func( first_par, /*
953 * Comment for
954 * first par
955 */
956 second_par /*
957 * Comment for
958 * second par
959 */
960 );
961
962}
963
964
Bram Moolenaar48d27922012-06-13 13:40:48 +0200965main(void)
966{
967 /* Make sure that cino=X0s is not parsed like cino=Xs. */
968 if (cond)
969 foo();
970 else
971 {
972 bar();
973 }
974}
975
976
Bram Moolenaar071d4272004-06-13 20:20:40 +0000977{
978 do
979 {
980 if ()
981 {
982 if ()
983 asdf;
984 else
985 asdf;
986 }
987 } while ();
988 cmd; /* this should go under the } */
989}
990
991
992void f()
993{
994 if ( k() ) {
995 l();
996
997 } else { /* Start (two words) end */
998 m();
999 }
1000
1001 n();
1002}
1003
1004
1005void f()
1006 {
1007 if ( k() )
1008 {
1009 l();
1010 } else { /* Start (two words) end */
1011 m();
1012 }
1013 n(); /* should be under the if () */
1014}
1015
1016
1017void bar(void)
1018 {
1019 static array[2][2] =
1020 {
1021 { 1, 2 },
1022 { 3, 4 },
1023 }
1024
1025 while (a)
1026 {
1027 foo(&a);
1028 }
1029
1030 {
1031 int a;
1032 {
1033 a = a + 1;
1034 }
1035 }
1036 b = a;
1037 }
1038
1039void func(void)
1040 {
1041 a = 1;
1042 {
1043 b = 2;
1044 }
1045 c = 3;
1046 d = 4;
1047 }
1048/* foo */
1049
1050
1051a()
1052{
1053 do {
1054 a = a +
1055 a;
1056 } while ( a ); /* add text under this line */
1057 here
1058 if ( a )
1059 a;
1060}
1061
1062
1063a()
1064{
1065label1:
1066 /* hmm */
1067 // comment
1068label2: b();
1069label3 /* post */:
1070/* pre */ label4:
1071 f(/*com*/);
1072 if (/*com*/)
1073 cmd();
1074}
1075
1076
1077/*
1078 * A simple comment
1079 */
1080
1081/*
1082** A different comment
1083*/
1084
1085
1086void f()
1087{
1088
1089 /*********
1090 A comment.
1091 *********/
1092}
1093
1094
1095void f()
1096{
1097
1098 /*********
1099 A comment.
1100 *********/
1101}
1102
1103
1104void f()
1105{
1106 c = c1 &&
1107 (
1108 c2 ||
1109 c3
1110 ) && c4;
1111}
1112
1113
1114void f()
1115{
1116 c = c1 &&
1117 (
1118 c2 ||
1119 c3
1120 ) && c4;
1121}
1122
1123
1124void f()
1125{
1126 c = c1 &&
1127 (
1128 c2 ||
1129 c3
1130 ) && c4;
1131}
1132
1133
1134void f()
1135{
1136 if ( c1
1137 && ( c2
1138 || c3))
1139 foo;
1140}
1141
1142
1143void f()
1144{
1145 if ( c1
1146 && ( c2
1147 || c3))
1148 foo;
1149}
1150
1151
1152void f()
1153{
1154 c = c1 && (
1155 c2 ||
1156 c3
1157 ) && c4;
1158 if (
1159 c1 && c2
1160 )
1161 foo;
1162}
1163
1164
1165void f()
1166{
1167 c = c1 && (
1168 c2 ||
1169 c3
1170 ) && c4;
1171 if (
1172 c1 && c2
1173 )
1174 foo;
1175}
1176
1177
1178void f()
1179{
1180 switch (x)
1181 {
1182 case 1:
1183 a = b;
1184 break;
1185 default:
1186 a = 0;
1187 break;
1188 }
1189}
1190
1191
1192void f()
1193{
1194 invokeme(
1195 argu,
1196 ment);
1197 invokeme(
1198 argu,
1199 ment
1200 );
1201 invokeme(argu,
1202 ment
1203 );
1204}
1205
1206
1207void f()
1208{
1209 statement;
1210 // comment 1
1211 // comment 2
1212}
1213
1214
1215void f()
1216{
1217 statement;
1218 // comment 1
1219 // comment 2
1220}
1221
1222
1223class CAbc
1224{
1225 int Test() { return FALSE; }
1226
1227public: // comment
1228 void testfall();
1229protected:
1230 void testfall();
1231};
1232
1233
Bram Moolenaare79d1532011-10-04 18:03:47 +02001234class Foo : public Bar
1235{
1236 public:
1237 virtual void method1(void) = 0;
1238 virtual void method2(int arg1,
1239 int arg2,
1240 int arg3) = 0;
1241};
1242
1243
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00001244 void
1245foo()
1246{
1247 if (a)
1248 {
1249 } else
1250 asdf;
1251}
1252
1253
Bram Moolenaar071d4272004-06-13 20:20:40 +00001254{
1255 averylongfunctionnamelongfunctionnameaverylongfunctionname()->asd(
1256 asdasdf,
1257 func(asdf,
1258 asdfadsf),
1259 asdfasdf
1260 );
1261
1262 /* those are ugly, but consequent */
1263
1264 func()->asd(asdasdf,
1265 averylongfunctionname(
1266 abc,
1267 dec)->averylongfunctionname(
1268 asdfadsf,
1269 asdfasdf,
1270 asdfasdf,
1271 ),
1272 func(asdfadf,
1273 asdfasdf
1274 ),
1275 asdasdf
1276 );
1277
1278 averylongfunctionnameaverylongfunctionnameavery()->asd(fasdf(
1279 abc,
1280 dec)->asdfasdfasdf(
1281 asdfadsf,
1282 asdfasdf,
1283 asdfasdf,
1284 ),
1285 func(asdfadf,
1286 asdfasdf),
1287 asdasdf
1288 );
1289}
1290
Bram Moolenaar9e54a0e2006-04-14 20:42:25 +00001291
1292int main ()
1293{
1294 if (cond1 &&
1295 cond2
1296 )
1297 foo;
1298}
1299
Bram Moolenaar8d2d71d2011-04-28 13:02:09 +02001300
1301void func(int a
1302#if defined(FOO)
1303 , int b
1304 , int c
1305#endif
1306 )
1307{
1308}
1309
1310
1311 void
1312func(int a
1313#if defined(FOO)
1314 , int b
1315 , int c
1316#endif
1317 )
1318{
1319}
1320
Bram Moolenaar4ae06c12011-05-10 11:39:19 +02001321
1322void func(void)
1323{
1324 if(x==y)
1325 if(y==z)
1326 foo=1;
1327 else { bar=1;
1328 baz=2;
1329 }
1330 printf("Foo!\n");
1331}
1332
Bram Moolenaar496f9512011-05-19 16:35:09 +02001333void func1(void)
1334{
1335 char* tab[] = {"foo", "bar",
1336 "baz", "quux",
1337 "this line used", "to be indented incorrectly"};
1338 foo();
1339}
1340
1341void func2(void)
1342{
1343 int tab[] =
1344 {1, 2,
1345 3, 4,
1346 5, 6};
1347
1348 printf("This line used to be indented incorrectly.\n");
1349}
1350
Bram Moolenaar3388bb42011-11-30 17:20:23 +01001351int foo[]
1352#ifdef BAR
1353
1354= { 1, 2, 3,
1355 4, 5, 6 }
1356
1357#endif
1358 ;
1359int baz;
1360
Bram Moolenaar496f9512011-05-19 16:35:09 +02001361void func3(void)
1362{
1363 int tab[] = {
1364 1, 2,
1365 3, 4,
1366 5, 6};
1367
Bram Moolenaarc367faa2011-12-14 20:21:35 +01001368 printf("Don't you dare indent this line incorrectly!\n");
1369}
1370
1371 void
1372func4(a, b,
1373 c)
1374 int a;
1375 int b;
1376 int c;
1377{
1378}
1379
1380 void
1381func5(
1382 int a,
1383 int b)
1384{
1385}
1386
1387 void
1388func6(
1389 int a)
1390{
Bram Moolenaar496f9512011-05-19 16:35:09 +02001391}
1392
Bram Moolenaaraede6ce2011-05-10 11:56:30 +02001393
1394void func(void)
1395{
Bram Moolenaar50f42ca2011-07-15 14:12:30 +02001396 int tab[] =
1397 {
1398 1, 2, 3,
1399 4, 5, 6};
1400
1401 printf("Indent this line correctly!\n");
1402
1403 switch (foo)
1404 {
1405 case bar:
1406 printf("bar");
1407 break;
1408 case baz: {
1409 printf("baz");
1410 break;
1411 }
1412 case quux:
1413 printf("But don't break the indentation of this instruction\n");
1414 break;
1415 }
1416}
1417
1418
1419void func(void)
1420{
Bram Moolenaaraede6ce2011-05-10 11:56:30 +02001421 cout << "a"
1422 << "b"
1423 << ") :"
1424 << "c";
1425}
1426
Bram Moolenaara4271d52011-05-10 13:38:27 +02001427
1428void func(void)
1429{
1430 /*
1431 * This is a comment.
1432 */
1433 foo();
1434}
1435
Bram Moolenaar334adf02011-05-25 13:34:04 +02001436
1437void func(void)
1438{
1439 for (int i = 0; i < 10; ++i)
1440 if (i & 1) {
1441 foo(1);
1442 } else
1443 foo(0);
1444 baz();
1445}
1446
Bram Moolenaared38b0a2011-05-25 15:16:18 +02001447
Bram Moolenaar3675fa02012-04-05 17:17:42 +02001448void func(void)
1449{
1450 if (condition1
1451 && condition2)
1452 action();
1453 function(argument1
1454 && argument2);
1455
1456 if (c1 && (c2 ||
1457 c3))
1458 foo;
1459 if (c1 &&
1460 (c2 || c3))
1461 {
1462 }
1463
1464 if ( c1
1465 && ( c2
1466 || c3))
1467 foo;
1468 func( c1
1469 && ( c2
1470 || c3))
1471 foo;
1472}
1473
1474
1475void func(void)
1476{
1477 if (condition1
1478 && condition2)
1479 action();
1480 function(argument1
1481 && argument2);
1482
1483 if (c1 && (c2 ||
1484 c3))
1485 foo;
1486 if (c1 &&
1487 (c2 || c3))
1488 {
1489 }
1490
1491 if ( c1
1492 && ( c2
1493 || c3))
1494 foo;
1495 func( c1
1496 && ( c2
1497 || c3))
1498 foo;
1499}
1500
1501
1502void func(void)
1503{
1504 if (condition1
1505 && condition2)
1506 action();
1507 function(argument1
1508 && argument2);
1509
1510 if (c1 && (c2 ||
1511 c3))
1512 foo;
1513 if (c1 &&
1514 (c2 || c3))
1515 {
1516 }
1517 if (c123456789
1518 && (c22345
1519 || c3))
1520 printf("foo\n");
1521
1522 c = c1 &&
1523 (
1524 c2 ||
1525 c3
1526 ) && c4;
1527}
1528
1529
1530void func(void)
1531{
1532 if (condition1
1533 && condition2)
1534 action();
1535 function(argument1
1536 && argument2);
1537
1538 if (c1 && (c2 ||
1539 c3))
1540 foo;
1541 if (c1 &&
1542 (c2 || c3))
1543 {
1544 }
1545 if (c123456789
1546 && (c22345
1547 || c3))
1548 printf("foo\n");
1549
1550 if ( c1
1551 && ( c2
1552 || c3))
1553 foo;
1554
1555 a_long_line(
1556 argument,
1557 argument);
1558 a_short_line(argument,
1559 argument);
1560}
1561
1562
1563void func(void)
1564{
1565 if (condition1
1566 && condition2)
1567 action();
1568 function(argument1
1569 && argument2);
1570
1571 if (c1 && (c2 ||
1572 c3))
1573 foo;
1574 if (c1 &&
1575 (c2 || c3))
1576 {
1577 }
1578 if (c123456789
1579 && (c22345
1580 || c3))
1581 printf("foo\n");
1582}
1583
1584
1585void func(void)
1586{
1587 if (condition1
1588 && condition2)
1589 action();
1590 function(argument1
1591 && argument2);
1592
1593 if (c1 && (c2 ||
1594 c3))
1595 foo;
1596 if (c1 &&
1597 (c2 || c3))
1598 {
1599 }
1600 if (c123456789
1601 && (c22345
1602 || c3))
1603 printf("foo\n");
1604
1605 if ( c1
1606 && ( c2
1607 || c3))
1608 foo;
1609 func( c1
1610 && ( c2
1611 || c3))
1612 foo;
1613}
1614
1615
1616void func(void)
1617{
1618 if (condition1
1619 && condition2)
1620 action();
1621 function(argument1
1622 && argument2);
1623
1624 if (c1 && (c2 ||
1625 c3))
1626 foo;
1627 if (c1 &&
1628 (c2 || c3))
1629 {
1630 }
1631}
1632
1633
Bram Moolenaar6ec154b2011-06-12 21:51:08 +02001634NAMESPACESTART
Bram Moolenaared38b0a2011-05-25 15:16:18 +02001635/* valid namespaces with normal indent */
1636namespace
1637{
1638{
1639 111111111111;
1640}
1641}
1642namespace /* test */
1643{
164411111111111111111;
1645}
1646namespace // test
1647{
1648111111111111111111;
1649}
1650namespace
1651{
1652111111111111111111;
1653}
1654namespace test
1655{
1656111111111111111111;
1657}
1658namespace{
1659111111111111111111;
1660}
1661namespace test{
1662111111111111111111;
1663}
1664namespace {
1665111111111111111111;
1666}
1667namespace test {
1668111111111111111111;
1669namespace test2 {
167022222222222222222;
1671}
1672}
1673
1674/* invalid namespaces use block indent */
1675namespace test test2 {
1676 111111111111111111111;
1677}
1678namespace11111111111 {
1679 111111111111;
1680}
1681namespace() {
1682 1111111111111;
1683}
1684namespace()
1685{
1686 111111111111111111;
1687}
1688namespace test test2
1689{
1690 1111111111111111111;
1691}
1692namespace111111111
1693{
1694 111111111111111111;
1695}
1696NAMESPACEEND
1697
1698
Bram Moolenaar6ec154b2011-06-12 21:51:08 +02001699
1700JSSTART
1701var bar = {
1702 foo: {
1703 that: this,
1704 some: ok,
1705 },
1706 "bar":{
1707 a : 2,
1708 b: "123abc",
1709 x: 4,
1710 "y": 5
1711 }
1712}
1713JSEND
1714
Bram Moolenaar76f7fd32011-07-20 15:09:43 +02001715
1716JSSTART
1717var foo = [
Bram Moolenaar9f4fe7c2014-07-03 22:57:55 +02001718 1,
Bram Moolenaar76f7fd32011-07-20 15:09:43 +02001719 2,
1720 3
Bram Moolenaar9f4fe7c2014-07-03 22:57:55 +02001721];
Bram Moolenaar76f7fd32011-07-20 15:09:43 +02001722JSEND
1723
1724
1725JSSTART
1726function bar() {
1727 var foo = [
1728 1,
1729 2,
1730 3
Bram Moolenaar9f4fe7c2014-07-03 22:57:55 +02001731 ];
Bram Moolenaar76f7fd32011-07-20 15:09:43 +02001732}
1733JSEND
1734
1735
1736JSSTART
1737(function($){
1738
Bram Moolenaar81439a62014-07-02 18:27:48 +02001739 if (cond &&
1740 cond) {
1741 stmt;
1742 }
Bram Moolenaar9f4fe7c2014-07-03 22:57:55 +02001743 window.something.left =
1744 (width - 50 + offset) + "px";
Bram Moolenaar76f7fd32011-07-20 15:09:43 +02001745 var class_name='myclass';
1746
1747 function private_method() {
1748 }
1749
1750 var public_method={
1751 method: function(options,args){
1752 private_method();
1753 }
1754 }
1755
1756 function init(options) {
1757
1758 $(this).data(class_name+'_public',$.extend({},{
1759 foo: 'bar',
Bram Moolenaar9f4fe7c2014-07-03 22:57:55 +02001760 bar: 2,
1761 foobar: [
1762 1,
1763 2,
1764 3
Bram Moolenaar76f7fd32011-07-20 15:09:43 +02001765 ],
Bram Moolenaar9f4fe7c2014-07-03 22:57:55 +02001766 callback: function(){
1767 return true;
1768 }
Bram Moolenaar76f7fd32011-07-20 15:09:43 +02001769 }, options||{}));
1770 }
1771
1772 $.fn[class_name]=function() {
1773
1774 var _arguments=arguments;
1775 return this.each(function(){
1776
1777 var options=$(this).data(class_name+'_public');
1778 if (!options) {
1779 init.apply(this,_arguments);
1780
1781 } else {
1782 var method=public_method[_arguments[0]];
1783
1784 if (typeof(method)!='function') {
1785 console.log(class_name+' has no method "'+_arguments[0]+'"');
1786 return false;
1787 }
1788 _arguments[0]=options;
1789 method.apply(this,_arguments);
1790 }
1791 });
1792 }
1793
1794})(jQuery);
1795JSEND
1796
1797
1798JSSTART
1799function init(options) {
1800 $(this).data(class_name+'_public',$.extend({},{
1801 foo: 'bar',
1802 bar: 2,
1803 foobar: [
Bram Moolenaar9f4fe7c2014-07-03 22:57:55 +02001804 1,
1805 2,
1806 3
Bram Moolenaar76f7fd32011-07-20 15:09:43 +02001807 ],
1808 callback: function(){
1809 return true;
1810 }
1811 }, options||{}));
1812}
1813JSEND
1814
1815
1816JSSTART
1817(function($){
1818 function init(options) {
1819 $(this).data(class_name+'_public',$.extend({},{
1820 foo: 'bar',
Bram Moolenaar9f4fe7c2014-07-03 22:57:55 +02001821 bar: 2,
1822 foobar: [
1823 1,
1824 2,
1825 3
Bram Moolenaar76f7fd32011-07-20 15:09:43 +02001826 ],
Bram Moolenaar9f4fe7c2014-07-03 22:57:55 +02001827 callback: function(){
1828 return true;
1829 }
Bram Moolenaar76f7fd32011-07-20 15:09:43 +02001830 }, options||{}));
1831 }
1832})(jQuery);
1833JSEND
1834