Home | History | Annotate | Line # | Download | only in indent
opt_eei.c revision 1.8
      1  1.8  rillig /* $NetBSD: opt_eei.c,v 1.8 2022/04/24 09:04:12 rillig Exp $ */
      2  1.1  rillig 
      3  1.3  rillig /*
      4  1.3  rillig  * Tests for the options '-eei' and '-neei'.
      5  1.3  rillig  *
      6  1.3  rillig  * The option '-eei' enables extra indentation on continuation lines of the
      7  1.3  rillig  * expression part of 'if' and 'while' statements. These continuation lines
      8  1.3  rillig  * are indented one extra level.
      9  1.3  rillig  *
     10  1.3  rillig  * The option '-neei' indents these conditions in the same way as all other
     11  1.3  rillig  * continued statements.
     12  1.3  rillig  */
     13  1.3  rillig 
     14  1.8  rillig //indent input
     15  1.1  rillig bool
     16  1.1  rillig less(int a, int b)
     17  1.1  rillig {
     18  1.1  rillig 	if (a <
     19  1.1  rillig 	    b)
     20  1.1  rillig 		return true;
     21  1.1  rillig 	if (a
     22  1.1  rillig 	    <
     23  1.1  rillig 	    b)
     24  1.1  rillig 		return true;
     25  1.1  rillig }
     26  1.8  rillig //indent end
     27  1.1  rillig 
     28  1.8  rillig //indent run -eei
     29  1.1  rillig bool
     30  1.1  rillig less(int a, int b)
     31  1.1  rillig {
     32  1.1  rillig 	if (a <
     33  1.1  rillig 			b)
     34  1.1  rillig 		return true;
     35  1.1  rillig 	if (a
     36  1.1  rillig 			<
     37  1.1  rillig 			b)
     38  1.1  rillig 		return true;
     39  1.1  rillig }
     40  1.8  rillig //indent end
     41  1.1  rillig 
     42  1.8  rillig //indent run-equals-input -neei
     43  1.3  rillig 
     44  1.3  rillig /*
     45  1.6  rillig  * When a single indentation level is the same as the continuation
     46  1.6  rillig  * indentation, the code does not clearly show whether the 'b' belongs to the
     47  1.6  rillig  * condition or the body statement.
     48  1.3  rillig  */
     49  1.8  rillig //indent run -neei -i4
     50  1.3  rillig bool
     51  1.3  rillig less(int a, int b)
     52  1.3  rillig {
     53  1.3  rillig     if (a <
     54  1.3  rillig 	b)
     55  1.3  rillig 	return true;
     56  1.3  rillig     if (a
     57  1.3  rillig 	<
     58  1.3  rillig 	b)
     59  1.3  rillig 	return true;
     60  1.3  rillig }
     61  1.8  rillig //indent end
     62  1.3  rillig 
     63  1.3  rillig /*
     64  1.3  rillig  * Adding the extra level of indentation is useful when the standard
     65  1.3  rillig  * indentation is the same as the indentation of statement continuations. In
     66  1.3  rillig  * such a case, the continued condition would have the same indentation as the
     67  1.3  rillig  * following statement, which would be confusing.
     68  1.3  rillig  */
     69  1.8  rillig //indent run -eei -i4
     70  1.3  rillig bool
     71  1.3  rillig less(int a, int b)
     72  1.3  rillig {
     73  1.3  rillig     if (a <
     74  1.3  rillig 	    b)
     75  1.3  rillig 	return true;
     76  1.3  rillig     if (a
     77  1.3  rillig 	    <
     78  1.3  rillig 	    b)
     79  1.3  rillig 	return true;
     80  1.3  rillig }
     81  1.8  rillig //indent end
     82  1.5  rillig 
     83  1.5  rillig /*
     84  1.5  rillig  * With an indentation size of 4, the width of the code 'if (' is exactly one
     85  1.5  rillig  * indentation level. With the option '-nlp', the option '-eei' has no effect.
     86  1.5  rillig  *
     87  1.5  rillig  * XXX: This is unexpected since this creates the exact ambiguity that the
     88  1.5  rillig  * option '-eei' is supposed to prevent.
     89  1.5  rillig  */
     90  1.8  rillig //indent run -eei -i4 -nlp
     91  1.5  rillig bool
     92  1.5  rillig less(int a, int b)
     93  1.5  rillig {
     94  1.5  rillig     if (a <
     95  1.5  rillig 	b)
     96  1.5  rillig 	return true;
     97  1.5  rillig     if (a
     98  1.5  rillig 	<
     99  1.5  rillig 	b)
    100  1.5  rillig 	return true;
    101  1.5  rillig }
    102  1.8  rillig //indent end
    103  1.5  rillig 
    104  1.5  rillig 
    105  1.5  rillig /*
    106  1.5  rillig  * The option '-eei' applies no matter whether the continued expression starts
    107  1.5  rillig  * with a word or an operator like '&&'. The latter cannot start a statement,
    108  1.5  rillig  * so there would be no ambiguity.
    109  1.5  rillig  */
    110  1.8  rillig //indent input
    111  1.5  rillig {
    112  1.5  rillig 	if (a
    113  1.5  rillig && b)
    114  1.5  rillig 	    stmt();
    115  1.5  rillig }
    116  1.8  rillig //indent end
    117  1.5  rillig 
    118  1.5  rillig /*
    119  1.5  rillig  * XXX: The extra indentation is unnecessary since there is no possible
    120  1.5  rillig  * confusion: the standard indentation is 8, the indentation of the continued
    121  1.5  rillig  * condition could have stayed at 4.
    122  1.5  rillig  */
    123  1.8  rillig //indent run -eei
    124  1.5  rillig {
    125  1.5  rillig 	if (a
    126  1.5  rillig 			&& b)
    127  1.5  rillig 		stmt();
    128  1.5  rillig }
    129  1.8  rillig //indent end
    130  1.5  rillig 
    131  1.5  rillig /*
    132  1.5  rillig  * The extra indentation is necessary here since otherwise the '&&' and the
    133  1.5  rillig  * 'stmt()' would start at the same indentation.
    134  1.5  rillig  */
    135  1.8  rillig //indent run -eei -i4
    136  1.5  rillig {
    137  1.5  rillig     if (a
    138  1.5  rillig 	    && b)
    139  1.5  rillig 	stmt();
    140  1.5  rillig }
    141  1.8  rillig //indent end
    142  1.5  rillig 
    143  1.5  rillig /*
    144  1.5  rillig  * With an indentation size of 4, the width of the code 'if (' is exactly one
    145  1.5  rillig  * indentation level. With the option '-nlp', the option '-eei' has no effect.
    146  1.5  rillig  *
    147  1.5  rillig  * XXX: This is unexpected since this creates the exact ambiguity that the
    148  1.5  rillig  * option '-eei' is supposed to prevent.
    149  1.5  rillig  */
    150  1.8  rillig //indent run -eei -i4 -nlp
    151  1.5  rillig {
    152  1.5  rillig     if (a
    153  1.5  rillig 	&& b)
    154  1.5  rillig 	stmt();
    155  1.5  rillig }
    156  1.8  rillig //indent end
    157