Added an option -ldi<N> to control indentation of local variable names.
The default is to be backwards compatible and non-KNF (use the same indentation for locals as for globals; -ldi0 gives KNF indentation for locals (none)). The indentation for globals also applies to struct member names in local declatations. The indentation of variable names in multi-line declarations is broken in various ways and this commit gives some new variations. indent.1: Also clarified the description of -di<N>.
This commit is contained in:
parent
7b3b38c6db
commit
88ce0e7f7e
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=125633
@ -121,6 +121,7 @@ struct pro {
|
||||
{"ip", PRO_BOOL, true, ON, &ps.indent_parameters},
|
||||
{"i", PRO_INT, 8, 0, &ps.ind_size},
|
||||
{"lc", PRO_INT, 0, 0, &block_comment_max_col},
|
||||
{"ldi", PRO_INT, -1, 0, &ps.local_decl_indent},
|
||||
{"lp", PRO_BOOL, true, ON, &lineup_to_parens},
|
||||
{"l", PRO_INT, 78, 0, &max_col},
|
||||
{"nbacc", PRO_BOOL, false, OFF, &blanklines_around_conditional_compilation},
|
||||
|
@ -69,6 +69,7 @@
|
||||
.Op Fl \&ip | Fl nip
|
||||
.Op Fl l Ns Ar n
|
||||
.Op Fl \&lc Ns Ar n
|
||||
.Op Fl \&ldi Ns Ar n
|
||||
.Op Fl \&lp | Fl nlp
|
||||
.Op Fl npro
|
||||
.Op Fl pcs | Fl npcs
|
||||
@ -219,8 +220,10 @@ left of code. Specifying the default
|
||||
lines-up these comments with the code. See the section on comment
|
||||
indentation below.
|
||||
.It Fl \&di Ns Ar n
|
||||
Specifies the indentation, in character positions, from a declaration keyword
|
||||
to the following identifier. The default is
|
||||
Specifies the indentation, in character positions,
|
||||
of global variable names and all struct/union member names
|
||||
relative to the beginning of their type declaration.
|
||||
The default is
|
||||
.Fl di16 .
|
||||
.It Fl dj , ndj
|
||||
.Fl \&dj
|
||||
@ -267,6 +270,12 @@ margin. The default is
|
||||
.Fl \&ip .
|
||||
.It Fl l Ns Ar n
|
||||
Maximum length of an output line. The default is 78.
|
||||
.It Fl \&ldi Ns Ar n
|
||||
Specifies the indentation, in character positions,
|
||||
of local variable names
|
||||
relative to the beginning of their type declaration.
|
||||
The default is for local variable names to be indented
|
||||
by the same amount as global ones.
|
||||
.It Fl \&lp , nlp
|
||||
Lines-up code surrounded by parenthesis in continuation lines. If a line
|
||||
has a left paren which is not closed on that line, then continuation lines
|
||||
|
@ -168,6 +168,9 @@ main(int argc, char **argv)
|
||||
ps.ind_size = 8; /* -i8 */
|
||||
verbose = 0;
|
||||
ps.decl_indent = 16; /* -di16 */
|
||||
ps.local_decl_indent = -1; /* if this is not set to some nonnegative value
|
||||
* by an arg, we will set this equal to
|
||||
* ps.decl_ind */
|
||||
ps.indent_parameters = 1; /* -ip */
|
||||
ps.decl_com_ind = 0; /* if this is not set to some positive value
|
||||
* by an arg, we will set this equal to
|
||||
@ -254,6 +257,8 @@ main(int argc, char **argv)
|
||||
}
|
||||
if (block_comment_max_col <= 0)
|
||||
block_comment_max_col = max_col;
|
||||
if (ps.local_decl_indent < 0) /* if not specified by user, set this */
|
||||
ps.local_decl_indent = ps.decl_indent;
|
||||
if (ps.decl_com_ind <= 0) /* if not specified by user, set this */
|
||||
ps.decl_com_ind = ps.ljust_decl ? (ps.com_ind <= 10 ? 2 : ps.com_ind - 8) : ps.com_ind;
|
||||
if (continuation_indent == 0)
|
||||
@ -906,8 +911,15 @@ main(int argc, char **argv)
|
||||
prefix_blankline_requested = 0;
|
||||
for (i = 0; token[i++];); /* get length of token */
|
||||
|
||||
dec_ind = ps.decl_indent > 0 ? ps.decl_indent : i;
|
||||
use_tabs = ps.decl_indent > 0;
|
||||
if (ps.ind_level == 0 || ps.dec_nest > 0) {
|
||||
/* global variable or struct member in local variable */
|
||||
dec_ind = ps.decl_indent > 0 ? ps.decl_indent : i;
|
||||
use_tabs = ps.decl_indent > 0;
|
||||
} else {
|
||||
/* local variable */
|
||||
dec_ind = ps.local_decl_indent > 0 ? ps.local_decl_indent : i;
|
||||
use_tabs = ps.local_decl_indent > 0;
|
||||
}
|
||||
goto copy_id;
|
||||
|
||||
case ident: /* got an identifier or constant */
|
||||
|
@ -303,6 +303,7 @@ struct parser_state {
|
||||
int else_if; /* True iff else if pairs should be handled
|
||||
* specially */
|
||||
int decl_indent; /* column to indent declared identifiers to */
|
||||
int local_decl_indent; /* like decl_indent but for locals */
|
||||
int its_a_keyword;
|
||||
int sizeof_keyword;
|
||||
int dumped_decl_indent;
|
||||
|
Loading…
Reference in New Issue
Block a user