Merge #6318 from justinmk/pr6244

test/legacy: fix test_normal.vim
This commit is contained in:
Justin M. Keyes
2017-03-20 00:47:27 +01:00
committed by GitHub
15 changed files with 2396 additions and 41 deletions

View File

@@ -2731,7 +2731,7 @@ A jump table for the options with a short description can be found at |Q_op|.
*'formatprg'* *'fp'*
'formatprg' 'fp' string (default "")
global
global or local to buffer |global-local|
The name of an external program that will be used to format the lines
selected with the |gq| operator. The program must take the input on
stdin and produce the output on stdout. The Unix program "fmt" is

View File

@@ -438,6 +438,17 @@ void close_buffer(win_T *win, buf_T *buf, int action, int abort_if_last)
/* Remember if we are closing the current buffer. Restore the number of
* windows, so that autocommands in buf_freeall() don't get confused. */
bool is_curbuf = (buf == curbuf);
// When closing the current buffer stop Visual mode before freeing
// anything.
if (is_curbuf && VIsual_active
#if defined(EXITFREE)
&& !entered_free_all_mem
#endif
) {
end_visual_mode();
}
buf->b_nwindows = nwindows;
buf_freeall(buf, (del_buf ? BFA_DEL : 0) + (wipe_buf ? BFA_WIPE : 0));
@@ -1075,6 +1086,11 @@ do_buffer (
}
}
// When closing the current buffer stop Visual mode.
if (buf == curbuf && VIsual_active) {
end_visual_mode();
}
/*
* If deleting the last (listed) buffer, make it empty.
* The last (listed) buffer cannot be unloaded.
@@ -1667,6 +1683,7 @@ void free_buf_options(buf_T *buf, int free_p_ff)
clear_string_option(&buf->b_p_inex);
clear_string_option(&buf->b_p_inde);
clear_string_option(&buf->b_p_indk);
clear_string_option(&buf->b_p_fp);
clear_string_option(&buf->b_p_fex);
clear_string_option(&buf->b_p_kp);
clear_string_option(&buf->b_p_mps);

View File

@@ -640,6 +640,7 @@ struct file_buffer {
char_u *b_p_inde; ///< 'indentexpr'
uint32_t b_p_inde_flags; ///< flags for 'indentexpr'
char_u *b_p_indk; ///< 'indentkeys'
char_u *b_p_fp; ///< 'formatprg'
char_u *b_p_fex; ///< 'formatexpr'
uint32_t b_p_fex_flags; ///< flags for 'formatexpr'
char_u *b_p_kp; ///< 'keywordprg'

View File

@@ -294,6 +294,26 @@ linenr_T get_cursor_rel_lnum(win_T *wp, linenr_T lnum)
return (lnum < cursor) ? -retval : retval;
}
// Make sure "pos.lnum" and "pos.col" are valid in "buf".
// This allows for the col to be on the NUL byte.
void check_pos(buf_T *buf, pos_T *pos)
{
char_u *line;
colnr_T len;
if (pos->lnum > buf->b_ml.ml_line_count) {
pos->lnum = buf->b_ml.ml_line_count;
}
if (pos->col > 0) {
line = ml_get_buf(buf, pos->lnum, false);
len = (colnr_T)STRLEN(line);
if (pos->col > len) {
pos->col = len;
}
}
}
/*
* Make sure curwin->w_cursor.lnum is valid.
*/

View File

@@ -7325,6 +7325,7 @@ static void ex_at(exarg_T *eap)
int prev_len = typebuf.tb_len;
curwin->w_cursor.lnum = eap->line2;
check_cursor_col();
// Get the register name. No name means use the previous one.
int c = *eap->arg;

View File

