Skip to content

Commit 130eee0

Browse files
committed
Merge remote-tracking branch 'vim/master'
2 parents fa9dd06 + 4445f7e commit 130eee0

14 files changed

Lines changed: 202 additions & 28 deletions

src/edit.c

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1535,7 +1535,12 @@ edit(
15351535

15361536
#ifdef FEAT_AUTOCMD
15371537
/* If typed something may trigger CursorHoldI again. */
1538-
if (c != K_CURSORHOLD)
1538+
if (c != K_CURSORHOLD
1539+
# ifdef FEAT_COMPL_FUNC
1540+
/* but not in CTRL-X mode, a script can't restore the state */
1541+
&& ctrl_x_mode == 0
1542+
# endif
1543+
)
15391544
did_cursorhold = FALSE;
15401545
#endif
15411546

@@ -2769,6 +2774,21 @@ ins_compl_make_cyclic(void)
27692774
return count;
27702775
}
27712776

2777+
/*
2778+
* Set variables that store noselect and noinsert behavior from the
2779+
* 'completeopt' value.
2780+
*/
2781+
void
2782+
completeopt_was_set()
2783+
{
2784+
compl_no_insert = FALSE;
2785+
compl_no_select = FALSE;
2786+
if (strstr((char *)p_cot, "noselect") != NULL)
2787+
compl_no_select = TRUE;
2788+
if (strstr((char *)p_cot, "noinsert") != NULL)
2789+
compl_no_insert = TRUE;
2790+
}
2791+
27722792
/*
27732793
* Start completion for the complete() function.
27742794
* "startcol" is where the matched text starts (1 is first column).
@@ -2807,12 +2827,15 @@ set_completion(colnr_T startcol, list_T *list)
28072827
compl_cont_status = 0;
28082828

28092829
compl_curr_match = compl_first_match;
2810-
if (compl_no_insert)
2830+
if (compl_no_insert || compl_no_select)
2831+
{
28112832
ins_complete(K_DOWN, FALSE);
2833+
if (compl_no_select)
2834+
/* Down/Up has no real effect. */
2835+
ins_complete(K_UP, FALSE);
2836+
}
28122837
else
28132838
ins_complete(Ctrl_N, FALSE);
2814-
if (compl_no_select)
2815-
ins_complete(Ctrl_P, FALSE);
28162839

28172840
/* Lazily show the popup menu, unless we got interrupted. */
28182841
if (!compl_interrupted)
@@ -3689,13 +3712,6 @@ ins_compl_prep(int c)
36893712

36903713
}
36913714

3692-
compl_no_insert = FALSE;
3693-
compl_no_select = FALSE;
3694-
if (strstr((char *)p_cot, "noselect") != NULL)
3695-
compl_no_select = TRUE;
3696-
if (strstr((char *)p_cot, "noinsert") != NULL)
3697-
compl_no_insert = TRUE;
3698-
36993715
if (ctrl_x_mode == CTRL_X_NOT_DEFINED_YET)
37003716
{
37013717
/*
@@ -4975,8 +4991,7 @@ ins_compl_check_keys(int frequency)
49754991
ins_compl_key2dir(int c)
49764992
{
49774993
if (c == Ctrl_P || c == Ctrl_L
4978-
|| (pum_visible() && (c == K_PAGEUP || c == K_KPAGEUP
4979-
|| c == K_S_UP || c == K_UP)))
4994+
|| c == K_PAGEUP || c == K_KPAGEUP || c == K_S_UP || c == K_UP)
49804995
return BACKWARD;
49814996
return FORWARD;
49824997
}

src/eval.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6051,7 +6051,7 @@ list_alloc(void)
60516051
}
60526052

60536053
/*
6054-
* Allocate an empty list for a return value.
6054+
* Allocate an empty list for a return value, with reference count set.
60556055
* Returns OK or FAIL.
60566056
*/
60576057
int
@@ -11547,6 +11547,7 @@ f_feedkeys(typval_T *argvars, typval_T *rettv UNUSED)
1154711547
char_u nbuf[NUMBUFLEN];
1154811548
int typed = FALSE;
1154911549
int execute = FALSE;
11550+
int dangerous = FALSE;
1155011551
char_u *keys_esc;
1155111552

1155211553
/* This is not allowed in the sandbox. If the commands would still be
@@ -11569,6 +11570,7 @@ f_feedkeys(typval_T *argvars, typval_T *rettv UNUSED)
1156911570
case 't': typed = TRUE; break;
1157011571
case 'i': insert = TRUE; break;
1157111572
case 'x': execute = TRUE; break;
11573+
case '!': dangerous = TRUE; break;
1157211574
}
1157311575
}
1157411576
}
@@ -11592,9 +11594,11 @@ f_feedkeys(typval_T *argvars, typval_T *rettv UNUSED)
1159211594
/* Avoid a 1 second delay when the keys start Insert mode. */
1159311595
msg_scroll = FALSE;
1159411596

11595-
++ex_normal_busy;
11597+
if (!dangerous)
11598+
++ex_normal_busy;
1159611599
exec_normal(TRUE);
11597-
--ex_normal_busy;
11600+
if (!dangerous)
11601+
--ex_normal_busy;
1159811602
msg_scroll |= save_msg_scroll;
1159911603
}
1160011604
}
@@ -13180,7 +13184,9 @@ f_getreg(typval_T *argvars, typval_T *rettv)
1318013184
rettv->v_type = VAR_LIST;
1318113185
rettv->vval.v_list = (list_T *)get_reg_contents(regname,
1318213186
(arg2 ? GREG_EXPR_SRC : 0) | GREG_LIST);
13183-
if (rettv->vval.v_list != NULL)
13187+
if (rettv->vval.v_list == NULL)
13188+
rettv_list_alloc(rettv);
13189+
else
1318413190
++rettv->vval.v_list->lv_refcount;
1318513191
}
1318613192
else

