Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/indent indent: in comments, keep a leading tab



details:   https://anonhg.NetBSD.org/src/rev/1ec24a373d0f
branches:  trunk
changeset: 375311:1ec24a373d0f
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun May 14 17:13:37 2023 +0000

description:
indent: in comments, keep a leading tab

This kind of comments is used for the CVS IDs at the top of files.

diffstat:

 tests/usr.bin/indent/opt_fc1.c |   8 ++++----
 usr.bin/indent/pr_comment.c    |  12 ++++++------
 2 files changed, 10 insertions(+), 10 deletions(-)

diffs (68 lines):

diff -r 7f118440aa2c -r 1ec24a373d0f tests/usr.bin/indent/opt_fc1.c
--- a/tests/usr.bin/indent/opt_fc1.c    Sun May 14 16:47:06 2023 +0000
+++ b/tests/usr.bin/indent/opt_fc1.c    Sun May 14 17:13:37 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: opt_fc1.c,v 1.9 2023/05/13 16:40:18 rillig Exp $ */
+/* $NetBSD: opt_fc1.c,v 1.10 2023/05/14 17:13:37 rillig Exp $ */
 
 /*
  * Tests for the options '-fc1' and '-nfc1'.
@@ -55,8 +55,8 @@
 /* $ The indentation got removed. */
 /* space */
 
-/* $ The indentation got removed, only the leading tab got replaced by a space. */
-/* indented tab        */
+/* $ The indentation got removed. */
+/*     indented tab    */
 
 /* $ The space between these comments got removed. */
 /* block1 *//* block2 */
@@ -76,7 +76,7 @@
  /* space */
 
 /* $ The indentation was changed from a single tab to a single space. */
- /* indented tab       */
+ /*    indented tab    */
 
 /* $ The space between these two comments got removed. */
 /* $ XXX: The option '-nfc1' says that comments in column 1 do not get */
diff -r 7f118440aa2c -r 1ec24a373d0f usr.bin/indent/pr_comment.c
--- a/usr.bin/indent/pr_comment.c       Sun May 14 16:47:06 2023 +0000
+++ b/usr.bin/indent/pr_comment.c       Sun May 14 17:13:37 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pr_comment.c,v 1.135 2023/05/14 16:47:06 rillig Exp $  */
+/*     $NetBSD: pr_comment.c,v 1.136 2023/05/14 17:13:37 rillig Exp $  */
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -38,7 +38,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: pr_comment.c,v 1.135 2023/05/14 16:47:06 rillig Exp $");
+__RCSID("$NetBSD: pr_comment.c,v 1.136 2023/05/14 17:13:37 rillig Exp $");
 
 #include <string.h>
 
@@ -145,16 +145,16 @@ analyze_comment(bool *p_may_wrap, bool *
        ps.n_comment_delta = -ind_add(0, inp_line_start(), inp_p() - 2);
     } else {
        ps.n_comment_delta = 0;
-       while (ch_isblank(inp_peek()))
-           inp_skip();
+       if (!(inp_peek() == '\t' && !ch_isblank(inp_lookahead(1))))
+           while (ch_isblank(inp_peek()))
+               inp_skip();
     }
 
     ps.comment_delta = 0;
     com_add_char('/');
     com_add_char(token.e[-1]); /* either '*' or '/' */
 
-    /* TODO: Maybe preserve a single '\t' as well. */
-    if (inp_peek() != ' ' && may_wrap)
+    if (may_wrap && !ch_isblank(inp_peek()))
        com_add_char(' ');
 
     if (break_delim && fits_in_one_line(com_ind, adj_max_line_length))



Home | Main Index | Thread Index | Old Index