Skip to content

Commit 7e66778

Browse files
committed
patch 8.2.5008: when 'formatoptions' contains "/" wrongly wrapping comment
Problem: When 'formatoptions' contains "/" wrongly wrapping a long trailing comment. Solution: Pass the OPENLINE_FORMAT flag.
1 parent 6d24b4f commit 7e66778

File tree

5 files changed

+29
-7
lines changed

5 files changed

+29
-7
lines changed

src/change.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1643,7 +1643,8 @@ open_line(
16431643
lead_len = get_leader_len(saved_line, &lead_flags,
16441644
dir == BACKWARD, TRUE);
16451645
if (lead_len == 0 && curbuf->b_p_cin && do_cindent && dir == FORWARD
1646-
&& !has_format_option(FO_NO_OPEN_COMS))
1646+
&& (!has_format_option(FO_NO_OPEN_COMS)
1647+
|| (flags & OPENLINE_FORMAT)))
16471648
{
16481649
// Check for a line comment after code.
16491650
comment_start = check_linecomment(saved_line);

src/testdir/test_textformat.vim

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,11 +289,28 @@ func Test_format_c_comment()
289289
x
290290
END
291291
call assert_equal(expected, getline(1, '$'))
292+
293+
" Comment is formatted when it wraps
294+
normal 2GA with some more text added
295+
let expected =<< trim END
296+
nop;
297+
val = val; // This is a comment
298+
// with some more text
299+
// added
300+
x
301+
END
302+
call assert_equal(expected, getline(1, '$'))
303+
292304
set fo-=/
293305

294306
" using 'indentexpr' instead of 'cindent' does not repeat a comment
295307
setl nocindent indentexpr=2
296-
3delete
308+
%del
309+
let text =<< trim END
310+
nop;
311+
val = val; // This is a comment
312+
END
313+
call setline(1, text)
297314
normal 2Gox
298315
let expected =<< trim END
299316
nop;

src/textformat.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,7 @@ internal_format(
371371
open_line(FORWARD, OPENLINE_DELSPACES + OPENLINE_MARKFIX
372372
+ (fo_white_par ? OPENLINE_KEEPTRAIL : 0)
373373
+ (do_comments ? OPENLINE_DO_COM : 0)
374+
+ OPENLINE_FORMAT
374375
+ ((flags & INSCHAR_COM_LIST) ? OPENLINE_COM_LIST : 0)
375376
, ((flags & INSCHAR_COM_LIST) ? second_indent : old_indent),
376377
&did_do_comment);

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,8 @@ static char *(features[]) =
734734

735735
static int included_patches[] =
736736
{ /* Add new patch number below this line */
737+
/**/
738+
5008,
737739
/**/
738740
5007,
739741
/**/

src/vim.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1118,11 +1118,12 @@ extern int (*dyn_libintl_wputenv)(const wchar_t *envstring);
11181118
#define INSCHAR_COM_LIST 16 // format comments with list/2nd line indent
11191119

11201120
// flags for open_line()
1121-
#define OPENLINE_DELSPACES 1 // delete spaces after cursor
1122-
#define OPENLINE_DO_COM 2 // format comments
1123-
#define OPENLINE_KEEPTRAIL 4 // keep trailing spaces
1124-
#define OPENLINE_MARKFIX 8 // fix mark positions
1125-
#define OPENLINE_COM_LIST 16 // format comments with list/2nd line indent
1121+
#define OPENLINE_DELSPACES 0x01 // delete spaces after cursor
1122+
#define OPENLINE_DO_COM 0x02 // format comments
1123+
#define OPENLINE_KEEPTRAIL 0x04 // keep trailing spaces
1124+
#define OPENLINE_MARKFIX 0x08 // fix mark positions
1125+
#define OPENLINE_COM_LIST 0x10 // format comments with list/2nd line indent
1126+
#define OPENLINE_FORMAT 0x20 // formatting long comment
11261127

11271128
// There are five history tables:
11281129
#define HIST_CMD 0 // colon commands

0 commit comments

Comments
 (0)