[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 7/9] Don't tab-align comments (-ntac)
From: |
Tim Hentenaar |
Subject: |
[PATCH 7/9] Don't tab-align comments (-ntac) |
Date: |
Wed, 17 Jun 2015 20:56:03 +0200 |
Added an option (-ntac/--dont-tab-align-comments) which if specified
prevents indent from automagically pushing comments out to the
nearest tabstop.
---
ChangeLog | 3 +++
doc/indent.texi | 12 +++++++++++-
regression/TEST | 3 ++-
regression/input/dont-tab-align-comments.c | 7 +++++++
regression/standard/dont-tab-align-comments.c | 8 ++++++++
src/args.c | 4 ++++
src/comments.c | 2 +-
src/indent.h | 1 +
8 files changed, 37 insertions(+), 3 deletions(-)
create mode 100644 regression/input/dont-tab-align-comments.c
create mode 100644 regression/standard/dont-tab-align-comments.c
diff --git a/ChangeLog b/ChangeLog
index d7786b0..96bc261 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -7,6 +7,9 @@
combuf by looping and incrememnting e_com.
* indent.c: Don't force a newline after an rbrace and before a
comma in a block initializer.
+ * Added an option (-ntac/--dont-tab-align-comments) which if specified
+ prevents indent from automagically pushing comments out to the
+ nearest tabstoo.
2015-06-16 Tim Hentenaar <address@hidden>
* Use want_blank instead of copying a space to e_code to avoid
diff --git a/doc/indent.texi b/doc/indent.texi
index 862aac0..a02daee 100644
--- a/doc/indent.texi
+++ b/doc/indent.texi
@@ -679,6 +679,8 @@ two spaces to the left of code. By default, comments are
aligned with
code, unless they begin in the first column, in which case they are left
there by default --- to get them aligned with the code, specify @option{-fc1}.
address@hidden -ntac
address@hidden --dont-tab-align-comments
@kindex address@hidden
@kindex address@hidden
@kindex address@hidden
@@ -701,7 +703,8 @@ causes @option{-c} to become effective.
If the code to the left of the comment exceeds the beginning column,
the comment column will be extended to the next tabstop column past
-the end of the code, or in the case of preprocessor directives, to one
+the end of the code, unless the @option{-ntac} option is specified.
+In the case of preprocessor directives,comments are extended to to one
space past the end of the directive. This extension lasts only for
the output of that particular comment.
@@ -2178,6 +2181,11 @@ Do not force a space before the semicolon after certain
statements.
Disables @address@hidden
@xref{Statements}.
address@hidden -ntac
address@hidden --dont-tab-align-comments
+Do not pad comments out to the nearest address@hidden
address@hidden
+
@item -nut
@itemx --no-tabs
Use spaces instead of address@hidden
@@ -2367,6 +2375,7 @@ the corresponding short option.
\line{ --dont-line-up-parentheses \leaderfill -nlp\ }
\line{ --dont-space-special-semicolon \leaderfill -nss\ }
\line{ --dont-star-comments \leaderfill -nsc\ }
+\line{ --dont-tab-align-comments \leaderfill -ntac\ }
\line{ --else-endif-column \leaderfill address@hidden }
\line{ --format-all-comments \leaderfill -fca\ }
\line{ --format-first-column-comments \leaderfill -fc1\ }
@@ -2461,6 +2470,7 @@ the corresponding short option.
--dont-left-justify-declarations -ndj
--dont-space-special-semicolon -nss
--dont-star-comments -nsc
+--dont-tab-align-comments -ntac
--else-endif-column address@hidden
--format-all-comments -fca
--format-first-column-comments -fc1
diff --git a/regression/TEST b/regression/TEST
index a5a7ec8..0311411 100755
--- a/regression/TEST
+++ b/regression/TEST
@@ -69,7 +69,7 @@ SPECIALS="typedef-bug.c bug-hp.c bug-di.c newlined-parms.c
indent.pro.c \
bad-comment.c unknown-type.c unknown-type-npsl.c bug-npsl.c bug-psl.c
do-cdw.c \
label.c goto-1.c goto-2.c line-count.c decl_block.c pointer-pal.c
else-comment-2-br.c else-comment-2-bl.c \
else-comment-2-br-ce.c preserve-newline-after-right-brace.c
gettext-strings.c single-line-conditionals.c \
- align-with-spaces.c no-space-after-fp-name.c
spaces-around-initializers.c"
+ align-with-spaces.c no-space-after-fp-name.c
spaces-around-initializers.c dont-tab-align-comments.c"
ARGS="-bad"
$INDENT -npro $ARGS input/bad-break.c -o output/bad-break.c
@@ -180,6 +180,7 @@ $INDENT -npro -slc input/single-line-conditionals.c -o
output/single-line-condit
$INDENT -npro -br -ut -i8 -l70 -ts8 -as input/align-with-spaces.c -o
output/align-with-spaces.c
$INDENT -npro -npcs input/fp.c -o output/no-space-after-fp-name.c
$INDENT -npro -sar input/spaces-around-initializers.c -o
output/spaces-around-initializers.c
+$INDENT -npro -c0 -ntac input/dont-tab-align-comments.c -o
output/dont-tab-align-comments.c
ARGS="-kr -cp0 -l132 -lps -br -psl"
$INDENT -npro $ARGS input/const.c -o output/const.c
diff --git a/regression/input/dont-tab-align-comments.c
b/regression/input/dont-tab-align-comments.c
new file mode 100644
index 0000000..7a4c000
--- /dev/null
+++ b/regression/input/dont-tab-align-comments.c
@@ -0,0 +1,7 @@
+struct zzz {
+ const char *a;
+} x[] = {
+ { "0" }, /* xxx */
+ { "999999999999999" }, /* yyy */
+ { "test123" } /* zzz */
+};
diff --git a/regression/standard/dont-tab-align-comments.c
b/regression/standard/dont-tab-align-comments.c
new file mode 100644
index 0000000..e36c347
--- /dev/null
+++ b/regression/standard/dont-tab-align-comments.c
@@ -0,0 +1,8 @@
+struct zzz
+{
+ const char *a;
+} x[] = {
+ {"0"}, /* xxx */
+ {"999999999999999"}, /* yyy */
+ {"test123"} /* zzz */
+};
diff --git a/src/args.c b/src/args.c
index 1951749..1e78c73 100644
--- a/src/args.c
+++ b/src/args.c
@@ -208,6 +208,7 @@ static int exp_par = 0;
static int exp_slc = 0;
static int exp_as = 0;
static int exp_sar = 0;
+static int exp_ntac = 0;
/**
* The following structure is controlled by command line parameters and
@@ -375,6 +376,7 @@ const pro_ty pro[] =
{"slc", PRO_BOOL, false, ON,
&settings.allow_single_line_conditionals, &exp_slc},
{"as", PRO_BOOL, false, ON,
&settings.align_with_spaces, &exp_as},
{"sar", PRO_BOOL, false, ON,
&settings.spaces_around_initializers, &exp_sar},
+ {"ntac", PRO_BOOL, false, ON,
&settings.dont_tab_align_comments, &exp_ntac},
/* Signify end of structure. */
{0, PRO_IGN, 0, ONOFF_NA, 0,
0}
@@ -503,6 +505,7 @@ const pro_ty pro[] =
{"slc", PRO_BOOL, false, ON,
&settings.allow_single_line_conditionals, &exp_slc},
{"as", PRO_BOOL, false, ON,
&settings.align_with_spaces, &exp_as},
{"sar", PRO_BOOL, false, ON,
&settings.spaces_around_initializers, &exp_sar},
+ {"ntac", PRO_BOOL, false, ON,
&settings.dont_tab_align_comments, &exp_ntac},
/* Signify end of structure. */
{0, PRO_IGN, 0, ONOFF_NA, 0,
0}
@@ -641,6 +644,7 @@ const long_option_conversion_ty option_conversions[] =
{"single-line-conditionals", "slc"},
{"align-with-spaces", "as"},
{"spaces-around-initializers", "sar"},
+ {"dont-tab-align-comments", "ntac"},
/* Signify end of structure. */
{0, 0},
diff --git a/src/comments.c b/src/comments.c
index 600614e..6c9e94e 100644
--- a/src/comments.c
+++ b/src/comments.c
@@ -373,7 +373,7 @@ extern void print_comment(
/* If the too-long code is a pre-processor command,
start the comment 1 space afterwards, otherwise
start at the next tab mark. */
- if (else_or_endif)
+ if (else_or_endif || settings.dont_tab_align_comments)
{
start_column++;
else_or_endif = false;
diff --git a/src/indent.h b/src/indent.h
index 8adfeb2..f64b694 100644
--- a/src/indent.h
+++ b/src/indent.h
@@ -330,6 +330,7 @@ typedef struct user_options_st
int allow_single_line_conditionals; /*!< Don't indent the body of an
unbraced if, else, etc. */
int align_with_spaces; /*!< Align with spaces if indenting with tabs. */
int spaces_around_initializers; /*!< Place spaces after { and before } in
initializers. */
+ int dont_tab_align_comments; /*!< Don't align comments to the nearest
tabstop. */
} user_options_ty;
extern user_options_ty settings;
--
2.3.6
- [PATCH 0/9] More bugfixes, etc., Tim Hentenaar, 2015/06/17
- [PATCH 1/9] Add regressions mising from upstream, Tim Hentenaar, 2015/06/17
- [PATCH 4/9] scan_profile(): Make sure the buffers are initialized, Tim Hentenaar, 2015/06/17
- [PATCH 2/9] comments.c: Fix print_comment reading past the end of the buffer when reading less than a full comment from stdin., Tim Hentenaar, 2015/06/17
- [PATCH 8/9] -npcs: Fix recognition of function pointers, Tim Hentenaar, 2015/06/17
- [PATCH 6/9] indent.c: Don't force nl between rbrace and comma, Tim Hentenaar, 2015/06/17
- [PATCH 9/9] Add an install target to the regression Makefile, Tim Hentenaar, 2015/06/17
- [PATCH 3/9] Fix several potential memory leaks, Tim Hentenaar, 2015/06/17
- [PATCH 7/9] Don't tab-align comments (-ntac),
Tim Hentenaar <=
- [PATCH 5/9] comments.c: Fix heap corruption, Tim Hentenaar, 2015/06/17