Skip to content

Commit 312c032

Browse files
committed
Merge remote-tracking branch 'vim/master'
2 parents 4f87e76 + c4dcd60 commit 312c032

16 files changed

Lines changed: 145 additions & 37 deletions

runtime/doc/autocmd.txt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -918,7 +918,15 @@ VimEnter After doing all the startup stuff, including
918918
loading .vimrc files, executing the "-c cmd"
919919
arguments, creating all windows and loading
920920
the buffers in them.
921-
*VimLeave*
921+
Just before this event is triggered the
922+
|v:vim_did_enter| variable is set, so that you
923+
can do: >
924+
if v:vim_did_enter
925+
call s:init()
926+
else
927+
au VimEnter * call s:init()
928+
endif
929+
< *VimLeave*
922930
VimLeave Before exiting Vim, just after writing the
923931
.viminfo file. Executed only once, like
924932
VimLeavePre.

runtime/doc/eval.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1762,6 +1762,10 @@ v:version Version number of Vim: Major version number times 100 plus
17621762
version 5.0 and 5.1 may have a patch 123, but these are
17631763
completely different.
17641764

1765+
*v:vim_did_enter* *vim_did_enter-variable*
1766+
v:vim_did_enter Zero until most of startup is done. It is set to one just
1767+
before |VimEnter| autocommands are triggered.
1768+
17651769
*v:warningmsg* *warningmsg-variable*
17661770
v:warningmsg Last given warning message. It's allowed to set this variable.
17671771

src/channel.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1680,8 +1680,17 @@ channel_exe_cmd(channel_T *channel, int part, typval_T *argv)
16801680

16811681
if (STRCMP(cmd, "ex") == 0)
16821682
{
1683+
int save_called_emsg = called_emsg;
1684+
1685+
called_emsg = FALSE;
16831686
ch_logs(channel, "Executing ex command '%s'", (char *)arg);
1687+
++emsg_silent;
16841688
do_cmdline_cmd(arg);
1689+
--emsg_silent;
1690+
if (called_emsg)
1691+
ch_logs(channel, "Ex command error: '%s'",
1692+
(char *)get_vim_var_str(VV_ERRMSG));
1693+
called_emsg = save_called_emsg;
16851694
}
16861695
else if (STRCMP(cmd, "normal") == 0)
16871696
{

src/eval.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,7 @@ static struct vimvar
372372
{VV_NAME("true", VAR_SPECIAL), VV_RO},
373373
{VV_NAME("null", VAR_SPECIAL), VV_RO},
374374
{VV_NAME("none", VAR_SPECIAL), VV_RO},
375+
{VV_NAME("vim_did_enter", VAR_NUMBER), VV_RO},
375376
};
376377

