Package: indent
Version: 2.2.9-9
Severity: wishlist

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.
 
[EMAIL PROTECTED] [EMAIL PROTECTED]
[EMAIL PROTECTED] [EMAIL PROTECTED]
+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
[EMAIL PROTECTED] parameter for that.
+
 @kindex [EMAIL PROTECTED]
 @kindex [EMAIL PROTECTED]
 @kindex -nip
@@ -1656,6 +1666,11 @@
 Set maximum line length for comment formatting to @[EMAIL PROTECTED]
 @xref{Comments}.
 
[EMAIL PROTECTED] [EMAIL PROTECTED]
[EMAIL PROTECTED] [EMAIL PROTECTED]
+Set indentation for labels to @[EMAIL PROTECTED]
[EMAIL PROTECTED]
+
 @item -lp
 @itemx --continue-at-parentheses
 Line up continued lines at [EMAIL PROTECTED]
--- 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"},

-- 
"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."


-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]

Reply via email to