blob: e87e7fdcab277b36a207fe005e306acf31cd25a3 [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 Moolenaarf7bb86d2015-07-28 21:17:36 +0200882void getstring() {
883 /* Raw strings */
884 const char* s = R"(
885 test {
886 # comment
887 field: 123
888 }
889 )";
890}
891
892void getstring() {
893 const char* s = R"foo(
894 test {
895 # comment
896 field: 123
897 }
898 )foo";
899}
900
Bram Moolenaar071d4272004-06-13 20:20:40 +0000901/* end of AUTO */
902
903
904{
905
906/* this is
907 * a real serious
908 * about life, the
909 * universe, and the
910 * rest important big
911 * comment
912 */
913 /* insert " about life, the universe, and the rest" after "serious" */
914}
915
916
917{
918 /*
919 * Testing for comments, without 'cin' set
920 */
921about life
922
923/*
924* what happens here?
925*/
926there
927
928 /*
929 the end of the comment, try inserting a line below */
930line
931
932 /* how about
933hello
934 this one */
935}
936
937
938{
939 var = this + that + vec[0] * vec[0]
940 + vec[1] * vec[1]
941 + vec2[2] * vec[2];
942}
943
944
945{
946 asdf asdflkajds f;
947 if (tes & ting) {
948 asdf asdf asdf ;
949 asdfa sdf asdf;
950 }
951 testing1;
952 if (tes & ting)
953 {
954 asdf asdf asdf ;
955 asdfa sdf asdf;
956 }
957 testing2;
958}
959
960
961main ( int first_par, /*
962 * Comment for
963 * first par
964 */
965 int second_par /*
966 * Comment for
967 * second par
968 */
969 )
970{
971 func( first_par, /*
972 * Comment for
973 * first par
974 */
975 second_par /*
976 * Comment for
977 * second par
978 */
979 );
980
981}
982
983
Bram Moolenaar48d27922012-06-13 13:40:48 +0200984main(void)
985{
986 /* Make sure that cino=X0s is not parsed like cino=Xs. */
987 if (cond)
988 foo();
989 else
990 {
991 bar();
992 }
993}
994
995
Bram Moolenaar071d4272004-06-13 20:20:40 +0000996{
997 do
998 {
999 if ()
1000 {
1001 if ()
1002 asdf;
1003 else
1004 asdf;
1005 }
1006 } while ();
1007 cmd; /* this should go under the } */
1008}
1009
1010
1011void f()
1012{
1013 if ( k() ) {
1014 l();
1015
1016 } else { /* Start (two words) end */
1017 m();
1018 }
1019
1020 n();
1021}
1022
1023
1024void f()
1025 {
1026 if ( k() )
1027 {
1028 l();
1029 } else { /* Start (two words) end */
1030 m();
1031 }
1032 n(); /* should be under the if () */
1033}
1034
1035
1036void bar(void)
1037 {
1038 static array[2][2] =
1039 {
1040 { 1, 2 },
1041 { 3, 4 },
1042 }
1043
1044 while (a)
1045 {
1046 foo(&a);
1047 }
1048
1049 {
1050 int a;
1051 {
1052 a = a + 1;
1053 }
1054 }
1055 b = a;
1056 }
1057
1058void func(void)
1059 {
1060 a = 1;
1061 {
1062 b = 2;
1063 }
1064 c = 3;
1065 d = 4;
1066 }
1067/* foo */
1068
1069
1070a()
1071{
1072 do {
1073 a = a +
1074 a;
1075 } while ( a ); /* add text under this line */
1076 here
1077 if ( a )
1078 a;
1079}
1080
1081
1082a()
1083{
1084label1:
1085 /* hmm */
1086 // comment
1087label2: b();
1088label3 /* post */:
1089/* pre */ label4:
1090 f(/*com*/);
1091 if (/*com*/)
1092 cmd();
1093}
1094
1095
1096/*
1097 * A simple comment
1098 */
1099
1100/*
1101** A different comment
1102*/
1103
1104
1105void f()
1106{
1107
1108 /*********
1109 A comment.
1110 *********/
1111}
1112
1113
1114void f()
1115{
1116
1117 /*********
1118 A comment.
1119 *********/
1120}
1121
1122
1123void f()
1124{
1125 c = c1 &&
1126 (
1127 c2 ||
1128 c3
1129 ) && c4;
1130}
1131
1132
1133void f()
1134{
1135 c = c1 &&
1136 (
1137 c2 ||
1138 c3
1139 ) && c4;
1140}
1141
1142
1143void f()
1144{
1145 c = c1 &&
1146 (
1147 c2 ||
1148 c3
1149 ) && c4;
1150}
1151
1152
1153void f()
1154{
1155 if ( c1
1156 && ( c2
1157 || c3))
1158 foo;
1159}
1160
1161
1162void f()
1163{
1164 if ( c1
1165 && ( c2
1166 || c3))
1167 foo;
1168}
1169
1170
1171void f()
1172{
1173 c = c1 && (
1174 c2 ||
1175 c3
1176 ) && c4;
1177 if (
1178 c1 && c2
1179 )
1180 foo;
1181}
1182
1183
1184void f()
1185{
1186 c = c1 && (
1187 c2 ||
1188 c3
1189 ) && c4;
1190 if (
1191 c1 && c2
1192 )
1193 foo;
1194}
1195
1196
1197void f()
1198{
1199 switch (x)
1200 {
1201 case 1:
1202 a = b;
1203 break;
1204 default:
1205 a = 0;
1206 break;
1207 }
1208}
1209
1210
1211void f()
1212{
1213 invokeme(
1214 argu,
1215 ment);
1216 invokeme(
1217 argu,
1218 ment
1219 );
1220 invokeme(argu,
1221 ment
1222 );
1223}
1224
1225
1226void f()
1227{
1228 statement;
1229 // comment 1
1230 // comment 2
1231}
1232
1233
1234void f()
1235{
1236 statement;
1237 // comment 1
1238 // comment 2
1239}
1240
1241
1242class CAbc
1243{
1244 int Test() { return FALSE; }
1245
1246public: // comment
1247 void testfall();
1248protected:
1249 void testfall();
1250};
1251
1252
Bram Moolenaare79d1532011-10-04 18:03:47 +02001253class Foo : public Bar
1254{
1255 public:
1256 virtual void method1(void) = 0;
1257 virtual void method2(int arg1,
1258 int arg2,
1259 int arg3) = 0;
1260};
1261
1262
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00001263 void
1264foo()
1265{
1266 if (a)
1267 {
1268 } else
1269 asdf;
1270}
1271
1272
Bram Moolenaar071d4272004-06-13 20:20:40 +00001273{
1274 averylongfunctionnamelongfunctionnameaverylongfunctionname()->asd(
1275 asdasdf,
1276 func(asdf,
1277 asdfadsf),
1278 asdfasdf
1279 );
1280
1281 /* those are ugly, but consequent */
1282
1283 func()->asd(asdasdf,
1284 averylongfunctionname(
1285 abc,
1286 dec)->averylongfunctionname(
1287 asdfadsf,
1288 asdfasdf,
1289 asdfasdf,
1290 ),
1291 func(asdfadf,
1292 asdfasdf
1293 ),
1294 asdasdf
1295 );
1296
1297 averylongfunctionnameaverylongfunctionnameavery()->asd(fasdf(
1298 abc,
1299 dec)->asdfasdfasdf(
1300 asdfadsf,
1301 asdfasdf,
1302 asdfasdf,
1303 ),
1304 func(asdfadf,
1305 asdfasdf),
1306 asdasdf
1307 );
1308}
1309
Bram Moolenaar9e54a0e2006-04-14 20:42:25 +00001310
1311int main ()
1312{
1313 if (cond1 &&
1314 cond2
1315 )
1316 foo;
1317}
1318
Bram Moolenaar8d2d71d2011-04-28 13:02:09 +02001319
1320void func(int a
1321#if defined(FOO)
1322 , int b
1323 , int c
1324#endif
1325 )
1326{
1327}
1328
1329
1330 void
1331func(int a
1332#if defined(FOO)
1333 , int b
1334 , int c
1335#endif
1336 )
1337{
1338}
1339
Bram Moolenaar4ae06c12011-05-10 11:39:19 +02001340
1341void func(void)
1342{
1343 if(x==y)
1344 if(y==z)
1345 foo=1;
1346 else { bar=1;
1347 baz=2;
1348 }
1349 printf("Foo!\n");
1350}
1351
Bram Moolenaar496f9512011-05-19 16:35:09 +02001352void func1(void)
1353{
1354 char* tab[] = {"foo", "bar",
1355 "baz", "quux",
1356 "this line used", "to be indented incorrectly"};
1357 foo();
1358}
1359
1360void func2(void)
1361{
1362 int tab[] =
1363 {1, 2,
1364 3, 4,
1365 5, 6};
1366
1367 printf("This line used to be indented incorrectly.\n");
1368}
1369
Bram Moolenaar3388bb42011-11-30 17:20:23 +01001370int foo[]
1371#ifdef BAR
1372
1373= { 1, 2, 3,
1374 4, 5, 6 }
1375
1376#endif
1377 ;
1378int baz;
1379
Bram Moolenaar496f9512011-05-19 16:35:09 +02001380void func3(void)
1381{
1382 int tab[] = {
1383 1, 2,
1384 3, 4,
1385 5, 6};
1386
Bram Moolenaarc367faa2011-12-14 20:21:35 +01001387 printf("Don't you dare indent this line incorrectly!\n");
1388}
1389
1390 void
1391func4(a, b,
1392 c)
1393 int a;
1394 int b;
1395 int c;
1396{
1397}
1398
1399 void
1400func5(
1401 int a,
1402 int b)
1403{
1404}
1405
1406 void
1407func6(
1408 int a)
1409{
Bram Moolenaar496f9512011-05-19 16:35:09 +02001410}
1411
Bram Moolenaaraede6ce2011-05-10 11:56:30 +02001412
1413void func(void)
1414{
Bram Moolenaar50f42ca2011-07-15 14:12:30 +02001415 int tab[] =
1416 {
1417 1, 2, 3,
1418 4, 5, 6};
1419
1420 printf("Indent this line correctly!\n");
1421
1422 switch (foo)
1423 {
1424 case bar:
1425 printf("bar");
1426 break;
1427 case baz: {
1428 printf("baz");
1429 break;
1430 }
1431 case quux:
1432 printf("But don't break the indentation of this instruction\n");
1433 break;
1434 }
1435}
1436
1437
1438void func(void)
1439{
Bram Moolenaaraede6ce2011-05-10 11:56:30 +02001440 cout << "a"
1441 << "b"
1442 << ") :"
1443 << "c";
1444}
1445
Bram Moolenaara4271d52011-05-10 13:38:27 +02001446
1447void func(void)
1448{
1449 /*
1450 * This is a comment.
1451 */
1452 foo();
1453}
1454
Bram Moolenaar334adf02011-05-25 13:34:04 +02001455
1456void func(void)
1457{
1458 for (int i = 0; i < 10; ++i)
1459 if (i & 1) {
1460 foo(1);
1461 } else
1462 foo(0);
1463 baz();
1464}
1465
Bram Moolenaared38b0a2011-05-25 15:16:18 +02001466
Bram Moolenaar3675fa02012-04-05 17:17:42 +02001467void func(void)
1468{
1469 if (condition1
1470 && condition2)
1471 action();
1472 function(argument1
1473 && argument2);
1474
1475 if (c1 && (c2 ||
1476 c3))
1477 foo;
1478 if (c1 &&
1479 (c2 || c3))
1480 {
1481 }
1482
1483 if ( c1
1484 && ( c2
1485 || c3))
1486 foo;
1487 func( c1
1488 && ( c2
1489 || c3))
1490 foo;
1491}
1492
1493
1494void func(void)
1495{
1496 if (condition1
1497 && condition2)
1498 action();
1499 function(argument1
1500 && argument2);
1501
1502 if (c1 && (c2 ||
1503 c3))
1504 foo;
1505 if (c1 &&
1506 (c2 || c3))
1507 {
1508 }
1509
1510 if ( c1
1511 && ( c2
1512 || c3))
1513 foo;
1514 func( c1
1515 && ( c2
1516 || c3))
1517 foo;
1518}
1519
1520
1521void func(void)
1522{
1523 if (condition1
1524 && condition2)
1525 action();
1526 function(argument1
1527 && argument2);
1528
1529 if (c1 && (c2 ||
1530 c3))
1531 foo;
1532 if (c1 &&
1533 (c2 || c3))
1534 {
1535 }
1536 if (c123456789
1537 && (c22345
1538 || c3))
1539 printf("foo\n");
1540
1541 c = c1 &&
1542 (
1543 c2 ||
1544 c3
1545 ) && c4;
1546}
1547
1548
1549void func(void)
1550{
1551 if (condition1
1552 && condition2)
1553 action();
1554 function(argument1
1555 && argument2);
1556
1557 if (c1 && (c2 ||
1558 c3))
1559 foo;
1560 if (c1 &&
1561 (c2 || c3))
1562 {
1563 }
1564 if (c123456789
1565 && (c22345
1566 || c3))
1567 printf("foo\n");
1568
1569 if ( c1
1570 && ( c2
1571 || c3))
1572 foo;
1573
1574 a_long_line(
1575 argument,
1576 argument);
1577 a_short_line(argument,
1578 argument);
1579}
1580
1581
1582void func(void)
1583{
1584 if (condition1
1585 && condition2)
1586 action();
1587 function(argument1
1588 && argument2);
1589
1590 if (c1 && (c2 ||
1591 c3))
1592 foo;
1593 if (c1 &&
1594 (c2 || c3))
1595 {
1596 }
1597 if (c123456789
1598 && (c22345
1599 || c3))
1600 printf("foo\n");
1601}
1602
1603
1604void func(void)
1605{
1606 if (condition1
1607 && condition2)
1608 action();
1609 function(argument1
1610 && argument2);
1611
1612 if (c1 && (c2 ||
1613 c3))
1614 foo;
1615 if (c1 &&
1616 (c2 || c3))
1617 {
1618 }
1619 if (c123456789
1620 && (c22345
1621 || c3))
1622 printf("foo\n");
1623
1624 if ( c1
1625 && ( c2
1626 || c3))
1627 foo;
1628 func( c1
1629 && ( c2
1630 || c3))
1631 foo;
1632}
1633
1634
1635void func(void)
1636{
1637 if (condition1
1638 && condition2)
1639 action();
1640 function(argument1
1641 && argument2);
1642
1643 if (c1 && (c2 ||
1644 c3))
1645 foo;
1646 if (c1 &&
1647 (c2 || c3))
1648 {
1649 }
1650}
1651
1652
Bram Moolenaar6ec154b2011-06-12 21:51:08 +02001653NAMESPACESTART
Bram Moolenaared38b0a2011-05-25 15:16:18 +02001654/* valid namespaces with normal indent */
1655namespace
1656{
1657{
1658 111111111111;
1659}
1660}
1661namespace /* test */
1662{
166311111111111111111;
1664}
1665namespace // test
1666{
1667111111111111111111;
1668}
1669namespace
1670{
1671111111111111111111;
1672}
1673namespace test
1674{
1675111111111111111111;
1676}
1677namespace{
1678111111111111111111;
1679}
1680namespace test{
1681111111111111111111;
1682}
1683namespace {
1684111111111111111111;
1685}
1686namespace test {
1687111111111111111111;
1688namespace test2 {
168922222222222222222;
1690}
1691}
1692
1693/* invalid namespaces use block indent */
1694namespace test test2 {
1695 111111111111111111111;
1696}
1697namespace11111111111 {
1698 111111111111;
1699}
1700namespace() {
1701 1111111111111;
1702}
1703namespace()
1704{
1705 111111111111111111;
1706}
1707namespace test test2
1708{
1709 1111111111111111111;
1710}
1711namespace111111111
1712{
1713 111111111111111111;
1714}
1715NAMESPACEEND
1716
1717
Bram Moolenaar6ec154b2011-06-12 21:51:08 +02001718
1719JSSTART
1720var bar = {
1721 foo: {
1722 that: this,
1723 some: ok,
1724 },
1725 "bar":{
1726 a : 2,
1727 b: "123abc",
1728 x: 4,
1729 "y": 5
1730 }
1731}
1732JSEND
1733
Bram Moolenaar76f7fd32011-07-20 15:09:43 +02001734
1735JSSTART
1736var foo = [
Bram Moolenaar9f4fe7c2014-07-03 22:57:55 +02001737 1,
Bram Moolenaar76f7fd32011-07-20 15:09:43 +02001738 2,
1739 3
Bram Moolenaar9f4fe7c2014-07-03 22:57:55 +02001740];
Bram Moolenaar76f7fd32011-07-20 15:09:43 +02001741JSEND
1742
1743
1744JSSTART
1745function bar() {
1746 var foo = [
1747 1,
1748 2,
1749 3
Bram Moolenaar9f4fe7c2014-07-03 22:57:55 +02001750 ];
Bram Moolenaar76f7fd32011-07-20 15:09:43 +02001751}
1752JSEND
1753
1754
1755JSSTART
1756(function($){
1757
Bram Moolenaar81439a62014-07-02 18:27:48 +02001758 if (cond &&
1759 cond) {
1760 stmt;
1761 }
Bram Moolenaar9f4fe7c2014-07-03 22:57:55 +02001762 window.something.left =
1763 (width - 50 + offset) + "px";
Bram Moolenaar76f7fd32011-07-20 15:09:43 +02001764 var class_name='myclass';
1765
1766 function private_method() {
1767 }
1768
1769 var public_method={
1770 method: function(options,args){
1771 private_method();
1772 }
1773 }
1774
1775 function init(options) {
1776
1777 $(this).data(class_name+'_public',$.extend({},{
1778 foo: 'bar',
Bram Moolenaar9f4fe7c2014-07-03 22:57:55 +02001779 bar: 2,
1780 foobar: [
1781 1,
1782 2,
1783 3
Bram Moolenaar76f7fd32011-07-20 15:09:43 +02001784 ],
Bram Moolenaar9f4fe7c2014-07-03 22:57:55 +02001785 callback: function(){
1786 return true;
1787 }
Bram Moolenaar76f7fd32011-07-20 15:09:43 +02001788 }, options||{}));
1789 }
1790
1791 $.fn[class_name]=function() {
1792
1793 var _arguments=arguments;
1794 return this.each(function(){
1795
1796 var options=$(this).data(class_name+'_public');
1797 if (!options) {
1798 init.apply(this,_arguments);
1799
1800 } else {
1801 var method=public_method[_arguments[0]];
1802
1803 if (typeof(method)!='function') {
1804 console.log(class_name+' has no method "'+_arguments[0]+'"');
1805 return false;
1806 }
1807 _arguments[0]=options;
1808 method.apply(this,_arguments);
1809 }
1810 });
1811 }
1812
1813})(jQuery);
1814JSEND
1815
1816
1817JSSTART
1818function init(options) {
1819 $(this).data(class_name+'_public',$.extend({},{
1820 foo: 'bar',
1821 bar: 2,
1822 foobar: [
Bram Moolenaar9f4fe7c2014-07-03 22:57:55 +02001823 1,
1824 2,
1825 3
Bram Moolenaar76f7fd32011-07-20 15:09:43 +02001826 ],
1827 callback: function(){
1828 return true;
1829 }
1830 }, options||{}));
1831}
1832JSEND
1833
1834
1835JSSTART
1836(function($){
1837 function init(options) {
1838 $(this).data(class_name+'_public',$.extend({},{
1839 foo: 'bar',
Bram Moolenaar9f4fe7c2014-07-03 22:57:55 +02001840 bar: 2,
1841 foobar: [
1842 1,
1843 2,
1844 3
Bram Moolenaar76f7fd32011-07-20 15:09:43 +02001845 ],
Bram Moolenaar9f4fe7c2014-07-03 22:57:55 +02001846 callback: function(){
1847 return true;
1848 }
Bram Moolenaar76f7fd32011-07-20 15:09:43 +02001849 }, options||{}));
1850 }
1851})(jQuery);
1852JSEND
1853
Bram Moolenaardcefba92015-03-20 19:06:06 +01001854
1855JSSTART
1856// Results of JavaScript indent
1857// 1
1858(function(){
1859 var a = [
1860 'a',
1861 'b',
1862 'c',
1863 'd',
1864 'e',
1865 'f',
1866 'g',
1867 'h',
1868 'i'
1869 ];
1870}())
1871
1872// 2
1873(function(){
1874 var a = [
1875 0 +
1876 5 *
1877 9 *
1878 'a',
1879 'b',
1880 0 +
1881 5 *
1882 9 *
1883 'c',
1884 'd',
1885 'e',
1886 'f',
1887 'g',
1888 'h',
1889 'i'
1890 ];
1891}())
1892
1893// 3
1894(function(){
1895 var a = [
1896 0 +
1897 // comment 1
1898 5 *
1899 /* comment 2 */
1900 9 *
1901 'a',
1902 'b',
1903 0 +
1904 5 *
1905 9 *
1906 'c',
1907 'd',
1908 'e',
1909 'f',
1910 'g',
1911 'h',
1912 'i'
1913 ];
1914}())
1915
1916// 4
1917{
1918 var a = [
1919 0,
1920 1
1921 ];
1922 var b;
1923 var c;
1924}
1925
1926// 5
1927{
1928 var a = [
1929 [
1930 0
1931 ],
1932 2,
1933 3
1934 ];
1935}
1936
1937// 6
1938{
1939 var a = [
1940 [
1941 0,
1942 1
1943 ],
1944 2,
1945 3
1946 ];
1947}
1948
1949// 7
1950{
1951 var a = [
1952 // [
1953 0,
1954 // 1
1955 // ],
1956 2,
1957 3
1958 ];
1959}
1960
1961// 8
1962var x = [
1963 (function(){
1964 var a,
1965 b,
1966 c,
1967 d,
1968 e,
1969 f,
1970 g,
1971 h,
1972 i;
1973 })
1974];
1975
1976// 9
1977var a = [
1978 0 +
1979 5 *
1980 9 *
1981 'a',
1982 'b',
1983 0 +
1984 5 *
1985 9 *
1986 'c',
1987 'd',
1988 'e',
1989 'f',
1990 'g',
1991 'h',
1992 'i'
1993];
1994
1995// 10
1996var a,
1997 b,
1998 c,
1999 d,
2000 e,
2001 f,
2002 g,
2003 h,
2004 i;
2005JSEND
2006