mirror of
https://github.com/vim/vim.git
synced 2025-07-26 11:04:33 -04:00
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.
This commit is contained in:
parent
6d24b4ff69
commit
7e66778815
@ -1643,7 +1643,8 @@ open_line(
|
|||||||
lead_len = get_leader_len(saved_line, &lead_flags,
|
lead_len = get_leader_len(saved_line, &lead_flags,
|
||||||
dir == BACKWARD, TRUE);
|
dir == BACKWARD, TRUE);
|
||||||
if (lead_len == 0 && curbuf->b_p_cin && do_cindent && dir == FORWARD
|
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.
|
// Check for a line comment after code.
|
||||||
comment_start = check_linecomment(saved_line);
|
comment_start = check_linecomment(saved_line);
|
||||||
|
@ -289,11 +289,28 @@ func Test_format_c_comment()
|
|||||||
x
|
x
|
||||||
END
|
END
|
||||||
call assert_equal(expected, getline(1, '$'))
|
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-=/
|
set fo-=/
|
||||||
|
|
||||||
" using 'indentexpr' instead of 'cindent' does not repeat a comment
|
" using 'indentexpr' instead of 'cindent' does not repeat a comment
|
||||||
setl nocindent indentexpr=2
|
setl nocindent indentexpr=2
|
||||||
3delete
|
%del
|
||||||
|
let text =<< trim END
|
||||||
|
nop;
|
||||||
|
val = val; // This is a comment
|
||||||
|
END
|
||||||
|
call setline(1, text)
|
||||||
normal 2Gox
|
normal 2Gox
|
||||||
let expected =<< trim END
|
let expected =<< trim END
|
||||||
nop;
|
nop;
|
||||||
|
@ -371,6 +371,7 @@ internal_format(
|
|||||||
open_line(FORWARD, OPENLINE_DELSPACES + OPENLINE_MARKFIX
|
open_line(FORWARD, OPENLINE_DELSPACES + OPENLINE_MARKFIX
|
||||||
+ (fo_white_par ? OPENLINE_KEEPTRAIL : 0)
|
+ (fo_white_par ? OPENLINE_KEEPTRAIL : 0)
|
||||||
+ (do_comments ? OPENLINE_DO_COM : 0)
|
+ (do_comments ? OPENLINE_DO_COM : 0)
|
||||||
|
+ OPENLINE_FORMAT
|
||||||
+ ((flags & INSCHAR_COM_LIST) ? OPENLINE_COM_LIST : 0)
|
+ ((flags & INSCHAR_COM_LIST) ? OPENLINE_COM_LIST : 0)
|
||||||
, ((flags & INSCHAR_COM_LIST) ? second_indent : old_indent),
|
, ((flags & INSCHAR_COM_LIST) ? second_indent : old_indent),
|
||||||
&did_do_comment);
|
&did_do_comment);
|
||||||
|
@ -734,6 +734,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
5008,
|
||||||
/**/
|
/**/
|
||||||
5007,
|
5007,
|
||||||
/**/
|
/**/
|
||||||
|
11
src/vim.h
11
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
|
#define INSCHAR_COM_LIST 16 // format comments with list/2nd line indent
|
||||||
|
|
||||||
// flags for open_line()
|
// flags for open_line()
|
||||||
#define OPENLINE_DELSPACES 1 // delete spaces after cursor
|
#define OPENLINE_DELSPACES 0x01 // delete spaces after cursor
|
||||||
#define OPENLINE_DO_COM 2 // format comments
|
#define OPENLINE_DO_COM 0x02 // format comments
|
||||||
#define OPENLINE_KEEPTRAIL 4 // keep trailing spaces
|
#define OPENLINE_KEEPTRAIL 0x04 // keep trailing spaces
|
||||||
#define OPENLINE_MARKFIX 8 // fix mark positions
|
#define OPENLINE_MARKFIX 0x08 // fix mark positions
|
||||||
#define OPENLINE_COM_LIST 16 // format comments with list/2nd line indent
|
#define OPENLINE_COM_LIST 0x10 // format comments with list/2nd line indent
|
||||||
|
#define OPENLINE_FORMAT 0x20 // formatting long comment
|
||||||
|
|
||||||
// There are five history tables:
|
// There are five history tables:
|
||||||
#define HIST_CMD 0 // colon commands
|
#define HIST_CMD 0 // colon commands
|
||||||
|
Loading…
x
Reference in New Issue
Block a user