Skip to content

Commit 38d94f1

Browse files
committed
Merge remote-tracking branch 'vim/master'
2 parents 650b5a9 + cb574f4 commit 38d94f1

11 files changed

Lines changed: 211 additions & 96 deletions

File tree

src/edit.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8737,7 +8737,7 @@ ins_esc(
87378737
*/
87388738
if (reg_recording != 0 || restart_edit != NUL)
87398739
showmode();
8740-
else if (p_smd)
8740+
else if (p_smd && !skip_showmode())
87418741
msg("");
87428742

87438743
return TRUE; /* exit Insert mode */

src/eval.c

Lines changed: 66 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9494,15 +9494,55 @@ assert_fails(typval_T *argvars)
94949494
return ret;
94959495
}
94969496

9497+
/*
9498+
* Append "p[clen]" to "gap", escaping unprintable characters.
9499+
* Changes NL to \n, CR to \r, etc.
9500+
*/
9501+
static void
9502+
ga_concat_esc(garray_T *gap, char_u *p, int clen)
9503+
{
9504+
char_u buf[NUMBUFLEN];
9505+
9506+
if (clen > 1)
9507+
{
9508+
mch_memmove(buf, p, clen);
9509+
buf[clen] = NUL;
9510+
ga_concat(gap, buf);
9511+
}
9512+
else switch (*p)
9513+
{
9514+
case BS: ga_concat(gap, (char_u *)"\\b"); break;
9515+
case ESC: ga_concat(gap, (char_u *)"\\e"); break;
9516+
case FF: ga_concat(gap, (char_u *)"\\f"); break;
9517+
case NL: ga_concat(gap, (char_u *)"\\n"); break;
9518+
case TAB: ga_concat(gap, (char_u *)"\\t"); break;
9519+
case CAR: ga_concat(gap, (char_u *)"\\r"); break;
9520+
case '\\': ga_concat(gap, (char_u *)"\\\\"); break;
9521+
default:
9522+
if (*p < ' ')
9523+
{
9524+
vim_snprintf((char *)buf, NUMBUFLEN, "\\x%02x", *p);
9525+
ga_concat(gap, buf);
9526+
}
9527+
else
9528+
ga_append(gap, *p);
9529+
break;
9530+
}
9531+
}
9532+
94979533
/*
94989534
* Append "str" to "gap", escaping unprintable characters.
94999535
* Changes NL to \n, CR to \r, etc.
95009536
*/
95019537
static void
9502-
ga_concat_esc(garray_T *gap, char_u *str)
9538+
ga_concat_shorten_esc(garray_T *gap, char_u *str)
95039539
{
95049540
char_u *p;
9541+
char_u *s;
9542+
int c;
9543+
int clen;
95059544
char_u buf[NUMBUFLEN];
9545+
int same_len;
95069546

95079547
if (str == NULL)
95089548
{
@@ -9511,25 +9551,29 @@ ga_concat_esc(garray_T *gap, char_u *str)
95119551
}
95129552

95139553
for (p = str; *p != NUL; ++p)
9514-
switch (*p)
9515-
{
9516-
case BS: ga_concat(gap, (char_u *)"\\b"); break;
9517-
case ESC: ga_concat(gap, (char_u *)"\\e"); break;
9518-
case FF: ga_concat(gap, (char_u *)"\\f"); break;
9519-
case NL: ga_concat(gap, (char_u *)"\\n"); break;
9520-
case TAB: ga_concat(gap, (char_u *)"\\t"); break;
9521-
case CAR: ga_concat(gap, (char_u *)"\\r"); break;
9522-
case '\\': ga_concat(gap, (char_u *)"\\\\"); break;
9523-
default:
9524-
if (*p < ' ')
9525-
{
9526-
vim_snprintf((char *)buf, NUMBUFLEN, "\\x%02x", *p);
9527-
ga_concat(gap, buf);
9528-
}
9529-
else
9530-
ga_append(gap, *p);
9531-
break;
9554+
{
9555+
same_len = 1;
9556+
s = p;
9557+
c = mb_ptr2char_adv(&s);
9558+
clen = s - p;
9559+
while (*s != NUL && c == mb_ptr2char(s))
9560+
{
9561+
++same_len;
9562+
s += clen;
9563+
}
9564+
if (same_len > 20)
9565+
{
9566+
ga_concat(gap, (char_u *)"\\[");
9567+
ga_concat_esc(gap, p, clen);
9568+
ga_concat(gap, (char_u *)" occurs ");
9569+
vim_snprintf((char *)buf, NUMBUFLEN, "%d", same_len);
9570+
ga_concat(gap, buf);
9571+
ga_concat(gap, (char_u *)" times]");
9572+
p = s - 1;
95329573
}
9574+
else
9575+
ga_concat_esc(gap, p, clen);
9576+
}
95339577
}
95349578

95359579
/*
@@ -9562,11 +9606,11 @@ fill_assert_error(
95629606
ga_concat(gap, (char_u *)"Expected ");
95639607
if (exp_str == NULL)
95649608
{
9565-
ga_concat_esc(gap, tv2string(exp_tv, &tofree, numbuf, 0));
9609+
ga_concat_shorten_esc(gap, tv2string(exp_tv, &tofree, numbuf, 0));
95669610
vim_free(tofree);
95679611
}
95689612
else
9569-
ga_concat_esc(gap, exp_str);
9613+
ga_concat_shorten_esc(gap, exp_str);
95709614
if (atype != ASSERT_NOTEQUAL)
95719615
{
95729616
if (atype == ASSERT_MATCH)
@@ -9575,7 +9619,7 @@ fill_assert_error(
95759619
ga_concat(gap, (char_u *)" does match ");
95769620
else
95779621
ga_concat(gap, (char_u *)" but got ");
9578-
ga_concat_esc(gap, tv2string(got_tv, &tofree, numbuf, 0));
9622+
ga_concat_shorten_esc(gap, tv2string(got_tv, &tofree, numbuf, 0));
95799623
vim_free(tofree);
95809624
}
95819625
}

src/getchar.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3039,9 +3039,10 @@ inchar(
30393039

30403040
/*
30413041
* Always flush the output characters when getting input characters
3042-
* from the user.
3042+
* from the user and not just peeking.
30433043
*/
3044-
out_flush();
3044+
if (wait_time == -1L || wait_time > 10L)
3045+
out_flush();
30453046

30463047
/*
30473048
* Fill up to a third of the buffer, because each character may be

src/proto/screen.pro

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ int win_ins_lines(win_T *wp, int row, int line_count, int invalid, int mayclear)
4949
int win_del_lines(win_T *wp, int row, int line_count, int invalid, int mayclear, int clear_attr);
5050
int screen_ins_lines(int off, int row, int line_count, int end, int clear_attr, win_T *wp);
5151
int screen_del_lines(int off, int row, int line_count, int end, int force, int clear_attr, win_T *wp);
52+
int skip_showmode(void);
5253
int showmode(void);
5354
void unshowmode(int force);
5455
void clearmode(void);

src/screen.c

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10158,6 +10158,26 @@ screen_del_lines(
1015810158
return OK;
1015910159
}
1016010160

10161+
/*
10162+
* Return TRUE when postponing displaying the mode message: when not redrawing
10163+
* or inside a mapping.
10164+
*/
10165+
int
10166+
skip_showmode()
10167+
{
10168+
// Call char_avail() only when we are going to show something, because it
10169+
// takes a bit of time. redrawing() may also call char_avail_avail().
10170+
if (global_busy
10171+
|| msg_silent != 0
10172+
|| !redrawing()
10173+
|| (char_avail() && !KeyTyped))
10174+
{
10175+
redraw_cmdline = TRUE; // show mode later
10176+
return TRUE;
10177+
}
10178+
return FALSE;
10179+
}
10180+
1016110181
/*
1016210182
* Show the current mode and ruler.
1016310183
*
@@ -10184,16 +10204,8 @@ showmode(void)
1018410204
|| VIsual_active));
1018510205
if (do_mode || reg_recording != 0)
1018610206
{
10187-
/*
10188-
* Don't show mode right now, when not redrawing or inside a mapping.
10189-
* Call char_avail() only when we are going to show something, because
10190-
* it takes a bit of time.
10191-
*/
10192-
if (!redrawing() || (char_avail() && !KeyTyped) || msg_silent != 0)
10193-
{
10194-
redraw_cmdline = TRUE; /* show mode later */
10195-
return 0;
10196-
}
10207+
if (skip_showmode())
10208+
return 0; // show mode later
1019710209

1019810210
nwr_save = need_wait_return;
1019910211

src/testdir/test_assert.vim

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ func Test_assert_equal()
3131
call assert_equal(1, assert_equal('bar', s))
3232
call assert_match("Expected 'bar' but got 'foo'", v:errors[0])
3333
call remove(v:errors, 0)
34+
35+
call assert_equal('XxxxxxxxxxxxxxxxxxxxxxX', 'XyyyyyyyyyyyyyyyyyyyyyyyyyX')
36+
call assert_match("Expected 'X\\\\\\[x occurs 21 times]X' but got 'X\\\\\\[y occurs 25 times]X'", v:errors[0])
37+
call remove(v:errors, 0)
3438
endfunc
3539

3640
func Test_assert_equalfile()

src/testdir/test_channel.vim

Lines changed: 41 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -885,19 +885,19 @@ endfunc
885885
func Test_pipe_err_to_buffer_name()
886886
call Run_test_pipe_err_to_buffer(1, 0, 1)
887887
endfunc
888-
888+
889889
func Test_pipe_err_to_buffer_nr()
890890
call Run_test_pipe_err_to_buffer(0, 0, 1)
891891
endfunc
892-
892+
893893
func Test_pipe_err_to_buffer_name_nomod()
894894
call Run_test_pipe_err_to_buffer(1, 1, 1)
895895
endfunc
896-
896+
897897
func Test_pipe_err_to_buffer_name_nomsg()
898898
call Run_test_pipe_err_to_buffer(1, 0, 0)
899899
endfunc
900-
900+
901901
func Test_pipe_both_to_buffer()
902902
if !has('job')
903903
return
@@ -972,15 +972,15 @@ func Run_pipe_through_sort(all, use_buffer)
972972
let options.in_top = 2
973973
let options.in_bot = 4
974974
endif
975-
let g:job = job_start('sort', options)
975+
let job = job_start('sort', options)
976976

977977
if !a:use_buffer
978-
call assert_equal("run", job_status(g:job))
979-
call ch_sendraw(g:job, "ccc\naaa\nddd\nbbb\neee\n")
980-
call ch_close_in(g:job)
978+
call assert_equal("run", job_status(job))
979+
call ch_sendraw(job, "ccc\naaa\nddd\nbbb\neee\n")
980+
call ch_close_in(job)
981981
endif
982982

983-
call WaitForAssert({-> assert_equal("dead", job_status(g:job))})
983+
call WaitForAssert({-> assert_equal("dead", job_status(job))})
984984

985985
sp sortout
986986
call WaitFor('line("$") > 3')
@@ -991,8 +991,7 @@ func Run_pipe_through_sort(all, use_buffer)
991991
call assert_equal(['aaa', 'bbb', 'ddd'], getline(2, 4))
992992
endif
993993

994-
call job_stop(g:job)
995-
unlet g:job
994+
call job_stop(job)
996995
if a:use_buffer
997996
bwipe! sortin
998997
endif
@@ -1192,7 +1191,8 @@ func Test_pipe_to_buffer_raw()
11921191
split testout
11931192
let job = job_start([s:python, '-c',
11941193
\ 'import sys; [sys.stdout.write(".") and sys.stdout.flush() for _ in range(10000)]'], options)
1195-
call assert_equal("run", job_status(job))
1194+
" the job may be done quickly, also accept "dead"
1195+
call assert_match('^\%(dead\|run\)$', job_status(job))
11961196
call WaitFor('len(join(getline(1, "$"), "")) >= 10000')
11971197
try
11981198
let totlen = 0
@@ -1253,9 +1253,9 @@ func Test_out_cb()
12531253
endfunc
12541254
let job = job_start(s:python . " test_channel_pipe.py",
12551255
\ {'out_cb': dict.outHandler,
1256-
\ 'out_mode': 'json',
1257-
\ 'err_cb': dict.errHandler,
1258-
\ 'err_mode': 'json'})
1256+
\ 'out_mode': 'json',
1257+
\ 'err_cb': dict.errHandler,
1258+
\ 'err_mode': 'json'})
12591259
call assert_equal("run", job_status(job))
12601260
try
12611261
let g:Ch_outmsg = ''
@@ -1296,8 +1296,9 @@ func Test_out_close_cb()
12961296
endfunc
12971297
let job = job_start(s:python . " test_channel_pipe.py quit now",
12981298
\ {'out_cb': 'OutHandler',
1299-
\ 'close_cb': 'CloseHandler'})
1300-
call assert_equal("run", job_status(job))
1299+
\ 'close_cb': 'CloseHandler'})
1300+
" the job may be done quickly, also accept "dead"
1301+
call assert_match('^\%(dead\|run\)$', job_status(job))
13011302
try
13021303
call WaitForAssert({-> assert_equal('quit', g:Ch_msg1)})
13031304
call WaitForAssert({-> assert_equal(2, g:Ch_closemsg)})
@@ -1320,7 +1321,8 @@ func Test_read_in_close_cb()
13201321
endfunc
13211322
let job = job_start(s:python . " test_channel_pipe.py quit now",
13221323
\ {'close_cb': 'CloseHandler'})
1323-
call assert_equal("run", job_status(job))
1324+
" the job may be done quickly, also accept "dead"
1325+
call assert_match('^\%(dead\|run\)$', job_status(job))
13241326
try
13251327
call WaitForAssert({-> assert_equal('quit', g:Ch_received)})
13261328
finally
@@ -1344,7 +1346,8 @@ func Test_read_in_close_cb_incomplete()
13441346
endfunc
13451347
let job = job_start(s:python . " test_channel_pipe.py incomplete",
13461348
\ {'close_cb': 'CloseHandler'})
1347-
call assert_equal("run", job_status(job))
1349+
" the job may be done quickly, also accept "dead"
1350+
call assert_match('^\%(dead\|run\)$', job_status(job))
13481351
try
13491352
call WaitForAssert({-> assert_equal('incomplete', g:Ch_received)})
13501353
finally
@@ -1360,10 +1363,10 @@ func Test_out_cb_lambda()
13601363
call ch_log('Test_out_cb_lambda()')
13611364

