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