summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane2017-06-20 19:27:29 +0000
committerTom Lane2017-06-20 19:27:29 +0000
commitdc8b3f67104281db426fe1c4676440e65b92d32b (patch)
tree68a899752bdd52bc965f1c118da70d5f37357132
parent9b87c99ae52f97628ce02ee023f7530b1d730668 (diff)
Add feature patch for -tpg/-ntpg.
This switch enables using Postgres' rules for using tabs vs spaces in indents, to match the output of our old "entab" program. The FreeBSD maintainer wants no part of this, so we'll have to carry this as a forked patch. (The alternative is to go over to use-tabs- whenever-possible rules, but that would result in circa 10K lines of invisible whitespace diffs in the PG sources, which seems like lots more pain than is justified.)
-rw-r--r--args.c2
-rw-r--r--indent.19
-rw-r--r--indent.c4
-rw-r--r--indent_globs.h1
-rw-r--r--io.c4
5 files changed, 18 insertions, 2 deletions
diff --git a/args.c b/args.c
index 73d8121..f79de75 100644
--- a/args.c
+++ b/args.c
@@ -154,6 +154,7 @@ struct pro {
{"nsac", PRO_BOOL, false, OFF, &space_after_cast},
{"nsc", PRO_BOOL, true, OFF, &star_comment_cont},
{"nsob", PRO_BOOL, false, OFF, &swallow_optional_blanklines},
+ {"ntpg", PRO_BOOL, false, OFF, &postgres_tab_rules},
{"nut", PRO_BOOL, true, OFF, &use_tabs},
{"nv", PRO_BOOL, false, OFF, &verbose},
{"pcs", PRO_BOOL, false, ON, &proc_calls_space},
@@ -163,6 +164,7 @@ struct pro {
{"sob", PRO_BOOL, false, ON, &swallow_optional_blanklines},
{"st", PRO_SPECIAL, 0, STDIN, 0},
{"ta", PRO_BOOL, false, ON, &auto_typedefs},
+ {"tpg", PRO_BOOL, false, ON, &postgres_tab_rules},
{"ts", PRO_INT, 8, 0, &tabsize},
{"ut", PRO_BOOL, true, ON, &use_tabs},
{"v", PRO_BOOL, false, ON, &verbose},
diff --git a/indent.1 b/indent.1
index 0a6ef06..131abfe 100644
--- a/indent.1
+++ b/indent.1
@@ -87,6 +87,7 @@
.Op Fl \&st
.Op Fl \&ta
.Op Fl T Ns Ar typename
+.Op Fl tpg | Fl ntpg
.Op Fl ts Ns Ar n
.Op Fl U Ns Ar file
.Op Fl ut | Fl nut
@@ -472,6 +473,14 @@ language and
cannot find all
instances of
.Ic typedef .
+.It Fl tpg , ntpg
+If
+.Fl tpg
+is specified, follow Postgres rules about when to use spaces versus
+tabs for indentation, that is, use a space instead of a tab if the
+tab would move only one column and no tab will follow it.
+Default:
+.Fl ntpg .
.It Fl ts Ns Ar n
Assumed distance between tab stops.
The default is 8.
diff --git a/indent.c b/indent.c
index d01d722..e6560af 100644
--- a/indent.c
+++ b/indent.c
@@ -1251,7 +1251,9 @@ indent_declaration(int cur_dec_ind, int tabs_to_var)
CHECK_SIZE_CODE(cur_dec_ind / tabsize);
while ((tpos = tabsize * (1 + pos / tabsize)) <= cur_dec_ind) {
- *e_code++ = '\t';
+ *e_code++ = (!postgres_tab_rules ||
+ tpos != pos + 1 ||
+ cur_dec_ind >= tpos + tabsize) ? '\t' : ' ';
pos = tpos;
}
}
diff --git a/indent_globs.h b/indent_globs.h
index ade80e5..d018af1 100644
--- a/indent_globs.h
+++ b/indent_globs.h
@@ -220,6 +220,7 @@ int use_tabs; /* set true to use tabs for spacing,
int auto_typedefs; /* set true to recognize identifiers
* ending in "_t" like typedefs */
int space_after_cast; /* "b = (int) a" vs "b = (int)a" */
+int postgres_tab_rules; /* use Postgres tab-vs-space rules */
int tabsize; /* the size of a tab */
int else_endif_com_ind; /* the column in which comments to
* the right of #else and #endif
diff --git a/io.c b/io.c
index 0792df0..df11094 100644
--- a/io.c
+++ b/io.c
@@ -401,7 +401,9 @@ pad_output(int current, int target)
int tcur;
while ((tcur = tabsize * (1 + (curr - 1) / tabsize) + 1) <= target) {
- putc('\t', output);
+ putc((!postgres_tab_rules ||
+ tcur != curr + 1 ||
+ target >= tcur + tabsize) ? '\t' : ' ', output);
curr = tcur;
}
}