summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2022-05-23 13:10:48 +0100
committerBram Moolenaar <Bram@vim.org>2022-05-23 13:10:48 +0100
commit7e667788150be617aeac42b0d668618ac33ab9da (patch)
tree192254db3546cae9e753acdab37b326f7cfcf693
parent6d24b4ff69913270ce1e5267dd6bd8454f75e2b9 (diff)
downloadvim-git-7e667788150be617aeac42b0d668618ac33ab9da.tar.gz
patch 8.2.5008: when 'formatoptions' contains "/" wrongly wrapping commentv8.2.5008
Problem: When 'formatoptions' contains "/" wrongly wrapping a long trailing comment. Solution: Pass the OPENLINE_FORMAT flag.
-rw-r--r--src/change.c3
-rw-r--r--src/testdir/test_textformat.vim19
-rw-r--r--src/textformat.c1
-rw-r--r--src/version.c2
-rw-r--r--src/vim.h11
5 files changed, 29 insertions, 7 deletions
diff --git a/src/change.c b/src/change.c
index 25a96f85c..b653dcc1b 100644
--- a/src/change.c
+++ b/src/change.c
@@ -1643,7 +1643,8 @@ open_line(
lead_len = get_leader_len(saved_line, &lead_flags,
dir == BACKWARD, TRUE);
if (lead_len == 0 && curbuf->b_p_cin && do_cindent && dir == FORWARD
- && !has_format_option(FO_NO_OPEN_COMS))
+ && (!has_format_option(FO_NO_OPEN_COMS)
+ || (flags & OPENLINE_FORMAT)))
{
// Check for a line comment after code.
comment_start = check_linecomment(saved_line);
diff --git a/src/testdir/test_textformat.vim b/src/testdir/test_textformat.vim
index 9630e8d15..d33e2508d 100644
--- a/src/testdir/test_textformat.vim
+++ b/src/testdir/test_textformat.vim
@@ -289,11 +289,28 @@ func Test_format_c_comment()
x
END
call assert_equal(expected, getline(1, '$'))
+
+ " Comment is formatted when it wraps
+ normal 2GA with some more text added
+ let expected =<< trim END
+ nop;
+ val = val; // This is a comment
+ // with some more text
+ // added
+ x
+ END
+ call assert_equal(expected, getline(1, '$'))
+
set fo-=/
" using 'indentexpr' instead of 'cindent' does not repeat a comment
setl nocindent indentexpr=2
- 3delete
+ %del
+ let text =<< trim END
+ nop;
+ val = val; // This is a comment
+ END
+ call setline(1, text)
normal 2Gox
let expected =<< trim END
nop;
diff --git a/src/textformat.c b/src/textformat.c
index a6a3b4dc6..7e32c1ccc 100644
--- a/src/textformat.c
+++ b/src/textformat.c
@@ -371,6 +371,7 @@ internal_format(
open_line(FORWARD, OPENLINE_DELSPACES + OPENLINE_MARKFIX
+ (fo_white_par ? OPENLINE_KEEPTRAIL : 0)
+ (do_comments ? OPENLINE_DO_COM : 0)
+ + OPENLINE_FORMAT
+ ((flags & INSCHAR_COM_LIST) ? OPENLINE_COM_LIST : 0)
, ((flags & INSCHAR_COM_LIST) ? second_indent : old_indent),
&did_do_comment);
diff --git a/src/version.c b/src/version.c
index c652b312b..36350c3b3 100644
--- a/src/version.c
+++ b/src/version.c
@@ -735,6 +735,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 5008,
+/**/
5007,
/**/
5006,
diff --git a/src/vim.h b/src/vim.h
index b7af316bf..9a970330c 100644
--- a/src/vim.h
+++ b/src/vim.h
@@ -1118,11 +1118,12 @@ extern int (*dyn_libintl_wputenv)(const wchar_t *envstring);
#define INSCHAR_COM_LIST 16 // format comments with list/2nd line indent
// flags for open_line()
-#define OPENLINE_DELSPACES 1 // delete spaces after cursor
-#define OPENLINE_DO_COM 2 // format comments
-#define OPENLINE_KEEPTRAIL 4 // keep trailing spaces
-#define OPENLINE_MARKFIX 8 // fix mark positions
-#define OPENLINE_COM_LIST 16 // format comments with list/2nd line indent
+#define OPENLINE_DELSPACES 0x01 // delete spaces after cursor
+#define OPENLINE_DO_COM 0x02 // format comments
+#define OPENLINE_KEEPTRAIL 0x04 // keep trailing spaces
+#define OPENLINE_MARKFIX 0x08 // fix mark positions
+#define OPENLINE_COM_LIST 0x10 // format comments with list/2nd line indent
+#define OPENLINE_FORMAT 0x20 // formatting long comment
// There are five history tables:
#define HIST_CMD 0 // colon commands