Patch 8.2.5008
Problem: When 'formatoptions' contains "/" wrongly wrapping a long trailing
comment.
Solution: Pass the OPENLINE_FORMAT flag.
Files: src/change.c, src/vim.h, src/textformat.c,
src/testdir/test_textformat.vim
*** ../vim-8.2.5007/src/change.c 2022-05-21 20:16:51.003567195 +0100
--- src/change.c 2022-05-23 12:52:21.872694633 +0100
***************
*** 1643,1649 ****
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))
{
// Check for a line comment after code.
comment_start = check_linecomment(saved_line);
--- 1643,1650 ----
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)
! || (flags & OPENLINE_FORMAT)))
{
// Check for a line comment after code.
comment_start = check_linecomment(saved_line);
*** ../vim-8.2.5007/src/vim.h 2022-05-22 19:13:45.500327035 +0100
--- src/vim.h 2022-05-23 12:54:31.400358997 +0100
***************
*** 1118,1128 ****
#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
// There are five history tables:
#define HIST_CMD 0 // colon commands
--- 1118,1129 ----
#define INSCHAR_COM_LIST 16 // format comments with list/2nd line indent
// flags for open_line()
! #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
*** ../vim-8.2.5007/src/textformat.c 2022-05-21 20:16:51.007567185 +0100
--- src/textformat.c 2022-05-23 12:55:12.944260876 +0100
***************
*** 371,376 ****
--- 371,377 ----
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);
*** ../vim-8.2.5007/src/testdir/test_textformat.vim 2022-05-07
15:43:48.973787528 +0100
--- src/testdir/test_textformat.vim 2022-05-23 13:02:17.955440987 +0100
***************
*** 289,299 ****
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
normal 2Gox
let expected =<< trim END
nop;
--- 289,316 ----
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
! %del
! let text =<< trim END
! nop;
! val = val; // This is a comment
! END
! call setline(1, text)
normal 2Gox
let expected =<< trim END
nop;
*** ../vim-8.2.5007/src/version.c 2022-05-23 12:01:10.937519982 +0100
--- src/version.c 2022-05-23 13:10:24.646733182 +0100
***************
*** 736,737 ****
--- 736,739 ----
{ /* Add new patch number below this line */
+ /**/
+ 5008,
/**/
--
We're knights of the round table
We dance whene'er we're able
We do routines and chorus scenes
With footwork impeccable.
We dine well here in Camelot
We eat ham and jam and spam a lot.
"Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD
/// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/vim_dev/20220523121352.9EFC61C0D2C%40moolenaar.net.