@@ -1877,9 +1877,10 @@ int onepage(int dir, long count)
}
}
foldAdjustCursor();
cursor_correct();
if (retval == OK)
check_cursor_col();
if (retval == OK) {
beginline(BL_SOL | BL_FIX);
}
curwin->w_valid &= ~(VALID_WCOL|VALID_WROW|VALID_VIRTCOL);
/*

View File

@@ -1596,6 +1596,8 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank)
oap->start = curwin->w_cursor;
}
// Just in case lines were deleted that make the position invalid.
check_pos(curwin->w_buffer, &oap->end);
oap->line_count = oap->end.lnum - oap->start.lnum + 1;
/* Set "virtual_op" before resetting VIsual_active. */
@@ -1899,12 +1901,13 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank)
break;
case OP_FORMAT:
if (*curbuf->b_p_fex != NUL)
op_formatexpr(oap); /* use expression */
else if (*p_fp != NUL)
op_colon(oap); /* use external command */
else
op_format(oap, false); /* use internal function */
if (*curbuf->b_p_fex != NUL) {
op_formatexpr(oap); // use expression
} else if (*p_fp != NUL || *curbuf->b_p_fp != NUL) {
op_colon(oap); // use external command
} else {
op_format(oap, false); // use internal function
}
break;
case OP_FORMAT2:
@@ -1912,7 +1915,10 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank)
break;
case OP_FUNCTION:
op_function(oap); /* call 'operatorfunc' */
// Restore linebreak, so that when the user edits it looks as
// before.
curwin->w_p_lbr = lbr_saved;
op_function(oap); // call 'operatorfunc'
break;
case OP_INSERT:
@@ -2059,10 +2065,13 @@ static void op_colon(oparg_T *oap)
stuffReadbuff(get_equalprg());
stuffReadbuff((char_u *)"\n");
} else if (oap->op_type == OP_FORMAT) {
if (*p_fp == NUL)
stuffReadbuff((char_u *)"fmt");
else
if (*curbuf->b_p_fp != NUL) {
stuffReadbuff(curbuf->b_p_fp);
} else if (*p_fp != NUL) {
stuffReadbuff(p_fp);
} else {
stuffReadbuff((char_u *)"fmt");
}
stuffReadbuff((char_u *)"\n']");
}
@@ -4757,13 +4766,16 @@ static void nv_ident(cmdarg_T *cap)
}
}
/*
* Now grab the chars in the identifier
*/
if (cmdchar == 'K' && !kp_ex) {
/* Escape the argument properly for a shell command */
// Now grab the chars in the identifier
if (cmdchar == 'K') {
ptr = vim_strnsave(ptr, n);
p = vim_strsave_shellescape(ptr, true, true);
if (kp_ex) {
// Escape the argument properly for an Ex command
p = vim_strsave_fnameescape(ptr, false);
} else {
// Escape the argument properly for a shell command
p = vim_strsave_shellescape(ptr, true, true);
}
xfree(ptr);
char *newbuf = xrealloc(buf, STRLEN(buf) + STRLEN(p) + 1);
buf = newbuf;

View File

@@ -3847,6 +3847,7 @@ fex_format (
int use_sandbox = was_set_insecurely((char_u *)"formatexpr",
OPT_LOCAL);
int r;
char_u *fex;
/*
* Set v:lnum to the first line number and v:count to the number of lines.
@@ -3856,16 +3857,22 @@ fex_format (
set_vim_var_nr(VV_COUNT, (varnumber_T)count);
set_vim_var_char(c);
/*
* Evaluate the function.
*/
if (use_sandbox)
++sandbox;
r = eval_to_number(curbuf->b_p_fex);
if (use_sandbox)
--sandbox;
// Make a copy, the option could be changed while calling it.
fex = vim_strsave(curbuf->b_p_fex);
if (fex == NULL) {
return 0;
}
// Evaluate the function.
if (use_sandbox) {
sandbox++;
}
r = (int)eval_to_number(fex);
if (use_sandbox) {
sandbox--;
}
set_vim_var_string(VV_CHAR, NULL, -1);
xfree(fex);
return r;
}

View File

@@ -2150,6 +2150,7 @@ void check_buf_options(buf_T *buf)
check_string_option(&buf->b_p_inex);
check_string_option(&buf->b_p_inde);
check_string_option(&buf->b_p_indk);
check_string_option(&buf->b_p_fp);
check_string_option(&buf->b_p_fex);
check_string_option(&buf->b_p_kp);
check_string_option(&buf->b_p_mps);
@@ -5255,6 +5256,9 @@ void unset_global_local_option(char *name, void *from)
case PV_TSR:
clear_string_option(&buf->b_p_tsr);
break;
case PV_FP:
clear_string_option(&buf->b_p_fp);
break;
case PV_EFM:
clear_string_option(&buf->b_p_efm);
break;
@@ -5288,6 +5292,7 @@ static char_u *get_varp_scope(vimoption_T *p, int opt_flags)
}
if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH)) {
switch ((int)p->indir) {
case PV_FP: return (char_u *)&(curbuf->b_p_fp);
case PV_EFM: return (char_u *)&(curbuf->b_p_efm);
case PV_GP: return (char_u *)&(curbuf->b_p_gp);
case PV_MP: return (char_u *)&(curbuf->b_p_mp);
@@ -5346,6 +5351,8 @@ static char_u *get_varp(vimoption_T *p)
? (char_u *)&(curbuf->b_p_dict) : p->var;
case PV_TSR: return *curbuf->b_p_tsr != NUL
? (char_u *)&(curbuf->b_p_tsr) : p->var;
case PV_FP: return *curbuf->b_p_fp != NUL
? (char_u *)&(curbuf->b_p_fp) : p->var;
case PV_EFM: return *curbuf->b_p_efm != NUL
? (char_u *)&(curbuf->b_p_efm) : p->var;
case PV_GP: return *curbuf->b_p_gp != NUL
@@ -5694,6 +5701,7 @@ void buf_copy_options(buf_T *buf, int flags)
buf->b_s.b_p_spl = vim_strsave(p_spl);
buf->b_p_inde = vim_strsave(p_inde);
buf->b_p_indk = vim_strsave(p_indk);
buf->b_p_fp = empty_option;
buf->b_p_fex = vim_strsave(p_fex);
buf->b_p_sua = vim_strsave(p_sua);
buf->b_p_keymap = vim_strsave(p_keymap);

View File

@@ -713,6 +713,7 @@ enum {
, BV_EP
, BV_ET
, BV_FENC
, BV_FP
, BV_BEXPR
, BV_FEX
, BV_FF

View File

@@ -948,7 +948,7 @@ return {
},
{
full_name='formatprg', abbreviation='fp',
type='string', scope={'global'},
type='string', scope={'global', 'buffer'},
secure=true,
vi_def=true,
expand=true,

View File

@@ -47,6 +47,7 @@ NEW_TESTS ?= \
test_match.res \
test_matchadd_conceal.res \
test_nested_function.res \
test_normal.res \
test_quickfix.res \
test_signs.res \
test_syntax.res \

View File

@@ -68,10 +68,10 @@ let $HOME = '/does/not/exist'
" Prepare for calling garbagecollect_for_testing().
let v:testing = 1
" Align with vim defaults.
" Align Nvim defaults to Vim.
set directory^=.
set nohidden
set backspace=
set nohidden smarttab noautoindent noautoread complete-=i noruler noshowcmd
function RunTheTest(test)
echo 'Executing ' . a:test

File diff suppressed because it is too large Load Diff

View File

@@ -79,7 +79,7 @@ static int included_patches[] = {
// 2365 NA
// 2364,
// 2363 NA
// 2362,
2362,
// 2361 NA
// 2360,
// 2359 NA
@@ -88,13 +88,13 @@ static int included_patches[] = {
// 2356,
// 2355,
// 2354,
// 2353,
2353,
// 2352 NA
// 2351 NA
// 2350,
// 2349,
// 2348,
// 2347,
2348,
2347,
// 2346,
// 2345 NA
// 2344 NA
@@ -105,28 +105,28 @@ static int included_patches[] = {
// 2339,
// 2338 NA
2337,
// 2336,
2336,
2335,
// 2334,
// 2333,
2333,
// 2332 NA
2331,
// 2330,
// 2329,
// 2328,
// 2327 NA
// 2326,
2326,
// 2325 NA
// 2324,
// 2323,
// 2322,
2323,
2322,
2321,
// 2320,
// 2319 NA
// 2318,
// 2317,
2317,
// 2316 NA
// 2315,
2315,
2314,
2313,
2312,