377378
/* shorthand */
@@ -13856,7 +13857,7 @@ f_has(typval_T *argvars, typval_T *rettv)
1385613857
if (STRNICMP(name, "patch", 5) == 0)
1385713858
{
1385813859
if (name[5] == '-'
13859-
&& STRLEN(name) > 11
13860+
&& STRLEN(name) >= 11
1386013861
&& vim_isdigit(name[6])
1386113862
&& vim_isdigit(name[8])
1386213863
&& vim_isdigit(name[10]))
@@ -20217,6 +20218,7 @@ get_callback(typval_T *arg, partial_T **pp)
2021720218
if (arg->v_type == VAR_PARTIAL && arg->vval.v_partial != NULL)
2021820219
{
2021920220
*pp = arg->vval.v_partial;
20221+
++(*pp)->pt_refcount;
2022020222
return (*pp)->pt_name;
2022120223
}
2022220224
*pp = NULL;

src/main.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,6 +1012,9 @@ vim_main2(int argc UNUSED, char **argv UNUSED)
10121012
if (p_im)
10131013
need_start_insertmode = TRUE;
10141014

1015+
#ifdef FEAT_EVAL
1016+
set_vim_var_nr(VV_VIM_DID_ENTER, 1L);
1017+
#endif
10151018
#ifdef FEAT_AUTOCMD
10161019
apply_autocmds(EVENT_VIMENTER, NULL, NULL, FALSE, curbuf);
10171020
TIME_MSG("VimEnter autocommands");

src/os_unix.c

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -176,11 +176,11 @@ typedef int waitstatus;
176176
static pid_t wait4pid(pid_t, waitstatus *);
177177

178178
static int WaitForChar(long);
179-
static int WaitForCharOrMouse(long);
179+
static int WaitForCharOrMouse(long, int *break_loop);
180180
#if defined(__BEOS__) || defined(VMS)
181-
int RealWaitForChar(int, long, int *);
181+
int RealWaitForChar(int, long, int *, int *break_loop);
182182
#else
183-
static int RealWaitForChar(int, long, int *);
183+
static int RealWaitForChar(int, long, int *, int *break_loop);
184184
#endif
185185

186186
#ifdef FEAT_XCLIPBOARD
@@ -366,7 +366,7 @@ mch_write(char_u *s, int len)
366366
{
367367
ignored = (int)write(1, (char *)s, len);
368368
if (p_wd) /* Unix is too fast, slow down a bit more */
369-
RealWaitForChar(read_cmd_fd, p_wd, NULL);
369+
RealWaitForChar(read_cmd_fd, p_wd, NULL, NULL);
370370
}
371371

372372
/*
@@ -4780,7 +4780,7 @@ mch_call_shell(
47804780
* to some terminal (vt52?).
47814781
*/
47824782
++noread_cnt;
4783-
while (RealWaitForChar(fromshell_fd, 10L, NULL))
4783+
while (RealWaitForChar(fromshell_fd, 10L, NULL, NULL))
47844784
{
47854785
len = read_eintr(fromshell_fd, buffer
47864786
# ifdef FEAT_MBYTE
@@ -5365,7 +5365,7 @@ mch_clear_job(job_T *job)
53655365
void
53665366
mch_breakcheck(void)
53675367
{
5368-
if (curr_tmode == TMODE_RAW && RealWaitForChar(read_cmd_fd, 0L, NULL))
5368+
if (curr_tmode == TMODE_RAW && RealWaitForChar(read_cmd_fd, 0L, NULL, NULL))
53695369
fill_input_buf(FALSE);
53705370
}
53715371

@@ -5382,10 +5382,11 @@ WaitForChar(long msec)
53825382
#ifdef FEAT_TIMERS
53835383
long due_time;
53845384
long remaining = msec;
5385+
int break_loop = FALSE;
53855386

53865387
/* When waiting very briefly don't trigger timers. */
53875388
if (msec >= 0 && msec < 10L)
5388-
return WaitForCharOrMouse(msec);
5389+
return WaitForCharOrMouse(msec, NULL);
53895390

53905391
while (msec < 0 || remaining > 0)
53915392
{
@@ -5394,14 +5395,18 @@ WaitForChar(long msec)
53945395
due_time = check_due_timer();
53955396
if (due_time <= 0 || (msec > 0 && due_time > remaining))
53965397
due_time = remaining;
5397-
if (WaitForCharOrMouse(due_time))
5398+
if (WaitForCharOrMouse(due_time, &break_loop))
53985399
return TRUE;
5400+
if (break_loop)
5401+
/* Nothing available, but need to return so that side effects get
5402+
* handled, such as handling a message on a channel. */
5403+
return FALSE;
53995404
if (msec > 0)
54005405
remaining -= due_time;
54015406
}
54025407
return FALSE;
54035408
#else
5404-
return WaitForCharOrMouse(msec);
5409+
return WaitForCharOrMouse(msec, NULL);
54055410
#endif
54065411
}
54075412

@@ -5412,7 +5417,7 @@ WaitForChar(long msec)
54125417
* When a GUI is being used, this will never get called -- webb
54135418
*/
54145419
static int
5415-
WaitForCharOrMouse(long msec)
5420+
WaitForCharOrMouse(long msec, int *break_loop)
54165421
{
54175422
#ifdef FEAT_MOUSE_GPM
54185423
int gpm_process_wanted;
@@ -5458,9 +5463,10 @@ WaitForCharOrMouse(long msec)
54585463
# endif
54595464
# ifdef FEAT_MOUSE_GPM
54605465
gpm_process_wanted = 0;
5461-
avail = RealWaitForChar(read_cmd_fd, msec, &gpm_process_wanted);
5466+
avail = RealWaitForChar(read_cmd_fd, msec,
5467+
&gpm_process_wanted, break_loop);
54625468
# else
5463-
avail = RealWaitForChar(read_cmd_fd, msec, NULL);
5469+
avail = RealWaitForChar(read_cmd_fd, msec, NULL, break_loop);
54645470
# endif
54655471
if (!avail)
54665472
{
@@ -5479,10 +5485,11 @@ WaitForCharOrMouse(long msec)
54795485
# ifdef FEAT_XCLIPBOARD
54805486
|| (!avail && rest != 0)
54815487
# endif
5482-
);
5488+
)
5489+
;
54835490

54845491
#else
5485-
avail = RealWaitForChar(read_cmd_fd, msec, NULL);
5492+
avail = RealWaitForChar(read_cmd_fd, msec, NULL, break_loop);
54865493
#endif
54875494
return avail;
54885495
}
@@ -5501,7 +5508,7 @@ WaitForCharOrMouse(long msec)
55015508
#else
55025509
static int
55035510
#endif
5504-
RealWaitForChar(int fd, long msec, int *check_for_gpm UNUSED)
5511+
RealWaitForChar(int fd, long msec, int *check_for_gpm UNUSED, int *break_loop)
55055512
{
55065513
int ret;
55075514
int result;
@@ -5614,6 +5621,8 @@ RealWaitForChar(int fd, long msec, int *check_for_gpm UNUSED)
56145621
ret = poll(fds, nfd, towait);
56155622

56165623
result = ret > 0 && (fds[0].revents & POLLIN);
5624+
if (break_loop != NULL && ret > 0)
5625+
*break_loop = TRUE;
56175626

56185627
# ifdef FEAT_MZSCHEME
56195628
if (ret == 0 && mzquantum_used)
@@ -5745,6 +5754,8 @@ RealWaitForChar(int fd, long msec, int *check_for_gpm UNUSED)
57455754
result = ret > 0 && FD_ISSET(fd, &rfds);
57465755
if (result)
57475756
--ret;
5757+
if (break_loop != NULL && ret > 0)
5758+
*break_loop = TRUE;
57485759

57495760
# ifdef EINTR
57505761
if (ret == -1 && errno == EINTR)

src/testdir/test60.in

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -589,15 +589,6 @@ endfunction
589589
endfunction
590590
:call TestExists()
591591
:"
592-
:function TestHas()
593-
redir >> test.out
594-
for pl in ['6.9.999', '7.1.999', '7.4.123', '9.1.0', '9.9.1']
595-
echo 'has patch ' . pl . ': ' . has('patch-' . pl)
596-
endfor
597-
redir END
598-
endfunc
599-
:call TestHas()
600-
:"
601592
:delfunc TestExists
602593
:delfunc RunTest
603594
:delfunc TestFuncArg

src/testdir/test60.ok

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,3 @@ OK
204204
g:footest#x = 1
205205
footest#F() 0
206206
UndefFun() 0
207-
has patch 6.9.999: 1
208-
has patch 7.1.999: 1
209-
has patch 7.4.123: 1
210-
has patch 9.1.0: 0
211-
has patch 9.9.1: 0

src/testdir/test_alot.vim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
" This makes testing go faster, since Vim doesn't need to restart.
33

44
source test_assign.vim
5+
source test_autocmd.vim
56
source test_cursor_func.vim
67
source test_delete.vim
78
source test_ex_undo.vim

src/testdir/test_autocmd.vim

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
" Tests for autocommands
2+
3+
func Test_vim_did_enter()
4+
call assert_false(v:vim_did_enter)
5+
6+
" This script will never reach the main loop, can't check if v:vim_did_enter
7+
" becomes one.
8+
endfunc

0 commit comments

Comments
 (0)