13621365
let job = job_start(s:python . " test_channel_pipe.py",
1363-
\ {'out_cb': {ch, msg -> execute("let g:Ch_outmsg = 'lambda: ' . msg")},
1364-
\ 'out_mode': 'json',
1365-
\ 'err_cb': {ch, msg -> execute(":let g:Ch_errmsg = 'lambda: ' . msg")},
1366-
\ 'err_mode': 'json'})
1366+
\ {'out_cb': {ch, msg -> execute("let g:Ch_outmsg = 'lambda: ' . msg")},
1367+
\ 'out_mode': 'json',
1368+
\ 'err_cb': {ch, msg -> execute(":let g:Ch_errmsg = 'lambda: ' . msg")},
1369+
\ 'err_mode': 'json'})
13671370
call assert_equal("run", job_status(job))
13681371
try
13691372
let g:Ch_outmsg = ''
@@ -1391,14 +1394,13 @@ func Test_close_and_exit_cb()
13911394
let self.ret['exit_cb'] = job_status(a:job)
13921395
endfunc
13931396

1394-
let g:job = job_start(has('win32') ? 'cmd /c echo:' : 'echo', {
1395-
\ 'close_cb': g:retdict.close_cb,
1396-
\ 'exit_cb': g:retdict.exit_cb,
1397-
\ })
1398-
call assert_equal('run', job_status(g:job))
1399-
unlet g:job
1397+
let job = job_start([&shell, &shellcmdflag, 'echo'],
1398+
\ {'close_cb': g:retdict.close_cb,
1399+
\ 'exit_cb': g:retdict.exit_cb})
1400+
" the job may be done quickly, also accept "dead"
1401+
call assert_match('^\%(dead\|run\)$', job_status(job))
14001402
call WaitForAssert({-> assert_equal(2, len(g:retdict.ret))})
1401-
call assert_match('^\%(dead\|run\)', g:retdict.ret['close_cb'])
1403+
call assert_match('^\%(dead\|run\)$', g:retdict.ret['close_cb'])
14021404
call assert_equal('dead', g:retdict.ret['exit_cb'])
14031405
unlet g:retdict
14041406
endfunc
@@ -1421,7 +1423,7 @@ func Test_exit_cb_wipes_buf()
14211423
let g:wipe_buf = bufnr('')
14221424

