mirror of
https://github.com/vim/vim.git
synced 2025-09-23 03:43:49 -04:00
patch 8.0.0453: adding fold marker creates new comment
Problem: Adding fold marker creates new comment. Solution: Use an existing comment if possible. (LemonBoy, closes #1549)
This commit is contained in:
@@ -1760,6 +1760,7 @@ foldAddMarker(linenr_T lnum, char_u *marker, int markerlen)
|
|||||||
int line_len;
|
int line_len;
|
||||||
char_u *newline;
|
char_u *newline;
|
||||||
char_u *p = (char_u *)strstr((char *)curbuf->b_p_cms, "%s");
|
char_u *p = (char_u *)strstr((char *)curbuf->b_p_cms, "%s");
|
||||||
|
int line_is_comment = FALSE;
|
||||||
|
|
||||||
/* Allocate a new line: old-line + 'cms'-start + marker + 'cms'-end */
|
/* Allocate a new line: old-line + 'cms'-start + marker + 'cms'-end */
|
||||||
line = ml_get(lnum);
|
line = ml_get(lnum);
|
||||||
@@ -1767,11 +1768,16 @@ foldAddMarker(linenr_T lnum, char_u *marker, int markerlen)
|
|||||||
|
|
||||||
if (u_save(lnum - 1, lnum + 1) == OK)
|
if (u_save(lnum - 1, lnum + 1) == OK)
|
||||||
{
|
{
|
||||||
|
#if defined(FEAT_COMMENTS)
|
||||||
|
/* Check if the line ends with an unclosed comment */
|
||||||
|
(void)skip_comment(line, FALSE, FALSE, &line_is_comment);
|
||||||
|
#endif
|
||||||
newline = alloc((unsigned)(line_len + markerlen + STRLEN(cms) + 1));
|
newline = alloc((unsigned)(line_len + markerlen + STRLEN(cms) + 1));
|
||||||
if (newline == NULL)
|
if (newline == NULL)
|
||||||
return;
|
return;
|
||||||
STRCPY(newline, line);
|
STRCPY(newline, line);
|
||||||
if (p == NULL)
|
/* Append the marker to the end of the line */
|
||||||
|
if (p == NULL || line_is_comment)
|
||||||
vim_strncpy(newline + line_len, marker, markerlen);
|
vim_strncpy(newline + line_len, marker, markerlen);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@@ -113,9 +113,6 @@ static void copy_yank_reg(yankreg_T *reg);
|
|||||||
static void may_set_selection(void);
|
static void may_set_selection(void);
|
||||||
#endif
|
#endif
|
||||||
static void dis_msg(char_u *p, int skip_esc);
|
static void dis_msg(char_u *p, int skip_esc);
|
||||||
#if defined(FEAT_COMMENTS) || defined(PROTO)
|
|
||||||
static char_u *skip_comment(char_u *line, int process, int include_space, int *is_comment);
|
|
||||||
#endif
|
|
||||||
static void block_prep(oparg_T *oap, struct block_def *, linenr_T, int);
|
static void block_prep(oparg_T *oap, struct block_def *, linenr_T, int);
|
||||||
static int do_addsub(int op_type, pos_T *pos, int length, linenr_T Prenum1);
|
static int do_addsub(int op_type, pos_T *pos, int length, linenr_T Prenum1);
|
||||||
#if defined(FEAT_CLIPBOARD) || defined(FEAT_EVAL)
|
#if defined(FEAT_CLIPBOARD) || defined(FEAT_EVAL)
|
||||||
@@ -4301,7 +4298,7 @@ dis_msg(
|
|||||||
* is_comment - will indicate whether the current line ends with an unclosed
|
* is_comment - will indicate whether the current line ends with an unclosed
|
||||||
* comment.
|
* comment.
|
||||||
*/
|
*/
|
||||||
static char_u *
|
char_u *
|
||||||
skip_comment(
|
skip_comment(
|
||||||
char_u *line,
|
char_u *line,
|
||||||
int process,
|
int process,
|
||||||
|
@@ -38,6 +38,7 @@ void adjust_cursor_eol(void);
|
|||||||
int preprocs_left(void);
|
int preprocs_left(void);
|
||||||
int get_register_name(int num);
|
int get_register_name(int num);
|
||||||
void ex_display(exarg_T *eap);
|
void ex_display(exarg_T *eap);
|
||||||
|
char_u *skip_comment(char_u *line, int process, int include_space, int *is_comment);
|
||||||
int do_join(long count, int insert_space, int save_undo, int use_formatoptions, int setmark);
|
int do_join(long count, int insert_space, int save_undo, int use_formatoptions, int setmark);
|
||||||
void op_format(oparg_T *oap, int keep_cursor);
|
void op_format(oparg_T *oap, int keep_cursor);
|
||||||
void op_formatexpr(oparg_T *oap);
|
void op_formatexpr(oparg_T *oap);
|
||||||
|
@@ -168,6 +168,22 @@ func Test_combining_folds_marker()
|
|||||||
bwipe!
|
bwipe!
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
func Test_folds_marker_in_comment()
|
||||||
|
new
|
||||||
|
call setline(1, ['" foo', 'bar', 'baz'])
|
||||||
|
setl fen fdm=marker
|
||||||
|
setl com=sO:\"\ -,mO:\"\ \ ,eO:\"\",:\" cms=\"%s
|
||||||
|
norm! zf2j
|
||||||
|
setl nofen
|
||||||
|
:1y
|
||||||
|
call assert_equal(['" foo{{{'], getreg(0,1,1))
|
||||||
|
:+2y
|
||||||
|
call assert_equal(['baz"}}}'], getreg(0,1,1))
|
||||||
|
|
||||||
|
set foldmethod&
|
||||||
|
bwipe!
|
||||||
|
endfunc
|
||||||
|
|
||||||
func s:TestFoldExpr(lnum)
|
func s:TestFoldExpr(lnum)
|
||||||
let thisline = getline(a:lnum)
|
let thisline = getline(a:lnum)
|
||||||
if thisline == 'a'
|
if thisline == 'a'
|
||||||
|
@@ -764,6 +764,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 */
|
||||||
|
/**/
|
||||||
|
453,
|
||||||
/**/
|
/**/
|
||||||
452,
|
452,
|
||||||
/**/
|
/**/
|
||||||
|
Reference in New Issue
Block a user