bug-indent
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Allow customising goto label indentation


From: david
Subject: Re: Allow customising goto label indentation
Date: Mon, 01 Oct 2007 18:02:51 +0200
User-agent: Thunderbird 1.5.0.12 (X11/20060911)

To submit a update that supports a new feature two more things beside
the code itself are needed:

1) an update to indent.texinfo that describes the new feature at all
relevant locations in the document.

2) updates to the regression tests that demonstrate correct working of
the feature:

        regression/TEST         - runs indent with the required options
on your <name>.c sample code
        regression/<name>.c   - new code sample pre application of intent
        regression/standard/<name>.c - code sample that shows correctly
applied indentation with your feature active.

3) you should have also verified that all the existing regression tests
still work correctly.

Matthew Wilcox wrote:
> ... ping ...
>
> On Thu, Sep 13, 2007 at 08:22:26AM -0600, Matthew Wilcox wrote:
>   
>> [I sent this to the Debian bug-tracking system a couple of months ago.
>> There's been no response to it, so I dug around a bit and found this
>> mailing list]
>>
>> I like my source code to have a one space indent before the goto label,
>> like this:
>>
>> int foo(void)
>> {
>>      bar();
>>  quux:
>> }
>>
>> The current code hardcodes an indentation of two columns less than the
>> current indentation.  This patch allows you to configure a negative
>> displacement from the current indent level, or a positive absolute
>> displacement.  So I can now invoke indent as:
>>
>> $ indent -kr -i8 -li1
>>
>> and get the style I prefer.
>>
>> Notice that -li0 will give you a label in the first column.  -li-2 will
>> give the current, and default behaviour.
>>
>> Here's the patch to implement that.  I even added documentation!
>>
>> diff -u indent-2.2.9/src/indent.h indent-2.2.9/src/indent.h
>> --- indent-2.2.9/src/indent.h
>> +++ indent-2.2.9/src/indent.h
>> @@ -80,6 +80,8 @@
>>  
>>  #define DEFAULT_RIGHT_COMMENT_MARGIN 78
>>  
>> +#define DEFAULT_LABEL_INDENT -2
>> +
>>  /* Name of input file.  */
>>  extern char *in_name;
>>  
>> @@ -201,6 +203,7 @@
>>      int leave_preproc_space; /* if true, leave the spaces between  '#' and 
>> preprocessor commands. */
>>      int force_preproc_width; /* if this is >0, this becomes the preproc 
>> indent-level */
>>      int lineup_to_parens;    /* if true, continued code within parens will 
>> be lined up to the open paren */
>> +    int label_indent;            /* if >0 an absolute indent, if <0 
>> relative to curret indent level */
>>      int honour_newlines;     /* True when positions at which we read a 
>> newline in the input file, should get
>>                                * a high priority to break long lines at. */
>>      int format_comments; /* If any comments are to be reformatted */
>> --- indent-2.2.9.orig/doc/indent.texinfo
>> +++ indent-2.2.9/doc/indent.texinfo
>> @@ -1188,6 +1188,16 @@
>>  columns wide, but (as of version 1.2) may be changed by the @option{-ts}
>>  option.  Tabs are treated as the equivalent number of spaces.
>>  
>> address@hidden address@hidden
>> address@hidden address@hidden
>> +The indentation of goto labels is controlled by the @option{-li} parameter. 
>>  If
>> +it is set to zero or a positive number, this indicates how far from the left
>> +margin to indent a label.  If it is set to a negative number, this indicates
>> +how far back from the current indent level to place the label.  The default
>> +setting is -2 which matches the behaviour of earlier versions of indent.
>> +Note that this parameter does not affect the placing of case labels; see the
>> address@hidden parameter for that.
>> +
>>  @kindex address@hidden
>>  @kindex address@hidden
>>  @kindex -nip
>> @@ -1656,6 +1666,11 @@
>>  Set maximum line length for comment formatting to @address@hidden
>>  @xref{Comments}.
>>  
>> address@hidden address@hidden
>> address@hidden address@hidden
>> +Set indentation for labels to @address@hidden
>> address@hidden
>> +
>>  @item -lp
>>  @itemx --continue-at-parentheses
>>  Line up continued lines at address@hidden
>> --- indent-2.2.9.orig/src/io.c
>> +++ indent-2.2.9/src/io.c
>> @@ -54,9 +54,6 @@
>>  
>>  RCSTAG_CC ("$Id: io.c,v 1.50 2002/08/04 17:08:41 david Exp $");
>>  
>> -/* number of levels a label is placed to left of code */
>> -#define LABEL_OFFSET 2
>> -
>>  
>> /******************************************************************************/
>>  /* Stuff that needs to be shared with the rest of indent. Documented in
>>   * indent.h.
>> @@ -312,9 +309,14 @@
>>          /* FIXME: does this belong here at all? */
>>          return 1;
>>      }
>> +
>> +    if (settings.label_indent < 0)
>> +    {
>> +        return parser_state_tos->ind_level + settings.label_indent + 1;
>> +    }
>>      else
>>      {
>> -        return parser_state_tos->ind_level - LABEL_OFFSET + 1;
>> +        return settings.label_indent + 1;
>>      }
>>  }
>>  
>> --- indent-2.2.9.orig/src/args.c
>> +++ indent-2.2.9/src/args.c
>> @@ -125,6 +125,7 @@
>>  static int exp_kr   = 0;
>>  static int exp_l    = 0;
>>  static int exp_lc   = 0;
>> +static int exp_li   = 0;
>>  static int exp_lp   = 0;
>>  static int exp_lps  = 0;
>>  static int exp_nip  = 0; 
>> @@ -252,6 +253,7 @@
>>      {"nbacc",   PRO_BOOL,                           false,      OFF, 
>> &settings.blanklines_around_conditional_compilation, &exp_bacc},
>>      {"lps",     PRO_BOOL,                           false,       ON, 
>> &settings.leave_preproc_space,              &exp_lps},
>>      {"lp",      PRO_BOOL,                            true,       ON, 
>> &settings.lineup_to_parens,                 &exp_lp},
>> +    {"li",      PRO_INT,             DEFAULT_LABEL_INDENT, ONOFF_NA, 
>> &settings.label_indent,                     &exp_li},
>>      {"lc",      PRO_INT,     DEFAULT_RIGHT_COMMENT_MARGIN, ONOFF_NA, 
>> &settings.comment_max_col,                  &exp_lc},
>>      {"l",       PRO_INT,             DEFAULT_RIGHT_MARGIN, ONOFF_NA, 
>> &settings.max_col,                          &exp_l},
>>      {"kr",      PRO_SETTINGS,                           0, ONOFF_NA, 
>> KR_SETTINGS_STRING,                         &exp_kr},
>> @@ -365,6 +367,7 @@
>>      {"nbacc",   PRO_BOOL,                           false,      OFF, 
>> &settings.blanklines_around_conditional_compilation, &exp_bacc},
>>      {"lps",     PRO_BOOL,                           false,       ON, 
>> &settings.leave_preproc_space,              &exp_lps},
>>      {"lp",      PRO_BOOL,                            true,       ON, 
>> &settings.lineup_to_parens,                 &exp_lp},
>> +    {"li",      PRO_INT,             DEFAULT_LABEL_INDENT, ONOFF_NA, 
>> &settings.label_indent,                     &exp_li},
>>      {"lc",      PRO_INT,     DEFAULT_RIGHT_COMMENT_MARGIN, ONOFF_NA, 
>> &settings.comment_max_col,                  &exp_lc},
>>      {"l",       PRO_INT,             DEFAULT_RIGHT_MARGIN, ONOFF_NA, 
>> &settings.max_col,                          &exp_l},
>>      {"kr",      PRO_SETTINGS,                           0, ONOFF_NA, 
>> KR_SETTINGS_STRING,                         &exp_kr},
>> @@ -475,6 +478,7 @@
>>      {"left-justify-declarations",                   "dj"},
>>      {"leave-preprocessor-space",                    "lps"},
>>      {"leave-optional-blank-lines",                  "nsob"},
>> +    {"label-indentation",                           "li"},
>>      {"kernighan-and-ritchie-style",                 "kr"},
>>      {"kernighan-and-ritchie",                       "kr"},
>>      {"k-and-r-style",                               "kr"},
>>
>> -- 
>> Intel are signing my paycheques ... these opinions are still mine
>> "Bill, look, we understand that you're interested in selling us this
>> operating system, but compare it to ours.  We can't possibly take such
>> a retrograde step."
>>     
>
>   





reply via email to

[Prev in Thread] Current Thread [Next in Thread]