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