diff src/evalfunc.c @ 9810:6a28d0c6f929 v7.4.2180

commit https://github.com/vim/vim/commit/b73598e2f022a22fec512ea681c70d2775e8fd87 Author: Bram Moolenaar <Bram@vim.org> Date: Sun Aug 7 18:22:53 2016 +0200 patch 7.4.2180 Problem: There is no easy way to stop all timers. There is no way to temporary pause a timer. Solution: Add timer_stopall() and timer_pause().
author Christian Brabandt <cb@256bit.org>
date Sun, 07 Aug 2016 18:30:05 +0200
parents 34cc6a101340
children 67781bb0a61a
line wrap: on
line diff
--- a/src/evalfunc.c
+++ b/src/evalfunc.c
@@ -397,8 +397,10 @@ static void f_tanh(typval_T *argvars, ty
 #endif
 #ifdef FEAT_TIMERS
 static void f_timer_info(typval_T *argvars, typval_T *rettv);
+static void f_timer_pause(typval_T *argvars, typval_T *rettv);
 static void f_timer_start(typval_T *argvars, typval_T *rettv);
 static void f_timer_stop(typval_T *argvars, typval_T *rettv);
+static void f_timer_stopall(typval_T *argvars, typval_T *rettv);
 #endif
 static void f_tolower(typval_T *argvars, typval_T *rettv);
 static void f_toupper(typval_T *argvars, typval_T *rettv);
@@ -817,8 +819,10 @@ static struct fst
     {"test_settime",	1, 1, f_test_settime},
 #ifdef FEAT_TIMERS
     {"timer_info",	0, 1, f_timer_info},
+    {"timer_pause",	2, 2, f_timer_pause},
     {"timer_start",	2, 3, f_timer_start},
     {"timer_stop",	1, 1, f_timer_stop},
+    {"timer_stopall",	0, 0, f_timer_stopall},
 #endif
     {"tolower",		1, 1, f_tolower},
     {"toupper",		1, 1, f_toupper},
@@ -11988,6 +11992,25 @@ f_timer_info(typval_T *argvars, typval_T
 }
 
 /*
+ * "timer_pause(timer, paused)" function
+ */
+    static void
+f_timer_pause(typval_T *argvars, typval_T *rettv UNUSED)
+{
+    timer_T	*timer = NULL;
+    int		paused = (int)get_tv_number(&argvars[1]);
+
+    if (argvars[0].v_type != VAR_NUMBER)
+	EMSG(_(e_number_exp));
+    else
+    {
+	timer = find_timer((int)get_tv_number(&argvars[0]));
+	if (timer != NULL)
+	    timer->tr_paused = paused;
+    }
+}
+
+/*
  * "timer_start(time, callback [, options])" function
  */
     static void
@@ -12048,6 +12071,15 @@ f_timer_stop(typval_T *argvars, typval_T
     if (timer != NULL)
 	stop_timer(timer);
 }
+
+/*
+ * "timer_stopall()" function
+ */
+    static void
+f_timer_stopall(typval_T *argvars UNUSED, typval_T *rettv UNUSED)
+{
+    stop_all_timers();
+}
 #endif
 
 /*