Skip to content

Commit 5e5f3b9

Browse files
committed
Merge remote-tracking branch 'vim/master'
2 parents c6e0b91 + 5842a74 commit 5e5f3b9

17 files changed

+244
-164
lines changed

runtime/pack/dist/opt/termdebug/plugin/termdebug.vim

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ func s:StartDebug(cmd)
8080
let commpty = job_info(term_getjob(s:commbuf))['tty_out']
8181

8282
" Open a terminal window to run the debugger.
83-
let cmd = [g:termdebugger, '-tty', pty, a:cmd]
83+
" Add -quiet to avoid the intro message causing a hit-enter prompt.
84+
let cmd = [g:termdebugger, '-quiet', '-tty', pty, a:cmd]
8485
echomsg 'executing "' . join(cmd) . '"'
8586
let gdbbuf = term_start(cmd, {
8687
\ 'exit_cb': function('s:EndDebug'),

src/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2276,6 +2276,7 @@ test_arglist \
22762276
test_stat \
22772277
test_statusline \
22782278
test_substitute \
2279+
test_swap \
22792280
test_syn_attr \
22802281
test_syntax \
22812282
test_system \

src/fileio.c

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -716,7 +716,29 @@ readfile(
716716
/* Set swap file protection bits after creating it. */
717717
if (swap_mode > 0 && curbuf->b_ml.ml_mfp != NULL
718718
&& curbuf->b_ml.ml_mfp->mf_fname != NULL)
719-
(void)mch_setperm(curbuf->b_ml.ml_mfp->mf_fname, (long)swap_mode);
719+
{
720+
char_u *swap_fname = curbuf->b_ml.ml_mfp->mf_fname;
721+
722+
/*
723+
* If the group-read bit is set but not the world-read bit, then
724+
* the group must be equal to the group of the original file. If
725+
* we can't make that happen then reset the group-read bit. This
726+
* avoids making the swap file readable to more users when the
727+
* primary group of the user is too permissive.
728+
*/
729+
if ((swap_mode & 044) == 040)
730+
{
731+
stat_T swap_st;
732+
733+
if (mch_stat((char *)swap_fname, &swap_st) >= 0
734+
&& st.st_gid != swap_st.st_gid
735+
&& fchown(curbuf->b_ml.ml_mfp->mf_fd, -1, st.st_gid)
736+
== -1)
737+
swap_mode &= 0600;
738+
}
739+
740+
(void)mch_setperm(swap_fname, (long)swap_mode);
741+
}
720742
#endif
721743
}
722744

src/term.c

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4553,22 +4553,6 @@ check_termcode(
45534553
{
45544554
int need_flush = FALSE;
45554555

4556-
/* Only set 'ttymouse' automatically if it was not set
4557-
* by the user already. */
4558-
if (!option_was_set((char_u *)"ttym"))
4559-
{
4560-
# ifdef TTYM_SGR
4561-
if (version >= 277)
4562-
set_option_value((char_u *)"ttym", 0L,
4563-
(char_u *)"sgr", 0);
4564-
else
4565-
# endif
4566-
/* if xterm version >= 95 use mouse dragging */
4567-
if (version >= 95)
4568-
set_option_value((char_u *)"ttym", 0L,
4569-
(char_u *)"xterm2", 0);
4570-
}
4571-
45724556
/* if xterm version >= 141 try to get termcap codes */
45734557
if (version >= 141)
45744558
{
@@ -4587,6 +4571,28 @@ check_termcode(
45874571
* 256, libvterm supports even more. */
45884572
if (mch_getenv((char_u *)"COLORS") == NULL)
45894573
may_adjust_color_count(256);
4574+
# ifdef FEAT_MOUSE_SGR
4575+
/* Libvterm can handle SGR mouse reporting. */
4576+
if (!option_was_set((char_u *)"ttym"))
4577+
set_option_value((char_u *)"ttym", 0L,
4578+
(char_u *)"sgr", 0);
4579+
# endif
4580+
}
4581+
4582+
/* Only set 'ttymouse' automatically if it was not set
4583+
* by the user already. */
4584+
if (!option_was_set((char_u *)"ttym"))
4585+
{
4586+
# ifdef FEAT_MOUSE_SGR
4587+
if (version >= 277)
4588+
set_option_value((char_u *)"ttym", 0L,
4589+
(char_u *)"sgr", 0);
4590+
else
4591+
# endif
4592+
/* if xterm version >= 95 use mouse dragging */
4593+
if (version >= 95)
4594+
set_option_value((char_u *)"ttym", 0L,
4595+
(char_u *)"xterm2", 0);
45904596
}
45914597

45924598
/* Detect terminals that set $TERM to something like

src/terminal.c

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
* in tl_scrollback are no longer used.
3939
*
4040
* TODO:
41+
* - Termdebug: issue #2154 might be avoided by adding -quiet to gdb?
42+
* patch by Christian, 2017 Oct 23.
4143
* - in GUI vertical split causes problems. Cursor is flickering. (Hirohito
4244
* Higashi, 2017 Sep 19)
4345
* - double click in Window toolbar starts Visual mode (but not always?).
@@ -51,8 +53,6 @@
5153
* Also: #2223
5254
* - implement term_setsize()
5355
* - Termdebug does not work when Vim build with mzscheme. gdb hangs.
54-
* - Termdebug: issue #2154 might be avoided by adding -quiet to gdb?
55-
* patch by Christian, 2017 Oct 23.
5656
* - MS-Windows GUI: WinBar has tearoff item
5757
* - MS-Windows GUI: still need to type a key after shell exits? #1924
5858
* - What to store in a session file? Shell at the prompt would be OK to
@@ -1540,6 +1540,9 @@ terminal_loop(int blocking)
15401540
int c;
15411541
int termkey = 0;
15421542
int ret;
1543+
#ifdef UNIX
1544+
int tty_fd = curbuf->b_term->tl_job->jv_channel->ch_part[get_tty_part(curbuf->b_term)].ch_fd;
1545+
#endif
15431546

15441547
/* Remember the terminal we are sending keys to. However, the terminal
15451548
* might be closed while waiting for a character, e.g. typing "exit" in a
@@ -1552,35 +1555,35 @@ terminal_loop(int blocking)
15521555
position_cursor(curwin, &curbuf->b_term->tl_cursor_pos);
15531556
may_set_cursor_props(curbuf->b_term);
15541557

1555-
#ifdef UNIX
1558+
while (blocking || vpeekc() != NUL)
15561559
{
1557-
int part = get_tty_part(curbuf->b_term);
1558-
int fd = curbuf->b_term->tl_job->jv_channel->ch_part[part].ch_fd;
1560+
/* TODO: skip screen update when handling a sequence of keys. */
1561+
/* Repeat redrawing in case a message is received while redrawing. */
1562+
while (must_redraw != 0)
1563+
if (update_screen(0) == FAIL)
1564+
break;
1565+
update_cursor(curbuf->b_term, FALSE);
15591566

1560-
if (isatty(fd))
1567+
#ifdef UNIX
1568+
/*
1569+
* The shell or another program may change the tty settings. Getting
1570+
* them for every typed character is a bit of overhead, but it's needed
1571+
* for the first CR typed, e.g. when Vim starts in a shell.
1572+
*/
1573+
if (isatty(tty_fd))
15611574
{
15621575
ttyinfo_T info;
15631576

15641577
/* Get the current backspace and enter characters of the pty. */
1565-
if (get_tty_info(fd, &info) == OK)
1578+
if (get_tty_info(tty_fd, &info) == OK)
15661579
{
15671580
term_backspace_char = info.backspace;
15681581
term_enter_char = info.enter;
15691582
term_nl_does_cr = info.nl_does_cr;
15701583
}
15711584
}
1572-
}
15731585
#endif
15741586

1575-
while (blocking || vpeekc() != NUL)
1576-
{
1577-
/* TODO: skip screen update when handling a sequence of keys. */
1578-
/* Repeat redrawing in case a message is received while redrawing. */
1579-
while (must_redraw != 0)
1580-
if (update_screen(0) == FAIL)
1581-
break;
1582-
update_cursor(curbuf->b_term, FALSE);
1583-
15841587
c = term_vgetc();
15851588
if (!term_use_loop())
15861589
/* job finished while waiting for a character */

src/testdir/runtest.vim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ let s:flaky = [
252252
\ 'Test_reltime()',
253253
\ 'Test_terminal_composing_unicode()',
254254
\ 'Test_terminal_noblock()',
255+
\ 'Test_terminal_redir_file()',
255256
\ 'Test_with_partial_callback()',
256257
\ ]
257258

src/testdir/shared.vim

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,9 @@ func s:kill_server(cmd)
113113
endif
114114
endfunc
115115

116-
" Wait for up to a second for "expr" to become true.
116+
" Wait for up to a second for "expr" to become true. "expr" can be a
117+
" stringified expression to evaluate, or a funcref without arguments.
118+
"
117119
" Return time slept in milliseconds. With the +reltime feature this can be
118120
" more than the actual waiting time. Without +reltime it can also be less.
119121
func WaitFor(expr, ...)
@@ -124,8 +126,13 @@ func WaitFor(expr, ...)
124126
else
125127
let slept = 0
126128
endif
129+
if type(a:expr) == v:t_func
130+
let Test = a:expr
131+
else
132+
let Test = {-> eval(a:expr) }
133+
endif
127134
for i in range(timeout / 10)
128-
if eval(a:expr)
135+
if Test()
129136
if has('reltime')
130137
return float2nr(reltimefloat(reltime(start)) * 1000)
131138
endif

src/testdir/test_channel.vim

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -274,12 +274,10 @@ func Ch_channel_handler(port)
274274
" Test that it works while waiting on a numbered message.
275275
call assert_equal('ok', ch_evalexpr(handle, 'call me'))
276276
call WaitFor('"we called you" == g:Ch_reply')
277-
call assert_equal('we called you', g:Ch_reply)
278277

279278
" Test that it works while not waiting on a numbered message.
280279
call ch_sendexpr(handle, 'call me again')
281280
call WaitFor('"we did call you" == g:Ch_reply')
282-
call assert_equal('we did call you', g:Ch_reply)
283281
endfunc
284282

285283
func Test_channel_handler()
@@ -322,7 +320,6 @@ func Ch_channel_zero(port)
322320
call assert_equal('sent zero', ch_evalexpr(handle, 'send zero'))
323321
if s:has_handler
324322
call WaitFor('"zero index" == g:Ch_reply')
325-
call assert_equal('zero index', g:Ch_reply)
326323
else
327324
sleep 20m
328325
call assert_equal('', g:Ch_reply)
@@ -338,7 +335,6 @@ func Ch_channel_zero(port)
338335
else
339336
call assert_equal('', g:Ch_reply)
340337
endif
341-
call assert_equal('sent zero', g:Ch_zero_reply)
342338
endfunc
343339

344340
func Test_zero_reply()
@@ -1468,7 +1464,7 @@ func Test_exit_callback_interval()
14681464
let g:exit_cb_val = {'start': reltime(), 'end': 0, 'process': 0}
14691465
let job = job_start([s:python, '-c', 'import time;time.sleep(0.5)'], {'exit_cb': 'MyExitTimeCb'})
14701466
let g:exit_cb_val.process = job_info(job).process
1471-
call WaitFor('type(g:exit_cb_val.end) != v:t_number || g:exit_cb_val.end != 0')
1467+
call WaitFor('type(g:exit_cb_val.end) != v:t_number || g:exit_cb_val.end != 0', 2000)
14721468
let elapsed = reltimefloat(g:exit_cb_val.end)
14731469
call assert_true(elapsed > 0.5)
14741470
call assert_true(elapsed < 1.0)

src/testdir/test_clientserver.vim

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,8 @@ func Test_client_server()
2727

2828
let name = 'XVIMTEST'
2929
let cmd .= ' --servername ' . name
30-
let g:job = job_start(cmd, {'stoponexit': 'kill', 'out_io': 'null'})
31-
call WaitFor('job_status(g:job) == "run"')
32-
if job_status(g:job) != 'run'
33-
call assert_report('Cannot run the Vim server')
34-
return
35-
endif
30+
let job = job_start(cmd, {'stoponexit': 'kill', 'out_io': 'null'})
31+
call WaitFor({-> job_status(job) == "run"})
3632

3733
" Takes a short while for the server to be active.
3834
" When using valgrind it takes much longer.
@@ -83,7 +79,7 @@ func Test_client_server()
8379
call remote_send(name, ":call server2client(expand('<client>'), 'another')\<CR>", 'g:myserverid')
8480
let peek_result = 'nothing'
8581
let r = remote_peek(g:myserverid, 'peek_result')
86-
" unpredictable whether the result is already avaialble.
82+
" unpredictable whether the result is already available.
8783
if r > 0
8884
call assert_equal('another', peek_result)
8985
elseif r == 0
@@ -97,11 +93,14 @@ func Test_client_server()
9793
call assert_equal('another', remote_read(g:myserverid, 2))
9894

9995
call remote_send(name, ":qa!\<CR>")
100-
call WaitFor('job_status(g:job) == "dead"')
101-
if job_status(g:job) != 'dead'
102-
call assert_report('Server did not exit')
103-
call job_stop(g:job, 'kill')
104-
endif
96+
try
97+
call WaitFor({-> job_status(job) == "dead"})
98+
finally
99+
if job_status(job) != 'dead'
100+
call assert_report('Server did not exit')
101+
call job_stop(job, 'kill')
102+
endif
103+
endtry
105104
endfunc
106105

107106
" Uncomment this line to get a debugging log

src/testdir/test_job_fails.vim

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,11 @@ source shared.vim
66

77
func Test_job_start_fails()
88
if has('job')
9-
let g:job = job_start('axdfxsdf')
9+
let job = job_start('axdfxsdf')
1010
if has('unix')
11-
call WaitFor('job_status(g:job) == "dead"')
12-
call assert_equal('dead', job_status(g:job))
11+
call WaitFor({-> job_status(job) == "dead"})
1312
else
14-
call WaitFor('job_status(g:job) == "fail"')
15-
call assert_equal('fail', job_status(g:job))
13+
call WaitFor({-> job_status(job) == "fail"})
1614
endif
17-
unlet g:job
1815
endif
1916
endfunc

0 commit comments

Comments
 (0)