src/fileio.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,18 @@ static void vim_settempdir(char_u *tempdir);
141141
#endif
142142
#ifdef FEAT_AUTOCMD
143143
static char *e_auchangedbuf = N_("E812: Autocommands changed buffer or buffer name");
144+
#endif
145+
146+
#ifdef FEAT_AUTOCMD
147+
/*
148+
* Set by the apply_autocmds_group function if the given event is equal to
149+
* EVENT_FILETYPE. Used by the readfile function in order to determine if
150+
* EVENT_BUFREADPOST triggered the EVENT_FILETYPE.
151+
*
152+
* Relying on this value requires one to reset it prior calling
153+
* apply_autocmds_group.
154+
*/
155+
static int au_did_filetype INIT(= FALSE);
144156
#endif
145157

146158
void
@@ -305,6 +317,10 @@ readfile(
305317
int using_b_fname;
306318
#endif
307319

320+
#ifdef FEAT_AUTOCMD
321+
au_did_filetype = FALSE; /* reset before triggering any autocommands */
322+
#endif
323+
308324
curbuf->b_no_eol_lnum = 0; /* in case it was set by the previous read */
309325

310326
/*
@@ -2669,8 +2685,17 @@ readfile(
26692685
apply_autocmds_exarg(EVENT_FILTERREADPOST, NULL, sfname,
26702686
FALSE, curbuf, eap);
26712687
else if (newfile)
2688+
{
26722689
apply_autocmds_exarg(EVENT_BUFREADPOST, NULL, sfname,
26732690
FALSE, curbuf, eap);
2691+
if (!au_did_filetype && *curbuf->b_p_ft != NUL)
2692+
/*
2693+
* EVENT_FILETYPE was not triggered but the buffer already has a
2694+
* filetype. Trigger EVENT_FILETYPE using the existing filetype.
2695+
*/
2696+
apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft, curbuf->b_fname,
2697+
TRUE, curbuf);
2698+
}
26742699
else
26752700
apply_autocmds_exarg(EVENT_FILEREADPOST, sfname, sfname,
26762701
FALSE, NULL, eap);
@@ -9575,6 +9600,9 @@ apply_autocmds_group(
95759600
if (event == EVENT_BUFWIPEOUT && buf != NULL)
95769601
aubuflocal_remove(buf);
95779602

9603+
if (retval == OK && event == EVENT_FILETYPE)
9604+
au_did_filetype = TRUE;
9605+
95789606
return retval;
95799607
}
95809608

src/gui.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2898,6 +2898,7 @@ gui_wait_for_chars_or_timer(long wtime)
28982898
#ifdef FEAT_TIMERS
28992899
int due_time;
29002900
long remaining = wtime;
2901+
int tb_change_cnt = typebuf.tb_change_cnt;
29012902

