mirror of
https://github.com/vim/vim.git
synced 2025-10-04 05:25:06 -04:00
patch 8.2.2239: Vim9: concatenating lines with backslash is inconvenient
Problem: Vim9: concatenating lines with backslash is inconvenient. Solution: Support concatenating lines starting with '|', useful for :autocmd, :command, etc. (closes #6702)
This commit is contained in:
@@ -5,7 +5,6 @@ int use_typecheck(type_T *actual, type_T *expected);
|
||||
int get_script_item_idx(int sid, char_u *name, int check_writable, cctx_T *cctx);
|
||||
imported_T *find_imported(char_u *name, size_t len, cctx_T *cctx);
|
||||
imported_T *find_imported_in_script(char_u *name, size_t len, int sid);
|
||||
int vim9_comment_start(char_u *p);
|
||||
char_u *peek_next_line_from_context(cctx_T *cctx);
|
||||
char_u *next_line_from_context(cctx_T *cctx, int skip_comment);
|
||||
char_u *to_name_end(char_u *arg, int use_namespace);
|
||||
@@ -15,7 +14,7 @@ void error_white_both(char_u *op, int len);
|
||||
int assignment_len(char_u *p, int *heredoc);
|
||||
void vim9_declare_error(char_u *name);
|
||||
int check_vim9_unlet(char_u *name);
|
||||
int compile_def_function(ufunc_T *ufunc, int set_return_type, cctx_T *outer_cctx);
|
||||
int compile_def_function(ufunc_T *ufunc, int check_return_type, cctx_T *outer_cctx);
|
||||
void set_function_type(ufunc_T *ufunc);
|
||||
void delete_instr(isn_T *isn);
|
||||
void unlink_def_function(ufunc_T *ufunc);
|
||||
|
@@ -2,6 +2,7 @@
|
||||
int in_vim9script(void);
|
||||
void ex_vim9script(exarg_T *eap);
|
||||
int not_in_vim9(exarg_T *eap);
|
||||
int vim9_comment_start(char_u *p);
|
||||
void ex_export(exarg_T *eap);
|
||||
void free_imports_and_script_vars(int sid);
|
||||
void mark_imports_for_reload(int sid);
|
||||
|
@@ -1739,6 +1739,10 @@ getsourceline(
|
||||
struct source_cookie *sp = (struct source_cookie *)cookie;
|
||||
char_u *line;
|
||||
char_u *p;
|
||||
int do_vim9_all = in_vim9script()
|
||||
&& options == GETLINE_CONCAT_ALL;
|
||||
int do_vim9_cont = do_vim9_all
|
||||
|| options == GETLINE_CONCAT_CONTDEF;
|
||||
|
||||
#ifdef FEAT_EVAL
|
||||
// If breakpoints have been added/deleted need to check for it.
|
||||
@@ -1785,17 +1789,15 @@ getsourceline(
|
||||
// backslash. We always need to read the next line, keep it in
|
||||
// sp->nextline.
|
||||
/* Also check for a comment in between continuation lines: "\ */
|
||||
// Also check for a Vim9 comment and empty line.
|
||||
// Also check for a Vim9 comment, empty line, line starting with '|',
|
||||
// but not "||".
|
||||
sp->nextline = get_one_sourceline(sp);
|
||||
if (sp->nextline != NULL
|
||||
&& (*(p = skipwhite(sp->nextline)) == '\\'
|
||||
|| (p[0] == '"' && p[1] == '\\' && p[2] == ' ')
|
||||
#ifdef FEAT_EVAL
|
||||
|| (in_vim9script()
|
||||
&& options == GETLINE_CONCAT_ALL
|
||||
&& (*p == NUL || vim9_comment_start(p)))
|
||||
#endif
|
||||
))
|
||||
|| (do_vim9_all && (*p == NUL
|
||||
|| vim9_comment_start(p)))
|
||||
|| (do_vim9_cont && p[0] == '|' && p[1] != '|')))
|
||||
{
|
||||
garray_T ga;
|
||||
|
||||
@@ -1803,6 +1805,11 @@ getsourceline(
|
||||
ga_concat(&ga, line);
|
||||
if (*p == '\\')
|
||||
ga_concat(&ga, p + 1);
|
||||
else if (*p == '|')
|
||||
{
|
||||
ga_concat(&ga, (char_u *)" ");
|
||||
ga_concat(&ga, p);
|
||||
}
|
||||
for (;;)
|
||||
{
|
||||
vim_free(sp->nextline);
|
||||
@@ -1810,7 +1817,7 @@ getsourceline(
|
||||
if (sp->nextline == NULL)
|
||||
break;
|
||||
p = skipwhite(sp->nextline);
|
||||
if (*p == '\\')
|
||||
if (*p == '\\' || (do_vim9_cont && p[0] == '|' && p[1] != '|'))
|
||||
{
|
||||
// Adjust the growsize to the current length to speed up
|
||||
// concatenating many lines.
|
||||
@@ -1821,15 +1828,16 @@ getsourceline(
|
||||
else
|
||||
ga.ga_growsize = ga.ga_len;
|
||||
}
|
||||
ga_concat(&ga, p + 1);
|
||||
if (*p == '\\')
|
||||
ga_concat(&ga, p + 1);
|
||||
else
|
||||
{
|
||||
ga_concat(&ga, (char_u *)" ");
|
||||
ga_concat(&ga, p);
|
||||
}
|
||||
}
|
||||
else if (!(p[0] == '"' && p[1] == '\\' && p[2] == ' ')
|
||||
#ifdef FEAT_EVAL
|
||||
&& !(in_vim9script()
|
||||
&& options == GETLINE_CONCAT_ALL
|
||||
&& (*p == NUL || vim9_comment_start(p)))
|
||||
#endif
|
||||
)
|
||||
&& !(do_vim9_all && (*p == NUL || vim9_comment_start(p))))
|
||||
break;
|
||||
/* drop a # comment or "\ comment line */
|
||||
}
|
||||
|
@@ -1565,7 +1565,8 @@ typedef void (*cfunc_free_T)(void *state);
|
||||
// type of getline() last argument
|
||||
typedef enum {
|
||||
GETLINE_NONE, // do not concatenate any lines
|
||||
GETLINE_CONCAT_CONT, // concatenate continuation lines
|
||||
GETLINE_CONCAT_CONT, // concatenate continuation lines in Vim9 script
|
||||
GETLINE_CONCAT_CONTDEF, // concatenate continuation lines always
|
||||
GETLINE_CONCAT_ALL // concatenate continuation and Vim9 # comment lines
|
||||
} getline_opt_T;
|
||||
|
||||
|
@@ -548,13 +548,33 @@ def Test_command_modifier_other()
|
||||
bwipe!
|
||||
|
||||
au BufNewFile Xfile g:readFile = 1
|
||||
| g:readExtra = 2
|
||||
g:readFile = 0
|
||||
g:readExtra = 0
|
||||
edit Xfile
|
||||
assert_equal(1, g:readFile)
|
||||
assert_equal(2, g:readExtra)
|
||||
bwipe!
|
||||
g:readFile = 0
|
||||
noautocmd edit Xfile
|
||||
assert_equal(0, g:readFile)
|
||||
au! BufNewFile
|
||||
|
||||
au BufNewFile Xfile g:readFile = 1
|
||||
| g:readExtra = 2
|
||||
| g:readMore = 3
|
||||
g:readFile = 0
|
||||
g:readExtra = 0
|
||||
g:readMore = 0
|
||||
edit Xfile
|
||||
assert_equal(1, g:readFile)
|
||||
assert_equal(2, g:readExtra)
|
||||
assert_equal(3, g:readMore)
|
||||
bwipe!
|
||||
au! BufNewFile
|
||||
unlet g:readFile
|
||||
unlet g:readExtra
|
||||
unlet g:readMore
|
||||
|
||||
noswapfile edit XnoSwap
|
||||
assert_equal(0, &l:swapfile)
|
||||
|
@@ -2960,7 +2960,7 @@ define_function(exarg_T *eap, char_u *name_arg)
|
||||
static int func_nr = 0; // number for nameless function
|
||||
int paren;
|
||||
hashitem_T *hi;
|
||||
getline_opt_T getline_options = GETLINE_CONCAT_CONT;
|
||||
getline_opt_T getline_options;
|
||||
linenr_T sourcing_lnum_off;
|
||||
linenr_T sourcing_lnum_top;
|
||||
int is_heredoc = FALSE;
|
||||
@@ -3291,6 +3291,8 @@ define_function(exarg_T *eap, char_u *name_arg)
|
||||
indent = 2;
|
||||
nesting = 0;
|
||||
nesting_def[nesting] = (eap->cmdidx == CMD_def);
|
||||
getline_options = eap->cmdidx == CMD_def
|
||||
? GETLINE_CONCAT_CONTDEF : GETLINE_CONCAT_CONT;
|
||||
for (;;)
|
||||
{
|
||||
if (KeyTyped)
|
||||
@@ -3365,7 +3367,8 @@ define_function(exarg_T *eap, char_u *name_arg)
|
||||
{
|
||||
VIM_CLEAR(skip_until);
|
||||
VIM_CLEAR(heredoc_trimmed);
|
||||
getline_options = GETLINE_CONCAT_CONT;
|
||||
getline_options = eap->cmdidx == CMD_def
|
||||
? GETLINE_CONCAT_CONTDEF : GETLINE_CONCAT_CONT;
|
||||
is_heredoc = FALSE;
|
||||
}
|
||||
}
|
||||
|
@@ -750,6 +750,8 @@ static char *(features[]) =
|
||||
|
||||
static int included_patches[] =
|
||||
{ /* Add new patch number below this line */
|
||||
/**/
|
||||
2239,
|
||||
/**/
|
||||
2238,
|
||||
/**/
|
||||
|
@@ -2164,15 +2164,6 @@ free_imported(cctx_T *cctx)
|
||||
ga_clear(&cctx->ctx_imports);
|
||||
}
|
||||
|
||||
/*
|
||||
* Return TRUE if "p" points at a "#". Does not check for white space.
|
||||
*/
|
||||
int
|
||||
vim9_comment_start(char_u *p)
|
||||
{
|
||||
return p[0] == '#';
|
||||
}
|
||||
|
||||
/*
|
||||
* Return a pointer to the next line that isn't empty or only contains a
|
||||
* comment. Skips over white space.
|
||||
|
@@ -103,6 +103,15 @@ not_in_vim9(exarg_T *eap)
|
||||
return OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* Return TRUE if "p" points at a "#". Does not check for white space.
|
||||
*/
|
||||
int
|
||||
vim9_comment_start(char_u *p)
|
||||
{
|
||||
return p[0] == '#';
|
||||
}
|
||||
|
||||
#if defined(FEAT_EVAL) || defined(PROTO)
|
||||
|
||||
/*
|
||||
|
Reference in New Issue
Block a user