indent: right-trim single-line comments
This commit is contained in:
parent
c417c79de7
commit
9f9251e958
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: lsym_comment.c,v 1.17 2023/06/06 05:39:49 rillig Exp $ */
|
||||
/* $NetBSD: lsym_comment.c,v 1.18 2023/06/06 07:51:35 rillig Exp $ */
|
||||
|
||||
/*
|
||||
* Tests for the token lsym_comment, which starts a comment.
|
||||
|
@ -371,18 +371,28 @@ tab1+++ tab2--- tab3+++ tab4--- tab5+++ tab6--- tab7+++fixed comment*/
|
|||
|
||||
|
||||
/*
|
||||
* TODO: Trailing whitespace in a comment is ignored when determining whether the
|
||||
* comment fits in a single line.
|
||||
* When determining whether the comment fits in a single line, only the first
|
||||
* trailing space or tab is kept, the others are removed.
|
||||
*/
|
||||
//indent input
|
||||
/* tab: */
|
||||
/* 456789 123456789 123456789 12345 */
|
||||
/* 456789 123456789 123456789 123456 */
|
||||
/* space: */
|
||||
/* 456789 123456789 123456789 12345 */
|
||||
/* 456789 123456789 123456789 123456 */
|
||||
//indent end
|
||||
|
||||
//indent run -l38
|
||||
/* tab: */
|
||||
/*
|
||||
* 456789 123456789 123456789 12345
|
||||
*/
|
||||
/*
|
||||
* 456789 123456789 123456789 123456
|
||||
*/
|
||||
/* space: */
|
||||
/* 456789 123456789 123456789 12345 */
|
||||
/*
|
||||
* 456789 123456789 123456789 123456
|
||||
*/
|
||||
|
@ -965,7 +975,7 @@ int
|
|||
f(void)
|
||||
{
|
||||
if (0)
|
||||
/* 12 1234 123 123456 1234 1234567 123 1234. */;
|
||||
/* 12 1234 123 123456 1234 1234567 123 1234. */;
|
||||
}
|
||||
//indent end
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: pr_comment.c,v 1.154 2023/06/06 07:14:20 rillig Exp $ */
|
||||
/* $NetBSD: pr_comment.c,v 1.155 2023/06/06 07:51:35 rillig Exp $ */
|
||||
|
||||
/*-
|
||||
* SPDX-License-Identifier: BSD-4-Clause
|
||||
|
@ -38,7 +38,7 @@
|
|||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__RCSID("$NetBSD: pr_comment.c,v 1.154 2023/06/06 07:14:20 rillig Exp $");
|
||||
__RCSID("$NetBSD: pr_comment.c,v 1.155 2023/06/06 07:51:35 rillig Exp $");
|
||||
|
||||
#include <string.h>
|
||||
|
||||
|
@ -62,6 +62,10 @@ fits_in_one_line(int com_ind, int max_line_length)
|
|||
{
|
||||
for (const char *start = inp_p, *p = start; *p != '\n'; p++) {
|
||||
if (p[0] == '*' && p[1] == '/') {
|
||||
while (p - inp_p >= 2
|
||||
&& ch_isblank(p[-1])
|
||||
&& ch_isblank(p[-2]))
|
||||
p--;
|
||||
int len = ind_add(com_ind + 3,
|
||||
start, (size_t)(p - start));
|
||||
len += p == start || ch_isblank(p[-1]) ? 2 : 3;
|
||||
|
@ -257,6 +261,11 @@ copy_comment_wrap_finish(int line_length, bool delim)
|
|||
output_line();
|
||||
}
|
||||
|
||||
while (com.len >= 2
|
||||
&& ch_isblank(com.s[com.len - 1])
|
||||
&& ch_isblank(com.s[com.len - 2]))
|
||||
com.len--;
|
||||
|
||||
inp_p += 2;
|
||||
if (com.len > 0 && ch_isblank(com.s[com.len - 1]))
|
||||
buf_add_chars(&com, "*/", 2);
|
||||
|
|
Loading…
Reference in New Issue