From 5c754a2d2263e455ba3704cd278d52b254d195df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Linse?= Date: Sun, 5 Jun 2016 10:59:40 +0200 Subject: [PATCH] timers: make repeat=0 work one-shot (consistent with vim) --- src/nvim/eval.c | 3 +++ test/functional/eval/timer_spec.lua | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/src/nvim/eval.c b/src/nvim/eval.c index f45612a886..06ed3407dd 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -16639,6 +16639,9 @@ static void f_timer_start(typval_T *argvars, typval_T *rettv) } if (dict_find(dict, (char_u *)"repeat", -1) != NULL) { repeat = get_dict_number(dict, (char_u *)"repeat"); + if (repeat == 0) { + repeat = 1; + } } } diff --git a/test/functional/eval/timer_spec.lua b/test/functional/eval/timer_spec.lua index 82b965c832..2f83edb9e4 100644 --- a/test/functional/eval/timer_spec.lua +++ b/test/functional/eval/timer_spec.lua @@ -22,6 +22,14 @@ describe('timers', function() eq(1,eval("g:val")) end) + it('works one-shot when repeat=0', function() + execute("call timer_start(50, 'MyHandler', {'repeat': 0})") + eq(0,eval("g:val")) + run(nil, nil, nil, 200) + eq(1,eval("g:val")) + end) + + it('works with repeat two', function() execute("call timer_start(50, 'MyHandler', {'repeat': 2})") eq(0,eval("g:val"))