# HG changeset patch # User Bram Moolenaar # Date 1639075503 -3600 # Node ID 7426c2657710fa806e065a8aab8190bcce1dbcde # Parent 9f535da74f6f692121bd8b5501ebb791b360e39e patch 8.2.3768: timer_info() has the wrong repeat value in a timer callback Commit: https://github.com/vim/vim/commit/95b2dd0c008f0977ebb3cbe233a5064001a332e1 Author: Bram Moolenaar Date: Thu Dec 9 18:42:57 2021 +0000 patch 8.2.3768: timer_info() has the wrong repeat value in a timer callback Problem: timer_info() has the wrong repeat value in a timer callback. Solution: Do not add one to the repeat value when in the callback. (closes #9294) diff --git a/src/testdir/test_timers.vim b/src/testdir/test_timers.vim --- a/src/testdir/test_timers.vim +++ b/src/testdir/test_timers.vim @@ -117,6 +117,13 @@ func Test_timer_info() call assert_equal([], timer_info(id)) call assert_fails('call timer_info("abc")', 'E39:') + + " check repeat count inside the callback + let g:timer_repeat = [] + let tid = timer_start(10, {tid -> execute("call add(g:timer_repeat, timer_info(tid)[0].repeat)")}, #{repeat: 3}) + sleep 100m + call assert_equal([2, 1, 0], g:timer_repeat) + unlet g:timer_repeat endfunc func Test_timer_stopall() diff --git a/src/time.c b/src/time.c --- a/src/time.c +++ b/src/time.c @@ -696,7 +696,8 @@ add_timer_info(typval_T *rettv, timer_T dict_add_number(dict, "remaining", (long)remaining); dict_add_number(dict, "repeat", - (long)(timer->tr_repeat < 0 ? -1 : timer->tr_repeat + 1)); + (long)(timer->tr_repeat < 0 ? -1 + : timer->tr_repeat + (timer->tr_firing ? 0 : 1))); dict_add_number(dict, "paused", (long)(timer->tr_paused)); di = dictitem_alloc((char_u *)"callback"); diff --git a/src/version.c b/src/version.c --- a/src/version.c +++ b/src/version.c @@ -754,6 +754,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 3768, +/**/ 3767, /**/ 3766,