Permalink
Browse files

patch 8.0.0670: can't use input() in a timer callback

Problem:    Can't use input() in a timer callback. (Cosmin Popescu)
Solution:   Reset vgetc_busy and set timer_busy. (Ozaki Kiichi, closes #1790,
            closes #1129)
  • Loading branch information...
brammool committed Jun 24, 2017
1 parent 24a9e34 commit 1e8e14552e0cc8881411eb8fbe39a654dae42554
Showing with 27 additions and 1 deletion.
  1. +1 −1 src/evalfunc.c
  2. +7 −0 src/ex_cmds2.c
  3. +1 −0 src/globals.h
  4. +16 −0 src/testdir/test_timers.vim
  5. +2 −0 src/version.c
View
@@ -3191,7 +3191,7 @@ f_feedkeys(typval_T *argvars, typval_T *rettv UNUSED)
ins_typebuf(keys_esc, (remap ? REMAP_YES : REMAP_NONE),
insert ? 0 : typebuf.tb_len, !typed, FALSE);
vim_free(keys_esc);
if (vgetc_busy)
if (vgetc_busy || timer_busy)
typebuf_was_filled = TRUE;
if (execute)
{
View
@@ -1209,11 +1209,18 @@ check_due_timer(void)
this_due = GET_TIMEDIFF(timer, now);
if (this_due <= 1)
{
int save_timer_busy = timer_busy;
int save_vgetc_busy = vgetc_busy;
timer_busy = timer_busy > 0 || vgetc_busy > 0;
vgetc_busy = 0;
timer->tr_firing = TRUE;
timer_callback(timer);
timer->tr_firing = FALSE;
timer_next = timer->tr_next;
did_one = TRUE;
timer_busy = save_timer_busy;
vgetc_busy = save_vgetc_busy;
/* Only fire the timer again if it repeats and stop_timer() wasn't
* called while inside the callback (tr_id == -1). */
View
@@ -1659,6 +1659,7 @@ EXTERN int in_free_unref_items INIT(= FALSE);
#ifdef FEAT_TIMERS
EXTERN int did_add_timer INIT(= FALSE);
EXTERN int timer_busy INIT(= 0); /* when timer is inside vgetc() then > 0 */
#endif
#ifdef FEAT_EVAL
@@ -172,5 +172,21 @@ func Test_stop_all_in_callback()
call assert_equal(0, len(info))
endfunc
func FeedkeysCb(timer)
call feedkeys("hello\<CR>", 'nt')
endfunc
func InputCb(timer)
call timer_start(10, 'FeedkeysCb')
let g:val = input('?')
call Resume()
endfunc
func Test_input_in_timer()
let g:val = ''
call timer_start(10, 'InputCb')
call Standby(1000)
call assert_equal('hello', g:val)
endfunc
" vim: shiftwidth=2 sts=2 expandtab
View
@@ -764,6 +764,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
670,
/**/
669,
/**/

0 comments on commit 1e8e145

Please sign in to comment.