vim-patch:7.4.2170

Problem:    Cannot get information about timers.
Solution:   Add timer_info().

8e97bd74b5
This commit is contained in:
Jurica Bradaric 2017-03-02 23:04:57 +01:00 committed by Jurica Bradaric
parent df1e7b7eda
commit 8924e75f34
4 changed files with 83 additions and 6 deletions

View File

@ -2297,6 +2297,7 @@ tan({expr}) Float tangent of {expr}
tanh({expr}) Float hyperbolic tangent of {expr} tanh({expr}) Float hyperbolic tangent of {expr}
tempname() String name for a temporary file tempname() String name for a temporary file
test_garbagecollect_now() none free memory right now for testing test_garbagecollect_now() none free memory right now for testing
timer_info([{id}]) List information about timers
timer_start({time}, {callback} [, {options}]) timer_start({time}, {callback} [, {options}])
Number create a timer Number create a timer
timer_stop({timer}) none stop a timer timer_stop({timer}) none stop a timer
@ -3198,8 +3199,12 @@ exepath({expr}) *exepath()*
*exists()* *exists()*
exists({expr}) The result is a Number, which is |TRUE| if {expr} is exists({expr}) The result is a Number, which is |TRUE| if {expr} is
defined, zero otherwise. The {expr} argument is a string, defined, zero otherwise.
which contains one of these:
For checking for a supported feature use |has()|.
For checking if a file exists use |filereadable()|.
The {expr} argument is a string, which contains one of these:
&option-name Vim option (only checks if it exists, &option-name Vim option (only checks if it exists,
not if it really works) not if it really works)
+option-name Vim option that works. +option-name Vim option that works.
@ -3247,7 +3252,6 @@ exists({expr}) The result is a Number, which is |TRUE| if {expr} is
event and pattern. event and pattern.
##event autocommand for this event is ##event autocommand for this event is
supported. supported.
For checking for a supported feature use |has()|.
Examples: > Examples: >
exists("&mouse") exists("&mouse")
@ -5329,7 +5333,8 @@ matchadd({group}, {pattern}[, {priority}[, {id} [, {dict}]]])
available from |getmatches()|. All matches can be deleted in available from |getmatches()|. All matches can be deleted in
one operation by |clearmatches()|. one operation by |clearmatches()|.
matchaddpos({group}, {pos}[, {priority}[, {id}[, {dict}]]]) *matchaddpos()* *matchaddpos()*
matchaddpos({group}, {pos}[, {priority}[, {id}[, {dict}]]])
Same as |matchadd()|, but requires a list of positions {pos} Same as |matchadd()|, but requires a list of positions {pos}
instead of a pattern. This command is faster than |matchadd()| instead of a pattern. This command is faster than |matchadd()|
because it does not require to handle regular expressions and because it does not require to handle regular expressions and
@ -7513,6 +7518,22 @@ tanh({expr}) *tanh()*
< -0.761594 < -0.761594
*timer_info()*
timer_info([{id}])
Return a list with information about timers.
When {id} is given only information about this timer is
returned. When timer {id} does not exist an empty list is
returned.
When {id} is omitted information about all timers is returned.
For each timer the information is stored in a Dictionary with
these items:
"id" the timer ID
"time" time the timer was started with
"repeat" number of times the timer will still fire;
-1 means forever
"callback" the callback
*timer_start()* *timer_start()*
timer_start({time}, {callback} [, {options}]) timer_start({time}, {callback} [, {options}])
Create a timer and return the timer ID. Create a timer and return the timer ID.
@ -7542,7 +7563,7 @@ timer_start({time}, {callback} [, {options}])
timer_stop({timer}) *timer_stop()* timer_stop({timer}) *timer_stop()*
Stop a timer. The timer callback will no longer be invoked. Stop a timer. The timer callback will no longer be invoked.
{timer} is an ID returned by timer_start(), thus it must be a {timer} is an ID returned by timer_start(), thus it must be a
Number. Number. If {timer} does not exist there is no error.
tolower({expr}) *tolower()* tolower({expr}) *tolower()*
The result is a copy of the String given, with all uppercase The result is a copy of the String given, with all uppercase

View File

@ -17931,6 +17931,61 @@ static bool set_ref_in_callback(Callback *callback, int copyID,
return false; return false;
} }
static void add_timer_info(typval_T *rettv, timer_T *timer)
{
list_T *list = rettv->vval.v_list;
dict_T *dict = dict_alloc();
list_append_dict(list, dict);
dict_add_nr_str(dict, "id", (long)timer->timer_id, NULL);
dict_add_nr_str(dict, "time", timer->timeout, NULL);
dict_add_nr_str(dict, "repeat",
(long)(timer->repeat_count < 0 ? -1 : timer->repeat_count),
NULL);
dictitem_T *di = dictitem_alloc((char_u *)"callback");
if (dict_add(dict, di) == FAIL) {
xfree(di);
return;
}
if (timer->callback.type == kCallbackPartial) {
di->di_tv.v_type = VAR_PARTIAL;
di->di_tv.vval.v_partial = timer->callback.data.partial;
timer->callback.data.partial->pt_refcount++;
} else if (timer->callback.type == kCallbackFuncref) {
di->di_tv.v_type = VAR_FUNC;
di->di_tv.vval.v_string = vim_strsave(timer->callback.data.funcref);
}
di->di_tv.v_lock = 0;
}
static void add_timer_info_all(typval_T *rettv)
{
timer_T *timer;
map_foreach_value(timers, timer, {
add_timer_info(rettv, timer);
})
}
/// "timer_info([timer])" function
static void f_timer_info(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
rettv_list_alloc(rettv);
if (argvars[0].v_type != VAR_UNKNOWN) {
if (argvars[0].v_type != VAR_NUMBER) {
EMSG(_(e_number_exp));
} else {
timer_T *timer = pmap_get(uint64_t)(timers, get_tv_number(&argvars[0]));
if (timer != NULL) {
add_timer_info(rettv, timer);
}
}
} else {
add_timer_info_all(rettv);
}
}
/// "timer_start(timeout, callback, opts)" function /// "timer_start(timeout, callback, opts)" function
static void f_timer_start(typval_T *argvars, typval_T *rettv, FunPtr fptr) static void f_timer_start(typval_T *argvars, typval_T *rettv, FunPtr fptr)

View File

@ -306,6 +306,7 @@ return {
tempname={}, tempname={},
termopen={args={1, 2}}, termopen={args={1, 2}},
test_garbagecollect_now={}, test_garbagecollect_now={},
timer_info={args={0,1}},
timer_start={args={2,3}}, timer_start={args={2,3}},
timer_stop={args=1}, timer_stop={args=1},
tolower={args=1}, tolower={args=1},

View File

@ -271,7 +271,7 @@ static int included_patches[] = {
// 2173, // 2173,
// 2172, // 2172,
// 2171, // 2171,
// 2170, 2170,
// 2169, // 2169,
// 2168 NA // 2168 NA
// 2167 NA // 2167 NA