29022903
/* When waiting very briefly don't trigger timers. */
29032904
if (wtime >= 0 && wtime < 10L)
@@ -2908,6 +2909,11 @@ gui_wait_for_chars_or_timer(long wtime)
29082909
/* Trigger timers and then get the time in wtime until the next one is
29092910
* due. Wait up to that time. */
29102911
due_time = check_due_timer();
2912+
if (typebuf.tb_change_cnt != tb_change_cnt)
2913+
{
2914+
/* timer may have used feedkeys() */
2915+
return FALSE;
2916+
}
29112917
if (due_time <= 0 || (wtime > 0 && due_time > remaining))
29122918
due_time = remaining;
29132919
if (gui_mch_wait_for_chars(due_time))

src/option.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1802,7 +1802,7 @@ static struct vimoption options[] =
18021802
(char_u *)&p_lpl, PV_NONE,
18031803
{(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
18041804
#if defined(DYNAMIC_LUA)
1805-
{"luadll", NULL, P_STRING|P_VI_DEF|P_SECURE,
1805+
{"luadll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
18061806
(char_u *)&p_luadll, PV_NONE,
18071807
{(char_u *)DYNAMIC_LUA_DLL, (char_u *)0L}
18081808
SCRIPTID_INIT},
@@ -2060,7 +2060,7 @@ static struct vimoption options[] =
20602060
#endif
20612061
(char_u *)0L} SCRIPTID_INIT},
20622062
#if defined(DYNAMIC_PERL)
2063-
{"perldll", NULL, P_STRING|P_VI_DEF|P_SECURE,
2063+
{"perldll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
20642064
(char_u *)&p_perldll, PV_NONE,
20652065
{(char_u *)DYNAMIC_PERL_DLL, (char_u *)0L}
20662066
SCRIPTID_INIT},
@@ -2171,13 +2171,13 @@ static struct vimoption options[] =
21712171
#endif
21722172
{(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
21732173
#if defined(DYNAMIC_PYTHON3)
2174-
{"pythonthreedll", NULL, P_STRING|P_VI_DEF|P_SECURE,
2174+
{"pythonthreedll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
21752175
(char_u *)&p_py3dll, PV_NONE,
21762176
{(char_u *)DYNAMIC_PYTHON3_DLL, (char_u *)0L}
21772177
SCRIPTID_INIT},
21782178
#endif
21792179
#if defined(DYNAMIC_PYTHON)
2180-
{"pythondll", NULL, P_STRING|P_VI_DEF|P_SECURE,
2180+
{"pythondll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
21812181
(char_u *)&p_pydll, PV_NONE,
21822182
{(char_u *)DYNAMIC_PYTHON_DLL, (char_u *)0L}
21832183
SCRIPTID_INIT},
@@ -2256,7 +2256,7 @@ static struct vimoption options[] =
22562256
#endif
22572257
SCRIPTID_INIT},
22582258
#if defined(DYNAMIC_RUBY)
2259-
{"rubydll", NULL, P_STRING|P_VI_DEF|P_SECURE,
2259+
{"rubydll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
22602260
(char_u *)&p_rubydll, PV_NONE,
22612261
{(char_u *)DYNAMIC_RUBY_DLL, (char_u *)0L}
22622262
SCRIPTID_INIT},
@@ -2640,7 +2640,7 @@ static struct vimoption options[] =
26402640
(char_u *)&p_tgst, PV_NONE,
26412641
{(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
26422642
#if defined(DYNAMIC_TCL)
2643-
{"tcldll", NULL, P_STRING|P_VI_DEF|P_SECURE,
2643+
{"tcldll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
26442644
(char_u *)&p_tcldll, PV_NONE,
26452645
{(char_u *)DYNAMIC_TCL_DLL, (char_u *)0L}
26462646
SCRIPTID_INIT},
@@ -7036,6 +7036,8 @@ did_set_string_option(
70367036
{
70377037
if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
70387038
errmsg = e_invarg;
7039+
else
7040+
completeopt_was_set();
70397041
}
70407042
#endif /* FEAT_INS_EXPAND */
70417043

src/os_unix.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ mch_inchar(
397397

398398
if (wtime >= 0)
399399
{
400-
while (WaitForChar(wtime) == 0) /* no character available */
400+
while (!WaitForChar(wtime)) /* no character available */
401401
{
402402
if (do_resize)
403403
handle_resize();
@@ -420,7 +420,7 @@ mch_inchar(
420420
* flush all the swap files to disk.
421421
* Also done when interrupted by SIGWINCH.
422422
*/
423-
if (WaitForChar(p_ut) == 0)
423+
if (!WaitForChar(p_ut))
424424
{
425425
#ifdef FEAT_AUTOCMD
426426
if (trigger_cursorhold() && maxlen >= 3
@@ -448,7 +448,7 @@ mch_inchar(
448448
* We want to be interrupted by the winch signal
449449
* or by an event on the monitored file descriptors.
450450
*/
451-
if (WaitForChar(-1L) == 0)
451+
if (!WaitForChar(-1L))
452452
{
453453
if (do_resize) /* interrupted by SIGWINCH signal */
454454
handle_resize();
@@ -482,7 +482,7 @@ handle_resize(void)
482482
}
483483

484484
/*
485-
* return non-zero if a character is available
485+
* Return non-zero if a character is available.
486486
*/
487487
int
488488
mch_char_avail(void)
@@ -5232,7 +5232,7 @@ mch_start_job(char **argv, job_T *job, jobopt_T *options UNUSED)
52325232
/* See above for type of argv. */
52335233
execvp(argv[0], argv);
52345234

5235-
perror("executing job failed");
5235+
// perror("executing job failed");
52365236
_exit(EXEC_FAILED); /* exec failed, return failure code */
52375237
}
52385238

@@ -5381,6 +5381,7 @@ mch_breakcheck(void)
53815381
* "msec" == -1 will block forever.
53825382
* Invokes timer callbacks when needed.
53835383
* When a GUI is being used, this will never get called -- webb
5384+
* Returns TRUE when a character is available.
53845385
*/
53855386
static int
53865387
WaitForChar(long msec)
@@ -5389,6 +5390,7 @@ WaitForChar(long msec)
53895390
long due_time;
53905391
long remaining = msec;
53915392
int break_loop = FALSE;
5393+
int tb_change_cnt = typebuf.tb_change_cnt;
53925394

53935395
/* When waiting very briefly don't trigger timers. */
53945396
if (msec >= 0 && msec < 10L)
@@ -5399,6 +5401,11 @@ WaitForChar(long msec)
53995401
/* Trigger timers and then get the time in msec until the next one is
54005402
* due. Wait up to that time. */
54015403
due_time = check_due_timer();
5404+
if (typebuf.tb_change_cnt != tb_change_cnt)
5405+
{
5406+
/* timer may have used feedkeys() */
5407+
return FALSE;
5408+
}
54025409
if (due_time <= 0 || (msec > 0 && due_time > remaining))
54035410
due_time = remaining;
54045411
if (WaitForCharOrMouse(due_time, &break_loop))

src/os_win32.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1446,6 +1446,9 @@ WaitForChar(long msec)
14461446
INPUT_RECORD ir;
14471447
DWORD cRecords;
14481448
WCHAR ch, ch2;
1449+
#ifdef FEAT_TIMERS
1450+
int tb_change_cnt = typebuf.tb_change_cnt;
1451+
#endif
14491452

14501453
if (msec > 0)
14511454
/* Wait until the specified time has elapsed. */
@@ -1511,6 +1514,11 @@ WaitForChar(long msec)
15111514
/* Trigger timers and then get the time in msec until the
15121515
* next one is due. Wait up to that time. */
15131516
due_time = check_due_timer();
1517+
if (typebuf.tb_change_cnt != tb_change_cnt)
1518+
{
1519+
/* timer may have used feedkeys() */
1520+
return FALSE;
1521+
}
15141522
if (due_time > 0 && dwWaitTime > (DWORD)due_time)
15151523
dwWaitTime = due_time;
15161524
}

src/proto/edit.pro

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ void truncate_spaces(char_u *line);
88
void backspace_until_column(int col);
99
int vim_is_ctrl_x_key(int c);
1010
int ins_compl_add_infercase(char_u *str, int len, int icase, char_u *fname, int dir, int flags);
11+
void completeopt_was_set(void);
1112
void set_completion(colnr_T startcol, list_T *list);
1213
void ins_compl_show_pum(void);
1314
char_u *find_word_start(char_u *ptr);

src/testdir/test_alot.vim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ source test_delete.vim
88
source test_ex_undo.vim
99
source test_expr.vim
1010
source test_expand.vim
11+
source test_expand_dllpath.vim
1112
source test_feedkeys.vim
1213
source test_fnamemodify.vim
1314
source test_file_perm.vim

0 commit comments

Comments
 (0)