14231425
let job = job_start(has('win32') ? 'cmd /c echo:' : ['true'],
1424-
\ {'exit_cb': 'ExitCbWipe'})
1426+
\ {'exit_cb': 'ExitCbWipe'})
14251427
let timer = timer_start(300, {-> feedkeys("\<Esc>", 'nt')}, {'repeat': 5})
14261428
call feedkeys(repeat('g', 1000) . 'o', 'ntx!')
14271429
call WaitForAssert({-> assert_equal("dead", job_status(job))})
@@ -1939,7 +1941,8 @@ func Test_keep_pty_open()
19391941
return
19401942
endif
19411943

1942-
let job = job_start(s:python . ' -c "import time;time.sleep(0.2)"', {'out_io': 'null', 'err_io': 'null', 'pty': 1})
1944+
let job = job_start(s:python . ' -c "import time;time.sleep(0.2)"',
1945+
\ {'out_io': 'null', 'err_io': 'null', 'pty': 1})
19431946
let elapsed = WaitFor({-> job_status(job) ==# 'dead'})
19441947
call assert_inrange(200, 1000, elapsed)
19451948
call job_stop(job)
@@ -1991,13 +1994,14 @@ func Test_raw_large_data()
19911994
try
19921995
let g:out = ''
19931996
let job = job_start(s:python . " test_channel_pipe.py",
1994-
\ {'mode': 'raw', 'drop': 'never', 'noblock': 1,
1995-
\ 'callback': {ch, msg -> execute('let g:out .= msg')}})
1997+
\ {'mode': 'raw', 'drop': 'never', 'noblock': 1,
1998+
\ 'callback': {ch, msg -> execute('let g:out .= msg')}})
19961999

1997-
let want = repeat('X', 79999) . "\n"
2000+
let outlen = 79999
2001+
let want = repeat('X', outlen) . "\n"
19982002
call ch_sendraw(job, want)
1999-
let g:Ch_job = job
2000-
call WaitForAssert({-> assert_equal("dead", job_status(g:Ch_job))})
2003+
call WaitFor({-> len(g:out) >= outlen}, 10000)
2004+
call WaitForAssert({-> assert_equal("dead", job_status(job))})
20012005
call assert_equal(want, substitute(g:out, '\r', '', 'g'))
20022006
finally
20032007
call job_stop(job)

0 commit comments

Comments
 (0)