mirror of
https://github.com/neovim/neovim.git
synced 2025-09-13 23:08:16 +00:00
Merge #6219 from jbradaric/vim-7.4.2170
vim-patch:7.4.{2170,2180,2240,2241,2242}
This commit is contained in:
@@ -2302,9 +2302,12 @@ tan({expr}) Float tangent of {expr}
|
||||
tanh({expr}) Float hyperbolic tangent of {expr}
|
||||
tempname() String name for a temporary file
|
||||
test_garbagecollect_now() none free memory right now for testing
|
||||
timer_info([{id}]) List information about timers
|
||||
timer_pause({id}, {pause}) none pause or unpause a timer
|
||||
timer_start({time}, {callback} [, {options}])
|
||||
Number create a timer
|
||||
timer_stop({timer}) none stop a timer
|
||||
timer_stopall() none stop all timers
|
||||
tolower({expr}) String the String {expr} switched to lowercase
|
||||
toupper({expr}) String the String {expr} switched to uppercase
|
||||
tr({src}, {fromstr}, {tostr}) String translate chars of {src} in {fromstr}
|
||||
@@ -3203,8 +3206,12 @@ exepath({expr}) *exepath()*
|
||||
|
||||
*exists()*
|
||||
exists({expr}) The result is a Number, which is |TRUE| if {expr} is
|
||||
defined, zero otherwise. The {expr} argument is a string,
|
||||
which contains one of these:
|
||||
defined, zero otherwise.
|
||||
|
||||
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,
|
||||
not if it really works)
|
||||
+option-name Vim option that works.
|
||||
@@ -3252,7 +3259,6 @@ exists({expr}) The result is a Number, which is |TRUE| if {expr} is
|
||||
event and pattern.
|
||||
##event autocommand for this event is
|
||||
supported.
|
||||
For checking for a supported feature use |has()|.
|
||||
|
||||
Examples: >
|
||||
exists("&mouse")
|
||||
@@ -5337,7 +5343,8 @@ matchadd({group}, {pattern}[, {priority}[, {id} [, {dict}]]])
|
||||
available from |getmatches()|. All matches can be deleted in
|
||||
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}
|
||||
instead of a pattern. This command is faster than |matchadd()|
|
||||
because it does not require to handle regular expressions and
|
||||
@@ -7528,6 +7535,35 @@ tanh({expr}) *tanh()*
|
||||
< -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_pause({timer}, {paused}) *timer_pause()*
|
||||
Pause or unpause a timer. A paused timer does not invoke its
|
||||
callback, while the time it would is not changed. Unpausing a
|
||||
timer may cause the callback to be invoked almost immediately
|
||||
if enough time has passed.
|
||||
|
||||
Pausing a timer is useful to avoid the callback to be called
|
||||
for a short time.
|
||||
|
||||
If {paused} evaluates to a non-zero Number or a non-empty
|
||||
String, then the timer is paused, otherwise it is unpaused.
|
||||
See |non-zero-arg|.
|
||||
|
||||
*timer_start()*
|
||||
timer_start({time}, {callback} [, {options}])
|
||||
Create a timer and return the timer ID.
|
||||
@@ -7557,7 +7593,12 @@ timer_start({time}, {callback} [, {options}])
|
||||
timer_stop({timer}) *timer_stop()*
|
||||
Stop a timer. The timer callback will no longer be invoked.
|
||||
{timer} is an ID returned by timer_start(), thus it must be a
|
||||
Number.
|
||||
Number. If {timer} does not exist there is no error.
|
||||
|
||||
timer_stopall() *timer_stopall()*
|
||||
Stop all timers. The timer callbacks will no longer be
|
||||
invoked. Useful if some timers is misbehaving. If there are
|
||||
no timers there is no error.
|
||||
|
||||
tolower({expr}) *tolower()*
|
||||
The result is a copy of the String given, with all uppercase
|
||||
|
@@ -462,6 +462,7 @@ typedef struct {
|
||||
int refcount;
|
||||
long timeout;
|
||||
bool stopped;
|
||||
bool paused;
|
||||
Callback callback;
|
||||
} timer_T;
|
||||
|
||||
@@ -16651,6 +16652,77 @@ static bool set_ref_in_callback(Callback *callback, int copyID,
|
||||
return false;
|
||||
}
|
||||
|
||||
static void add_timer_info(typval_T *rettv, timer_T *timer)
|
||||
{
|
||||
list_T *list = rettv->vval.v_list;
|
||||
dict_T *dict = tv_dict_alloc();
|
||||
|
||||
tv_list_append_dict(list, dict);
|
||||
tv_dict_add_nr(dict, S_LEN("id"), timer->timer_id);
|
||||
tv_dict_add_nr(dict, S_LEN("time"), timer->timeout);
|
||||
tv_dict_add_nr(dict, S_LEN("paused"), timer->paused);
|
||||
|
||||
tv_dict_add_nr(dict, S_LEN("repeat"),
|
||||
(timer->repeat_count < 0 ? -1 : timer->repeat_count));
|
||||
|
||||
dictitem_T *di = tv_dict_item_alloc("callback");
|
||||
if (tv_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, {
|
||||
if (!timer->stopped) {
|
||||
add_timer_info(rettv, timer);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/// "timer_info([timer])" function
|
||||
static void f_timer_info(typval_T *argvars, typval_T *rettv, FunPtr fptr)
|
||||
{
|
||||
tv_list_alloc_ret(rettv);
|
||||
if (argvars[0].v_type != VAR_UNKNOWN) {
|
||||
if (argvars[0].v_type != VAR_NUMBER) {
|
||||
EMSG(_(e_number_exp));
|
||||
return;
|
||||
}
|
||||
timer_T *timer = pmap_get(uint64_t)(timers, tv_get_number(&argvars[0]));
|
||||
if (timer != NULL && !timer->stopped) {
|
||||
add_timer_info(rettv, timer);
|
||||
}
|
||||
} else {
|
||||
add_timer_info_all(rettv);
|
||||
}
|
||||
}
|
||||
|
||||
/// "timer_pause(timer, paused)" function
|
||||
static void f_timer_pause(typval_T *argvars, typval_T *unused, FunPtr fptr)
|
||||
{
|
||||
if (argvars[0].v_type != VAR_NUMBER) {
|
||||
EMSG(_(e_number_exp));
|
||||
return;
|
||||
}
|
||||
int paused = (bool)tv_get_number(&argvars[1]);
|
||||
timer_T *timer = pmap_get(uint64_t)(timers, tv_get_number(&argvars[0]));
|
||||
if (timer != NULL) {
|
||||
timer->paused = paused;
|
||||
}
|
||||
}
|
||||
|
||||
/// "timer_start(timeout, callback, opts)" function
|
||||
static void f_timer_start(typval_T *argvars, typval_T *rettv, FunPtr fptr)
|
||||
@@ -16685,6 +16757,7 @@ static void f_timer_start(typval_T *argvars, typval_T *rettv, FunPtr fptr)
|
||||
timer = xmalloc(sizeof *timer);
|
||||
timer->refcount = 1;
|
||||
timer->stopped = false;
|
||||
timer->paused = false;
|
||||
timer->repeat_count = repeat;
|
||||
timer->timeout = timeout;
|
||||
timer->timer_id = last_timer_id++;
|
||||
@@ -16694,8 +16767,7 @@ static void f_timer_start(typval_T *argvars, typval_T *rettv, FunPtr fptr)
|
||||
timer->tw.events = multiqueue_new_child(main_loop.events);
|
||||
// if main loop is blocked, don't queue up multiple events
|
||||
timer->tw.blockable = true;
|
||||
time_watcher_start(&timer->tw, timer_due_cb, timeout,
|
||||
timeout * (repeat != 1));
|
||||
time_watcher_start(&timer->tw, timer_due_cb, timeout, timeout);
|
||||
|
||||
pmap_put(uint64_t)(timers, timer->timer_id, timer);
|
||||
rettv->vval.v_number = timer->timer_id;
|
||||
@@ -16719,13 +16791,19 @@ static void f_timer_stop(typval_T *argvars, typval_T *rettv, FunPtr fptr)
|
||||
timer_stop(timer);
|
||||
}
|
||||
|
||||
static void f_timer_stopall(typval_T *argvars, typval_T *unused, FunPtr fptr)
|
||||
{
|
||||
timer_stop_all();
|
||||
}
|
||||
|
||||
// invoked on the main loop
|
||||
static void timer_due_cb(TimeWatcher *tw, void *data)
|
||||
{
|
||||
timer_T *timer = (timer_T *)data;
|
||||
if (timer->stopped) {
|
||||
if (timer->stopped || timer->paused) {
|
||||
return;
|
||||
}
|
||||
|
||||
timer->refcount++;
|
||||
// if repeat was negative repeat forever
|
||||
if (timer->repeat_count >= 0 && --timer->repeat_count == 0) {
|
||||
@@ -16778,7 +16856,7 @@ static void timer_decref(timer_T *timer)
|
||||
}
|
||||
}
|
||||
|
||||
void timer_teardown(void)
|
||||
static void timer_stop_all(void)
|
||||
{
|
||||
timer_T *timer;
|
||||
map_foreach_value(timers, timer, {
|
||||
@@ -16786,6 +16864,11 @@ void timer_teardown(void)
|
||||
})
|
||||
}
|
||||
|
||||
void timer_teardown(void)
|
||||
{
|
||||
timer_stop_all();
|
||||
}
|
||||
|
||||
/*
|
||||
* "tolower(string)" function
|
||||
*/
|
||||
|
@@ -306,8 +306,11 @@ return {
|
||||
tempname={},
|
||||
termopen={args={1, 2}},
|
||||
test_garbagecollect_now={},
|
||||
timer_info={args={0,1}},
|
||||
timer_pause={args=2},
|
||||
timer_start={args={2,3}},
|
||||
timer_stop={args=1},
|
||||
timer_stopall={args=0},
|
||||
tolower={args=1},
|
||||
toupper={args=1},
|
||||
tr={args=3},
|
||||
|
@@ -4,8 +4,10 @@ if !has('timers')
|
||||
finish
|
||||
endif
|
||||
|
||||
source shared.vim
|
||||
|
||||
func MyHandler(timer)
|
||||
let s:val += 1
|
||||
let g:val += 1
|
||||
endfunc
|
||||
|
||||
func MyHandlerWithLists(lists, timer)
|
||||
@@ -13,44 +15,159 @@ func MyHandlerWithLists(lists, timer)
|
||||
endfunc
|
||||
|
||||
func Test_oneshot()
|
||||
let s:val = 0
|
||||
let g:val = 0
|
||||
let timer = timer_start(50, 'MyHandler')
|
||||
sleep 200m
|
||||
call assert_equal(1, s:val)
|
||||
let slept = WaitFor('g:val == 1')
|
||||
call assert_equal(1, g:val)
|
||||
if has('reltime')
|
||||
call assert_inrange(40, 100, slept)
|
||||
else
|
||||
call assert_inrange(20, 100, slept)
|
||||
endif
|
||||
endfunc
|
||||
|
||||
func Test_repeat_three()
|
||||
let s:val = 0
|
||||
let g:val = 0
|
||||
let timer = timer_start(50, 'MyHandler', {'repeat': 3})
|
||||
sleep 500m
|
||||
call assert_equal(3, s:val)
|
||||
let slept = WaitFor('g:val == 3')
|
||||
call assert_equal(3, g:val)
|
||||
if has('reltime')
|
||||
call assert_inrange(120, 250, slept)
|
||||
else
|
||||
call assert_inrange(80, 200, slept)
|
||||
endif
|
||||
endfunc
|
||||
|
||||
func Test_repeat_many()
|
||||
let s:val = 0
|
||||
let g:val = 0
|
||||
let timer = timer_start(50, 'MyHandler', {'repeat': -1})
|
||||
sleep 200m
|
||||
call timer_stop(timer)
|
||||
call assert_true(s:val > 1)
|
||||
call assert_true(s:val < 5)
|
||||
call assert_inrange(2, 4, g:val)
|
||||
endfunc
|
||||
|
||||
func Test_with_partial_callback()
|
||||
let s:val = 0
|
||||
let s:meow = {}
|
||||
function s:meow.bite(...)
|
||||
let s:val += 1
|
||||
let g:val = 0
|
||||
let meow = {'one': 1}
|
||||
function meow.bite(...)
|
||||
let g:val += self.one
|
||||
endfunction
|
||||
|
||||
call timer_start(50, s:meow.bite)
|
||||
sleep 200m
|
||||
call assert_equal(1, s:val)
|
||||
call timer_start(50, meow.bite)
|
||||
let slept = WaitFor('g:val == 1')
|
||||
call assert_equal(1, g:val)
|
||||
if has('reltime')
|
||||
call assert_inrange(40, 130, slept)
|
||||
else
|
||||
call assert_inrange(20, 100, slept)
|
||||
endif
|
||||
endfunc
|
||||
|
||||
func Test_retain_partial()
|
||||
call timer_start(100, function('MyHandlerWithLists', [['a']]))
|
||||
call timer_start(50, function('MyHandlerWithLists', [['a']]))
|
||||
call garbagecollect()
|
||||
sleep 200m
|
||||
sleep 100m
|
||||
endfunc
|
||||
|
||||
func Test_info()
|
||||
let id = timer_start(1000, 'MyHandler')
|
||||
let info = timer_info(id)
|
||||
call assert_equal(id, info[0]['id'])
|
||||
call assert_equal(1000, info[0]['time'])
|
||||
call assert_equal("function('MyHandler')", string(info[0]['callback']))
|
||||
|
||||
let found = 0
|
||||
for info in timer_info()
|
||||
if info['id'] == id
|
||||
let found += 1
|
||||
endif
|
||||
endfor
|
||||
call assert_equal(1, found)
|
||||
|
||||
call timer_stop(id)
|
||||
call assert_equal([], timer_info(id))
|
||||
endfunc
|
||||
|
||||
func Test_stopall()
|
||||
let id1 = timer_start(1000, 'MyHandler')
|
||||
let id2 = timer_start(2000, 'MyHandler')
|
||||
let info = timer_info()
|
||||
call assert_equal(2, len(info))
|
||||
|
||||
call timer_stopall()
|
||||
let info = timer_info()
|
||||
call assert_equal(0, len(info))
|
||||
endfunc
|
||||
|
||||
func Test_paused()
|
||||
let g:val = 0
|
||||
|
||||
let id = timer_start(50, 'MyHandler')
|
||||
let info = timer_info(id)
|
||||
call assert_equal(0, info[0]['paused'])
|
||||
|
||||
call timer_pause(id, 1)
|
||||
let info = timer_info(id)
|
||||
call assert_equal(1, info[0]['paused'])
|
||||
sleep 200m
|
||||
call assert_equal(0, g:val)
|
||||
|
||||
call timer_pause(id, 0)
|
||||
let info = timer_info(id)
|
||||
call assert_equal(0, info[0]['paused'])
|
||||
|
||||
let slept = WaitFor('g:val == 1')
|
||||
call assert_equal(1, g:val)
|
||||
if has('reltime')
|
||||
call assert_inrange(0, 60, slept)
|
||||
else
|
||||
call assert_inrange(0, 10, slept)
|
||||
endif
|
||||
endfunc
|
||||
|
||||
func StopMyself(timer)
|
||||
let g:called += 1
|
||||
if g:called == 2
|
||||
call timer_stop(a:timer)
|
||||
endif
|
||||
endfunc
|
||||
|
||||
func Test_delete_myself()
|
||||
let g:called = 0
|
||||
let t = timer_start(10, 'StopMyself', {'repeat': -1})
|
||||
call WaitFor('g:called == 2')
|
||||
call assert_equal(2, g:called)
|
||||
call assert_equal([], timer_info(t))
|
||||
endfunc
|
||||
|
||||
func StopTimer1(timer)
|
||||
let g:timer2 = timer_start(10, 'StopTimer2')
|
||||
" avoid maxfuncdepth error
|
||||
call timer_pause(g:timer1, 1)
|
||||
sleep 40m
|
||||
endfunc
|
||||
|
||||
func StopTimer2(timer)
|
||||
call timer_stop(g:timer1)
|
||||
endfunc
|
||||
|
||||
func Test_stop_in_callback()
|
||||
let g:timer1 = timer_start(10, 'StopTimer1')
|
||||
sleep 40m
|
||||
endfunc
|
||||
|
||||
func StopTimerAll(timer)
|
||||
call timer_stopall()
|
||||
endfunc
|
||||
|
||||
func Test_stop_all_in_callback()
|
||||
let g:timer1 = timer_start(10, 'StopTimerAll')
|
||||
let info = timer_info()
|
||||
call assert_equal(1, len(info))
|
||||
sleep 40m
|
||||
let info = timer_info()
|
||||
call assert_equal(0, len(info))
|
||||
endfunc
|
||||
|
||||
|
||||
" vim: shiftwidth=2 sts=2 expandtab
|
||||
|
@@ -82,7 +82,7 @@ static const int included_patches[] = {
|
||||
2362,
|
||||
// 2361 NA
|
||||
// 2360,
|
||||
// 2359 NA
|
||||
2359,
|
||||
// 2358 NA
|
||||
2357,
|
||||
// 2356,
|
||||
@@ -109,7 +109,7 @@ static const int included_patches[] = {
|
||||
2335,
|
||||
2334,
|
||||
2333,
|
||||
// 2332 NA
|
||||
2332,
|
||||
2331,
|
||||
2330,
|
||||
2329,
|
||||
@@ -137,7 +137,7 @@ static const int included_patches[] = {
|
||||
2307,
|
||||
2306,
|
||||
2305,
|
||||
// 2304 NA
|
||||
2304,
|
||||
2303,
|
||||
// 2302 NA
|
||||
// 2301 NA
|
||||
@@ -160,7 +160,7 @@ static const int included_patches[] = {
|
||||
2284,
|
||||
2283,
|
||||
// 2282 NA
|
||||
// 2281 NA
|
||||
2281,
|
||||
2280,
|
||||
2279,
|
||||
// 2278 NA
|
||||
@@ -199,9 +199,9 @@ static const int included_patches[] = {
|
||||
// 2245,
|
||||
// 2244,
|
||||
// 2243 NA
|
||||
// 2242,
|
||||
// 2241,
|
||||
// 2240,
|
||||
2242,
|
||||
2241,
|
||||
2240,
|
||||
// 2239,
|
||||
// 2238 NA
|
||||
2237,
|
||||
@@ -260,8 +260,8 @@ static const int included_patches[] = {
|
||||
2184,
|
||||
2183,
|
||||
// 2182 NA
|
||||
// 2181,
|
||||
// 2180,
|
||||
// 2181 NA
|
||||
2180,
|
||||
// 2179,
|
||||
2178,
|
||||
2177,
|
||||
@@ -270,8 +270,8 @@ static const int included_patches[] = {
|
||||
2174,
|
||||
// 2173,
|
||||
2172,
|
||||
// 2171,
|
||||
// 2170,
|
||||
// 2171 NA
|
||||
2170,
|
||||
2169,
|
||||
// 2168 NA
|
||||
// 2167 NA
|
||||
|
Reference in New Issue
Block a user