From 790500a8e65bee295ef51a59dfa67ecbaab8ea17 Mon Sep 17 00:00:00 2001 From: Bram Moolenaar Date: Tue, 15 Mar 2016 11:05:45 +0100 Subject: [PATCH 01/18] patch 7.4.1563 Problem: Partial test fails on windows. Solution: Return 1 or -1 from compare function. --- src/testdir/test_partial.vim | 4 ++-- src/version.c | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/testdir/test_partial.vim b/src/testdir/test_partial.vim index 061f839668..998b232206 100644 --- a/src/testdir/test_partial.vim +++ b/src/testdir/test_partial.vim @@ -9,9 +9,9 @@ func MySort(up, one, two) return 0 endif if a:up - return a:one > a:two + return a:one > a:two ? 1 : -1 endif - return a:one < a:two + return a:one < a:two ? 1 : -1 endfunc func Test_partial_args() diff --git a/src/version.c b/src/version.c index a323d2c0f8..50d20f1003 100644 --- a/src/version.c +++ b/src/version.c @@ -743,6 +743,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 1563, /**/ 1562, /**/ From 346418c624f1bc7c04c98907134a2b284e6452dd Mon Sep 17 00:00:00 2001 From: Bram Moolenaar Date: Tue, 15 Mar 2016 12:36:08 +0100 Subject: [PATCH 02/18] patch 7.4.1564 Problem: An empty list in function() causes an error. Solution: Handle an empty list like there is no list of arguments. --- src/eval.c | 43 ++++++++++++++++++++++-------------- src/testdir/test_partial.vim | 11 ++++++++- src/version.c | 2 ++ 3 files changed, 39 insertions(+), 17 deletions(-) diff --git a/src/eval.c b/src/eval.c index 3040e93d01..eadb802b30 100644 --- a/src/eval.c +++ b/src/eval.c @@ -11786,6 +11786,10 @@ f_function(typval_T *argvars, typval_T *rettv) EMSG2(_("E700: Unknown function: %s"), s); else { + int dict_idx = 0; + int arg_idx = 0; + list_T *list = NULL; + if (STRNCMP(s, "s:", 2) == 0 || STRNCMP(s, "", 5) == 0) { char sid_buf[25]; @@ -11808,10 +11812,6 @@ f_function(typval_T *argvars, typval_T *rettv) if (argvars[1].v_type != VAR_UNKNOWN) { - partial_T *pt; - int dict_idx = 0; - int arg_idx = 0; - if (argvars[2].v_type != VAR_UNKNOWN) { /* function(name, [args], dict) */ @@ -11824,27 +11824,38 @@ f_function(typval_T *argvars, typval_T *rettv) else /* function(name, [args]) */ arg_idx = 1; - if (dict_idx > 0 && (argvars[dict_idx].v_type != VAR_DICT - || argvars[dict_idx].vval.v_dict == NULL)) + if (dict_idx > 0) { - EMSG(_("E922: expected a dict")); - vim_free(name); - return; + if (argvars[dict_idx].v_type != VAR_DICT) + { + EMSG(_("E922: expected a dict")); + vim_free(name); + return; + } + if (argvars[dict_idx].vval.v_dict == NULL) + dict_idx = 0; } - if (arg_idx > 0 && (argvars[arg_idx].v_type != VAR_LIST - || argvars[arg_idx].vval.v_list == NULL)) + if (arg_idx > 0) { - EMSG(_("E923: Second argument of function() must be a list or a dict")); - vim_free(name); - return; + if (argvars[arg_idx].v_type != VAR_LIST) + { + EMSG(_("E923: Second argument of function() must be a list or a dict")); + vim_free(name); + return; + } + list = argvars[arg_idx].vval.v_list; + if (list == NULL || list->lv_len == 0) + arg_idx = 0; } + } + if (dict_idx > 0 || arg_idx > 0) + { + partial_T *pt = (partial_T *)alloc_clear(sizeof(partial_T)); - pt = (partial_T *)alloc_clear(sizeof(partial_T)); if (pt != NULL) { if (arg_idx > 0) { - list_T *list = argvars[arg_idx].vval.v_list; listitem_T *li; int i = 0; diff --git a/src/testdir/test_partial.vim b/src/testdir/test_partial.vim index 998b232206..b1a52db03b 100644 --- a/src/testdir/test_partial.vim +++ b/src/testdir/test_partial.vim @@ -19,6 +19,9 @@ func Test_partial_args() call assert_equal("foo/bar/xxx", Cb("xxx")) call assert_equal("foo/bar/yyy", call(Cb, ["yyy"])) + let Cb = function('MyFunc', []) + call assert_equal("a/b/c", Cb("a", "b", "c")) + let Sort = function('MySort', [1]) call assert_equal([1, 2, 3], sort([3, 1, 2], Sort)) let Sort = function('MySort', [0]) @@ -34,10 +37,16 @@ func Test_partial_dict() let Cb = function('MyDictFunc', ["foo", "bar"], dict) call assert_equal("hello/foo/bar", Cb()) call assert_fails('Cb("xxx")', 'E492:') + let Cb = function('MyDictFunc', ["foo"], dict) call assert_equal("hello/foo/xxx", Cb("xxx")) call assert_fails('Cb()', 'E492:') + + let Cb = function('MyDictFunc', [], dict) + call assert_equal("hello/ttt/xxx", Cb("ttt", "xxx")) + call assert_fails('Cb("yyy")', 'E492:') + let Cb = function('MyDictFunc', dict) call assert_equal("hello/xxx/yyy", Cb("xxx", "yyy")) - call assert_fails('Cb()', 'E492:') + call assert_fails('Cb("fff")', 'E492:') endfunc diff --git a/src/version.c b/src/version.c index 50d20f1003..3cab689794 100644 --- a/src/version.c +++ b/src/version.c @@ -743,6 +743,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 1564, /**/ 1563, /**/ From f1551964448607f8222de2d8f0992ea43eb2fe67 Mon Sep 17 00:00:00 2001 From: Bram Moolenaar Date: Tue, 15 Mar 2016 12:55:58 +0100 Subject: [PATCH 03/18] patch 7.4.1565 Problem: Crash when assert_equal() runs into a NULL string. Solution: Check for NULL. (Dominique) Add a test. --- src/eval.c | 6 ++++++ src/testdir/test_assert.vim | 15 +++++++++++++++ src/version.c | 2 ++ 3 files changed, 23 insertions(+) diff --git a/src/eval.c b/src/eval.c index eadb802b30..425ab688f9 100644 --- a/src/eval.c +++ b/src/eval.c @@ -9240,6 +9240,12 @@ ga_concat_esc(garray_T *gap, char_u *str) char_u *p; char_u buf[NUMBUFLEN]; + if (str == NULL) + { + ga_concat(gap, (char_u *)"NULL"); + return; + } + for (p = str; *p != NUL; ++p) switch (*p) { diff --git a/src/testdir/test_assert.vim b/src/testdir/test_assert.vim index 6d2f80094a..df2636d7bc 100644 --- a/src/testdir/test_assert.vim +++ b/src/testdir/test_assert.vim @@ -48,6 +48,21 @@ func Test_wrong_error_type() call assert_equal(type([]), type(verrors)) endfunc +func Test_compare_fail() + let s:v = {} + let s:x = {"a": s:v} + let s:v["b"] = s:x + let s:w = {"c": s:x, "d": ''} + try + call assert_equal(s:w, '') + catch + call assert_exception('E724:') + call assert_true(v:errors[0] =~ "Expected NULL but got ''") + call remove(v:errors, 0) + endtry +endfunc + + func Test_user_is_happy() smile sleep 300m diff --git a/src/version.c b/src/version.c index 3cab689794..59c7714c88 100644 --- a/src/version.c +++ b/src/version.c @@ -743,6 +743,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 1565, /**/ 1564, /**/ From 4f118be2bb987cdf313da879d2a93ae125e99202 Mon Sep 17 00:00:00 2001 From: Bram Moolenaar Date: Tue, 15 Mar 2016 13:09:53 +0100 Subject: [PATCH 04/18] patch 7.4.1566 Problem: Compiler warning for shadowed variable. (Kazunobu Kuriyama) Solution: Remove the inner one. --- src/eval.c | 2 -- src/version.c | 2 ++ 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/eval.c b/src/eval.c index 425ab688f9..fd028ccce6 100644 --- a/src/eval.c +++ b/src/eval.c @@ -8759,8 +8759,6 @@ call_func( } if (error == ERROR_NONE && partial->pt_argc > 0) { - int i; - for (argv_clear = 0; argv_clear < partial->pt_argc; ++argv_clear) copy_tv(&partial->pt_argv[argv_clear], &argv[argv_clear]); for (i = 0; i < argcount_in; ++i) diff --git a/src/version.c b/src/version.c index 59c7714c88..e4004f81c3 100644 --- a/src/version.c +++ b/src/version.c @@ -743,6 +743,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 1566, /**/ 1565, /**/ From 1abb502635c7f317e05a0cf3ea067101f9d684f5 Mon Sep 17 00:00:00 2001 From: Bram Moolenaar Date: Tue, 15 Mar 2016 13:33:55 +0100 Subject: [PATCH 05/18] patch 7.4.1567 Problem: Crash in assert_fails(). Solution: Check for NULL. (Dominique Pelle) Add a test. --- src/eval.c | 3 ++- src/testdir/test_assert.vim | 6 ++++++ src/version.c | 2 ++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/eval.c b/src/eval.c index fd028ccce6..7776cc6c33 100644 --- a/src/eval.c +++ b/src/eval.c @@ -9386,7 +9386,8 @@ f_assert_fails(typval_T *argvars, typval_T *rettv UNUSED) char_u buf[NUMBUFLEN]; char *error = (char *)get_tv_string_buf_chk(&argvars[1], buf); - if (strstr((char *)vimvars[VV_ERRMSG].vv_str, error) == NULL) + if (error == NULL + || strstr((char *)vimvars[VV_ERRMSG].vv_str, error) == NULL) { prepare_assert_error(&ga); fill_assert_error(&ga, &argvars[2], NULL, &argvars[1], diff --git a/src/testdir/test_assert.vim b/src/testdir/test_assert.vim index df2636d7bc..2ac828b282 100644 --- a/src/testdir/test_assert.vim +++ b/src/testdir/test_assert.vim @@ -62,6 +62,12 @@ func Test_compare_fail() endtry endfunc +func Test_assert_fail_fails() + call assert_fails('xxx', {}) + call assert_true(v:errors[0] =~ "Expected {} but got 'E731:") + call remove(v:errors, 0) +endfunc + func Test_user_is_happy() smile diff --git a/src/version.c b/src/version.c index e4004f81c3..eecbfe1ed2 100644 --- a/src/version.c +++ b/src/version.c @@ -743,6 +743,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 1567, /**/ 1566, /**/ From 00f9e0dbbd3472db217d56639fad9346b9eb3b82 Mon Sep 17 00:00:00 2001 From: Bram Moolenaar Date: Tue, 15 Mar 2016 13:44:12 +0100 Subject: [PATCH 06/18] patch 7.4.1568 Problem: Using CTRL-] in help on option in parentheses doesn't work. Solution: Skip the "(" in "('". (Hirohito Higashi) --- src/ex_cmds.c | 5 +++++ src/version.c | 2 ++ 2 files changed, 7 insertions(+) diff --git a/src/ex_cmds.c b/src/ex_cmds.c index b7434774af..6461c3c08f 100644 --- a/src/ex_cmds.c +++ b/src/ex_cmds.c @@ -6114,6 +6114,11 @@ find_help_tags( || (arg[0] == '\\' && arg[1] == '{')) *d++ = '\\'; + /* + * If tag starts with "('", skip the "(". Fixes CTRL-] on ('option'. + */ + if (*arg == '(' && arg[1] == '\'') + arg++; for (s = arg; *s; ++s) { /* diff --git a/src/version.c b/src/version.c index eecbfe1ed2..bfb196870a 100644 --- a/src/version.c +++ b/src/version.c @@ -743,6 +743,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 1568, /**/ 1567, /**/ From e27dba499aaaf2ffe9f0da45f062450b434cddaa Mon Sep 17 00:00:00 2001 From: Bram Moolenaar Date: Tue, 15 Mar 2016 14:11:10 +0100 Subject: [PATCH 07/18] patch 7.4.1569 Problem: Using old style tests for quickfix. Solution: Change them to new style tests. (Yegappan Lakshmanan) --- src/testdir/Make_all.mak | 2 -- src/testdir/test106.in | 16 ----------- src/testdir/test106.ok | 4 --- src/testdir/test_qf_title.in | 18 ------------- src/testdir/test_qf_title.ok | 2 -- src/testdir/test_quickfix.vim | 50 +++++++++++++++++++++++++++++++++++ src/version.c | 2 ++ 7 files changed, 52 insertions(+), 42 deletions(-) delete mode 100644 src/testdir/test106.in delete mode 100644 src/testdir/test106.ok delete mode 100644 src/testdir/test_qf_title.in delete mode 100644 src/testdir/test_qf_title.ok diff --git a/src/testdir/Make_all.mak b/src/testdir/Make_all.mak index 233ca12dfd..1885bd7ed2 100644 --- a/src/testdir/Make_all.mak +++ b/src/testdir/Make_all.mak @@ -87,7 +87,6 @@ SCRIPTS_ALL = \ test103.out \ test104.out \ test105.out \ - test106.out \ test107.out \ test108.out \ test_autocmd_option.out \ @@ -110,7 +109,6 @@ SCRIPTS_ALL = \ test_match_conceal.out \ test_nested_function.out \ test_options.out \ - test_qf_title.out \ test_ruby.out \ test_search_mbyte.out \ test_signs.out \ diff --git a/src/testdir/test106.in b/src/testdir/test106.in deleted file mode 100644 index eb99e650ae..0000000000 --- a/src/testdir/test106.in +++ /dev/null @@ -1,16 +0,0 @@ -Tests for errorformat. vim: set ft=vim ts=8 : - -STARTTEST -:so small.vim -:if !has('quickfix') | e! test.ok | wq! test.out | endif -:set efm=%EEEE%m,%WWWW%m,%+CCCC%.%#,%-GGGG%.%# -:cgetexpr ['WWWW', 'EEEE', 'CCCC'] -:$put =strtrans(string(map(getqflist(), '[v:val.text, v:val.valid]'))) -:cgetexpr ['WWWW', 'GGGG', 'EEEE', 'CCCC'] -:$put =strtrans(string(map(getqflist(), '[v:val.text, v:val.valid]'))) -:cgetexpr ['WWWW', 'GGGG', 'ZZZZ', 'EEEE', 'CCCC', 'YYYY'] -:$put =strtrans(string(map(getqflist(), '[v:val.text, v:val.valid]'))) -:/^Results/,$wq! test.out -ENDTEST - -Results of test106: diff --git a/src/testdir/test106.ok b/src/testdir/test106.ok deleted file mode 100644 index 0a18cecf1c..0000000000 --- a/src/testdir/test106.ok +++ /dev/null @@ -1,4 +0,0 @@ -Results of test106: -[['W', 1], ['E^@CCCC', 1]] -[['W', 1], ['E^@CCCC', 1]] -[['W', 1], ['ZZZZ', 0], ['E^@CCCC', 1], ['YYYY', 0]] diff --git a/src/testdir/test_qf_title.in b/src/testdir/test_qf_title.in deleted file mode 100644 index fce0c260e3..0000000000 --- a/src/testdir/test_qf_title.in +++ /dev/null @@ -1,18 +0,0 @@ -Tests for quickfix window's title vim: set ft=vim : - -STARTTEST -:so small.vim -:if !has('quickfix') | e! test.ok | wq! test.out | endif -:set efm=%E%f:%l:%c:%m -:cgetexpr ['file:1:1:message'] -:let qflist=getqflist() -:call setqflist(qflist, 'r') -:copen -:let g:quickfix_title=w:quickfix_title -:wincmd p -:$put =g:quickfix_title -:/^Results/,$w test.out -:qa! -ENDTEST - -Results of test_qf_title: diff --git a/src/testdir/test_qf_title.ok b/src/testdir/test_qf_title.ok deleted file mode 100644 index 4ebdbeff3b..0000000000 --- a/src/testdir/test_qf_title.ok +++ /dev/null @@ -1,2 +0,0 @@ -Results of test_qf_title: -:setqflist() diff --git a/src/testdir/test_quickfix.vim b/src/testdir/test_quickfix.vim index 5e68450239..4be37d5860 100644 --- a/src/testdir/test_quickfix.vim +++ b/src/testdir/test_quickfix.vim @@ -316,3 +316,53 @@ func Test_errortitle() augroup END augroup! QfBufWinEnter endfunc + +function XqfTitleTests(cchar) + let Xgetexpr = a:cchar . 'getexpr' + if a:cchar == 'c' + let Xgetlist = 'getqflist()' + else + let Xgetlist = 'getloclist(0)' + endif + let Xopen = a:cchar . 'open' + let Xclose = a:cchar . 'close' + + exe Xgetexpr . " ['file:1:1:message']" + exe 'let l = ' . Xgetlist + if a:cchar == 'c' + call setqflist(l, 'r') + else + call setloclist(0, l, 'r') + endif + + exe Xopen + if a:cchar == 'c' + let title = ':setqflist()' + else + let title = ':setloclist()' + endif + call assert_equal(title, w:quickfix_title) + exe Xclose +endfunction + +" Tests for quickfix window's title +function Test_qf_title() + call XqfTitleTests('c') + call XqfTitleTests('l') +endfunction + +" Tests for 'errorformat' +function Test_efm() + let save_efm = &efm + set efm=%EEEE%m,%WWWW%m,%+CCCC%.%#,%-GGGG%.%# + cgetexpr ['WWWW', 'EEEE', 'CCCC'] + let l = strtrans(string(map(getqflist(), '[v:val.text, v:val.valid]'))) + call assert_equal("[['W', 1], ['E^@CCCC', 1]]", l) + cgetexpr ['WWWW', 'GGGG', 'EEEE', 'CCCC'] + let l = strtrans(string(map(getqflist(), '[v:val.text, v:val.valid]'))) + call assert_equal("[['W', 1], ['E^@CCCC', 1]]", l) + cgetexpr ['WWWW', 'GGGG', 'ZZZZ', 'EEEE', 'CCCC', 'YYYY'] + let l = strtrans(string(map(getqflist(), '[v:val.text, v:val.valid]'))) + call assert_equal("[['W', 1], ['ZZZZ', 0], ['E^@CCCC', 1], ['YYYY', 0]]", l) + let &efm = save_efm +endfunction diff --git a/src/version.c b/src/version.c index bfb196870a..5695515f55 100644 --- a/src/version.c +++ b/src/version.c @@ -743,6 +743,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 1569, /**/ 1568, /**/ From 426dd0219512af5f4abeb0901b533159253ffba3 Mon Sep 17 00:00:00 2001 From: Bram Moolenaar Date: Tue, 15 Mar 2016 15:09:29 +0100 Subject: [PATCH 08/18] patch 7.4.1570 Problem: There is no way to avoid the message when editing a file. Solution: Add the "F" flag to 'shortmess'. (Shougo, closes #686) --- runtime/doc/options.txt | 4 +++- src/buffer.c | 5 +++++ src/ex_cmds.c | 6 ++++-- src/option.h | 3 ++- src/version.c | 2 ++ 5 files changed, 16 insertions(+), 4 deletions(-) diff --git a/runtime/doc/options.txt b/runtime/doc/options.txt index 0396011e7b..024e621e5d 100644 --- a/runtime/doc/options.txt +++ b/runtime/doc/options.txt @@ -6533,7 +6533,9 @@ A jump table for the options with a short description can be found at |Q_op|. c don't give |ins-completion-menu| messages. For example, "-- XXX completion (YYY)", "match 1 of 2", "The only match", "Pattern not found", "Back at original", etc. - q use "recording" instead of "recording @a" + q use "recording" instead of "recording @a" + F don't give the file info when editing a file, like `:silent` + was used for the command This gives you the opportunity to avoid that a change between buffers requires you to hit , but still gives as useful a message as diff --git a/src/buffer.c b/src/buffer.c index 9ef8a50822..543b4a7078 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -139,14 +139,19 @@ open_buffer( #endif ) { + int old_msg_silent = msg_silent; + #ifdef FEAT_NETBEANS_INTG int oldFire = netbeansFireChanges; netbeansFireChanges = 0; #endif + if (shortmess(SHM_FILEINFO)) + msg_silent = 1; retval = readfile(curbuf->b_ffname, curbuf->b_fname, (linenr_T)0, (linenr_T)0, (linenr_T)MAXLNUM, eap, flags | READ_NEW); + msg_silent = old_msg_silent; #ifdef FEAT_NETBEANS_INTG netbeansFireChanges = oldFire; #endif diff --git a/src/ex_cmds.c b/src/ex_cmds.c index 6461c3c08f..ae88cc69e8 100644 --- a/src/ex_cmds.c +++ b/src/ex_cmds.c @@ -2605,7 +2605,8 @@ ex_file(exarg_T *eap) return; } /* print full file name if :cd used */ - fileinfo(FALSE, FALSE, eap->forceit); + if (!shortmess(SHM_FILEINFO)) + fileinfo(FALSE, FALSE, eap->forceit); } /* @@ -3884,7 +3885,8 @@ do_ecmd( msg_scroll = msg_scroll_save; msg_scrolled_ign = TRUE; - fileinfo(FALSE, TRUE, FALSE); + if (!shortmess(SHM_FILEINFO)) + fileinfo(FALSE, TRUE, FALSE); msg_scrolled_ign = FALSE; } diff --git a/src/option.h b/src/option.h index 6b194bc0d1..460e30084a 100644 --- a/src/option.h +++ b/src/option.h @@ -214,7 +214,8 @@ #define SHM_INTRO 'I' /* intro messages */ #define SHM_COMPLETIONMENU 'c' /* completion menu messages */ #define SHM_RECORDING 'q' /* short recording message */ -#define SHM_ALL "rmfixlnwaWtToOsAIcq" /* all possible flags for 'shm' */ +#define SHM_FILEINFO 'F' /* no file info messages */ +#define SHM_ALL "rmfixlnwaWtToOsAIcqF" /* all possible flags for 'shm' */ /* characters for p_go: */ #define GO_ASEL 'a' /* autoselect */ diff --git a/src/version.c b/src/version.c index 5695515f55..f6b1f3baa8 100644 --- a/src/version.c +++ b/src/version.c @@ -743,6 +743,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 1570, /**/ 1569, /**/ From 8e15ffcde757ffc6cfe8b5e384948b3278e9af33 Mon Sep 17 00:00:00 2001 From: Bram Moolenaar Date: Tue, 15 Mar 2016 16:35:39 +0100 Subject: [PATCH 09/18] patch 7.4.1571 Problem: No test for ":help". Solution: Add a test for what 7.4.1568 fixed. (Higashi Higashi) --- src/testdir/test_alot.vim | 1 + src/testdir/test_help_tagjump.vim | 18 ++++++++++++++++++ src/version.c | 2 ++ 3 files changed, 21 insertions(+) create mode 100644 src/testdir/test_help_tagjump.vim diff --git a/src/testdir/test_alot.vim b/src/testdir/test_alot.vim index 55502bae6c..f4a1450319 100644 --- a/src/testdir/test_alot.vim +++ b/src/testdir/test_alot.vim @@ -9,6 +9,7 @@ source test_expand.vim source test_feedkeys.vim source test_file_perm.vim source test_glob2regpat.vim +source test_help_tagjump.vim source test_join.vim source test_lispwords.vim source test_menu.vim diff --git a/src/testdir/test_help_tagjump.vim b/src/testdir/test_help_tagjump.vim new file mode 100644 index 0000000000..d1e9ad422b --- /dev/null +++ b/src/testdir/test_help_tagjump.vim @@ -0,0 +1,18 @@ +" Tests for :help! {subject} + +func Test_help_tagjump() + help + call assert_equal("help", &filetype) + call assert_true(getline('.') =~ '\*help.txt\*') + helpclose + + exec "help! ('textwidth'" + call assert_equal("help", &filetype) + call assert_true(getline('.') =~ "\\*'textwidth'\\*") + helpclose + + exec "help! ('buflisted')," + call assert_equal("help", &filetype) + call assert_true(getline('.') =~ "\\*'buflisted'\\*") + helpclose +endfunc diff --git a/src/version.c b/src/version.c index f6b1f3baa8..944ffea316 100644 --- a/src/version.c +++ b/src/version.c @@ -743,6 +743,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 1571, /**/ 1570, /**/ From 85a7cb4dcf50aa562ff1fc872bfc1b50a5a9e368 Mon Sep 17 00:00:00 2001 From: Bram Moolenaar Date: Tue, 15 Mar 2016 16:53:26 +0100 Subject: [PATCH 10/18] patch 7.4.1572 Problem: Setting 'compatible' in test influences following tests. Solution: Turn 'compatible' off again. --- src/testdir/test_backspace_opt.vim | 1 + src/version.c | 2 ++ 2 files changed, 3 insertions(+) diff --git a/src/testdir/test_backspace_opt.vim b/src/testdir/test_backspace_opt.vim index 5793e34866..f80e831e9a 100644 --- a/src/testdir/test_backspace_opt.vim +++ b/src/testdir/test_backspace_opt.vim @@ -53,6 +53,7 @@ func Test_backspace_option() " Cleared when 'compatible' is set set compatible call assert_equal('', &backspace) + set nocompatible endfunc " vim: tabstop=2 shiftwidth=0 expandtab diff --git a/src/version.c b/src/version.c index 944ffea316..51068b4323 100644 --- a/src/version.c +++ b/src/version.c @@ -743,6 +743,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 1572, /**/ 1571, /**/ From ce2ec0a82a778ff4d79a2c3309f6cac079d7b5ee Mon Sep 17 00:00:00 2001 From: Bram Moolenaar Date: Tue, 15 Mar 2016 17:10:19 +0100 Subject: [PATCH 11/18] patch 7.4.1573 Problem: Tests get stuck at the more prompt. Solution: Move the backspace test out of test_alot. --- src/testdir/Make_all.mak | 1 + src/testdir/test_alot.vim | 1 - src/version.c | 2 ++ 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/testdir/Make_all.mak b/src/testdir/Make_all.mak index 1885bd7ed2..84474d920c 100644 --- a/src/testdir/Make_all.mak +++ b/src/testdir/Make_all.mak @@ -170,6 +170,7 @@ SCRIPTS_GUI = test16.out # Keep test_alot.res as the last one, sort the others. NEW_TESTS = test_arglist.res \ test_assert.res \ + test_backspace_opt.res \ test_cdo.res \ test_channel.res \ test_hardcopy.res \ diff --git a/src/testdir/test_alot.vim b/src/testdir/test_alot.vim index f4a1450319..94ff8b1dac 100644 --- a/src/testdir/test_alot.vim +++ b/src/testdir/test_alot.vim @@ -2,7 +2,6 @@ " This makes testing go faster, since Vim doesn't need to restart. source test_assign.vim -source test_backspace_opt.vim source test_cursor_func.vim source test_delete.vim source test_expand.vim diff --git a/src/version.c b/src/version.c index 51068b4323..c3c932381a 100644 --- a/src/version.c +++ b/src/version.c @@ -743,6 +743,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 1573, /**/ 1572, /**/ From d22e9465f6228207a4fe722ee84371c7817060d6 Mon Sep 17 00:00:00 2001 From: Bram Moolenaar Date: Tue, 15 Mar 2016 17:43:55 +0100 Subject: [PATCH 12/18] patch 7.4.1574 Problem: ":undo 0" does not work. (Florent Fayolle) Solution: Make it undo all the way. (closes #688) --- src/testdir/test_alot.vim | 1 + src/testdir/test_undolevels.vim | 2 -- src/undo.c | 9 ++++++++- src/version.c | 2 ++ 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/testdir/test_alot.vim b/src/testdir/test_alot.vim index 94ff8b1dac..bd74afc4aa 100644 --- a/src/testdir/test_alot.vim +++ b/src/testdir/test_alot.vim @@ -4,6 +4,7 @@ source test_assign.vim source test_cursor_func.vim source test_delete.vim +source test_ex_undo.vim source test_expand.vim source test_feedkeys.vim source test_file_perm.vim diff --git a/src/testdir/test_undolevels.vim b/src/testdir/test_undolevels.vim index 427cece24c..7bb25effb5 100644 --- a/src/testdir/test_undolevels.vim +++ b/src/testdir/test_undolevels.vim @@ -1,7 +1,5 @@ " Tests for 'undolevels' -set nocompatible viminfo+=nviminfo - func FillBuffer() for i in range(1,13) put=i diff --git a/src/undo.c b/src/undo.c index 2bf815ba45..07b2781307 100644 --- a/src/undo.c +++ b/src/undo.c @@ -2286,7 +2286,14 @@ undo_time( * Init "closest" to a value we can't reach. */ if (absolute) { - target = step; + if (step == 0) + { + /* target 0 does not exist, got to 1 and above it. */ + target = 1; + above = TRUE; + } + else + target = step; closest = -1; } else diff --git a/src/version.c b/src/version.c index c3c932381a..4779f7d876 100644 --- a/src/version.c +++ b/src/version.c @@ -743,6 +743,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 1574, /**/ 1573, /**/ From 8067a64852d6d134b493c5674e404225ed4bbe7d Mon Sep 17 00:00:00 2001 From: Bram Moolenaar Date: Tue, 15 Mar 2016 17:52:10 +0100 Subject: [PATCH 13/18] Add missing test file. --- src/testdir/test_ex_undo.vim | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 src/testdir/test_ex_undo.vim diff --git a/src/testdir/test_ex_undo.vim b/src/testdir/test_ex_undo.vim new file mode 100644 index 0000000000..44feb3680a --- /dev/null +++ b/src/testdir/test_ex_undo.vim @@ -0,0 +1,19 @@ +" Tests for :undo + +func Test_ex_undo() + new ex-undo + setlocal ul=10 + exe "normal ione\n\" + setlocal ul=10 + exe "normal itwo\n\" + setlocal ul=10 + exe "normal ithree\n\" + call assert_equal(4, line('$')) + undo + call assert_equal(3, line('$')) + undo 1 + call assert_equal(2, line('$')) + undo 0 + call assert_equal(1, line('$')) + quit! +endfunc From 89e375a88f3eceb73bbd97e78aca1a1c4647c897 Mon Sep 17 00:00:00 2001 From: Bram Moolenaar Date: Tue, 15 Mar 2016 18:09:57 +0100 Subject: [PATCH 14/18] patch 7.4.1575 Problem: Using wrong size for struct. Solution: Use the size for wide API. (Ken Takata) --- src/gui_w32.c | 5 ++--- src/version.c | 2 ++ 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/gui_w32.c b/src/gui_w32.c index 6cc2e06988..b2ee9ca641 100644 --- a/src/gui_w32.c +++ b/src/gui_w32.c @@ -3682,10 +3682,9 @@ gui_mch_browseW( filterp = convert_filterW(filter); vim_memset(&fileStruct, 0, sizeof(OPENFILENAMEW)); -#ifdef OPENFILENAME_SIZE_VERSION_400 +#ifdef OPENFILENAME_SIZE_VERSION_400W /* be compatible with Windows NT 4.0 */ - /* TODO: what to use for OPENFILENAMEW??? */ - fileStruct.lStructSize = OPENFILENAME_SIZE_VERSION_400; + fileStruct.lStructSize = OPENFILENAME_SIZE_VERSION_400W; #else fileStruct.lStructSize = sizeof(fileStruct); #endif diff --git a/src/version.c b/src/version.c index 4779f7d876..4ac46b05d7 100644 --- a/src/version.c +++ b/src/version.c @@ -743,6 +743,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 1575, /**/ 1574, /**/ From 927030af23982a70580178e32806cd3638ce6e5b Mon Sep 17 00:00:00 2001 From: Bram Moolenaar Date: Tue, 15 Mar 2016 18:23:55 +0100 Subject: [PATCH 15/18] patch 7.4.1576 Problem: Write error of viminfo file is not handled properly. (Christian Neukirchen) Solution: Check the return value of fclose(). (closes #682) --- src/ex_cmds.c | 24 ++++++++++++++---------- src/version.c | 2 ++ 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/ex_cmds.c b/src/ex_cmds.c index ae88cc69e8..8a763c9a9d 100644 --- a/src/ex_cmds.c +++ b/src/ex_cmds.c @@ -2065,26 +2065,30 @@ write_viminfo(char_u *file, int forceit) viminfo_errcnt = 0; do_viminfo(fp_in, fp_out, forceit ? 0 : (VIF_WANT_INFO | VIF_WANT_MARKS)); - fclose(fp_out); /* errors are ignored !? */ + if (fclose(fp_out) == EOF) + ++viminfo_errcnt; + if (fp_in != NULL) { fclose(fp_in); /* In case of an error keep the original viminfo file. Otherwise * rename the newly written file. Give an error if that fails. */ - if (viminfo_errcnt == 0 && vim_rename(tempname, fname) == -1) + if (viminfo_errcnt == 0) { - ++viminfo_errcnt; - EMSG2(_("E886: Can't rename viminfo file to %s!"), fname); + if (vim_rename(tempname, fname) == -1) + { + ++viminfo_errcnt; + EMSG2(_("E886: Can't rename viminfo file to %s!"), fname); + } +# ifdef WIN3264 + /* If the viminfo file was hidden then also hide the new file. */ + else if (hidden) + mch_hide(fname); +# endif } if (viminfo_errcnt > 0) mch_remove(tempname); - -#ifdef WIN3264 - /* If the viminfo file was hidden then also hide the new file. */ - if (hidden) - mch_hide(fname); -#endif } end: diff --git a/src/version.c b/src/version.c index 4ac46b05d7..5cc53c8a78 100644 --- a/src/version.c +++ b/src/version.c @@ -743,6 +743,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 1576, /**/ 1575, /**/ From ab1fa3955f25dfdb7e329c3bd76e175c93c8cb5e Mon Sep 17 00:00:00 2001 From: Bram Moolenaar Date: Tue, 15 Mar 2016 19:33:34 +0100 Subject: [PATCH 16/18] patch 7.4.1577 Problem: Cannot pass "dict.Myfunc" around as a partial. Solution: Create a partial when expected. --- src/eval.c | 59 +++++++++++++++++++++++++++++++----- src/testdir/test_partial.vim | 18 +++++++++++ src/version.c | 2 ++ 3 files changed, 72 insertions(+), 7 deletions(-) diff --git a/src/eval.c b/src/eval.c index 7776cc6c33..38c192ed1b 100644 --- a/src/eval.c +++ b/src/eval.c @@ -110,6 +110,7 @@ static char *e_illvar = N_("E461: Illegal variable name: %s"); #ifdef FEAT_FLOAT static char *e_float_as_string = N_("E806: using Float as a String"); #endif +static char *e_dict_both = N_("E924: can't have both a \"self\" dict and a partial: %s"); #define NAMESPACE_CHAR (char_u *)"abglstvw" @@ -8912,8 +8913,7 @@ call_func( name); break; case ERROR_BOTH: - emsg_funcname(N_("E924: can't have both a \"self\" dict and a partial: %s"), - name); + emsg_funcname(e_dict_both, name); break; } } @@ -11782,12 +11782,29 @@ f_function(typval_T *argvars, typval_T *rettv) { char_u *s; char_u *name; + int use_string = FALSE; - s = get_tv_string(&argvars[0]); - if (s == NULL || *s == NUL || VIM_ISDIGIT(*s)) + if (argvars[0].v_type == VAR_FUNC) + { + /* function(MyFunc, [arg], dict) */ + s = argvars[0].vval.v_string; + } + else if (argvars[0].v_type == VAR_PARTIAL + && argvars[0].vval.v_partial != NULL) + /* function(dict.MyFunc, [arg]) */ + s = argvars[0].vval.v_partial->pt_name; + else + { + /* function('MyFunc', [arg], dict) */ + s = get_tv_string(&argvars[0]); + use_string = TRUE; + } + + if (s == NULL || *s == NUL || (use_string && VIM_ISDIGIT(*s))) EMSG2(_(e_invarg2), s); /* Don't check an autoload name for existence here. */ - else if (vim_strchr(s, AUTOLOAD_CHAR) == NULL && !function_exists(s)) + else if (use_string && vim_strchr(s, AUTOLOAD_CHAR) == NULL + && !function_exists(s)) EMSG2(_("E700: Unknown function: %s"), s); else { @@ -11837,6 +11854,12 @@ f_function(typval_T *argvars, typval_T *rettv) vim_free(name); return; } + if (argvars[0].v_type == VAR_PARTIAL) + { + EMSG2(_(e_dict_both), name); + vim_free(name); + return; + } if (argvars[dict_idx].vval.v_dict == NULL) dict_idx = 0; } @@ -11880,7 +11903,12 @@ f_function(typval_T *argvars, typval_T *rettv) } } - if (dict_idx > 0) + if (argvars[0].v_type == VAR_PARTIAL) + { + pt->pt_dict = argvars[0].vval.v_partial->pt_dict; + ++pt->pt_dict->dv_refcount; + } + else if (dict_idx > 0) { pt->pt_dict = argvars[dict_idx].vval.v_dict; ++pt->pt_dict->dv_refcount; @@ -21533,7 +21561,7 @@ handle_subscript( rettv->v_type = VAR_UNKNOWN; /* Invoke the function. Recursive! */ - if (rettv->v_type == VAR_PARTIAL) + if (functv.v_type == VAR_PARTIAL) { pt = functv.vval.v_partial; s = pt->pt_name; @@ -21582,6 +21610,23 @@ handle_subscript( } } } + + if (rettv->v_type == VAR_FUNC && selfdict != NULL) + { + partial_T *pt = (partial_T *)alloc_clear(sizeof(partial_T)); + + /* Turn "dict.Func" into a partial for "Func" with "dict". */ + if (pt != NULL) + { + pt->pt_dict = selfdict; + selfdict = NULL; + pt->pt_name = rettv->vval.v_string; + func_ref(pt->pt_name); + rettv->v_type = VAR_PARTIAL; + rettv->vval.v_partial = pt; + } + } + dict_unref(selfdict); return ret; } diff --git a/src/testdir/test_partial.vim b/src/testdir/test_partial.vim index b1a52db03b..ddc85e0ef9 100644 --- a/src/testdir/test_partial.vim +++ b/src/testdir/test_partial.vim @@ -50,3 +50,21 @@ func Test_partial_dict() call assert_equal("hello/xxx/yyy", Cb("xxx", "yyy")) call assert_fails('Cb("fff")', 'E492:') endfunc + +func Test_partial_implicit() + let dict = {'name': 'foo'} + func dict.MyFunc(arg) dict + return self.name . '/' . a:arg + endfunc + + call assert_equal('foo/bar', dict.MyFunc('bar')) + + call assert_fails('let func = dict.MyFunc', 'E704:') + let Func = dict.MyFunc + call assert_equal('foo/aaa', Func('aaa')) + + let Func = function(dict.MyFunc, ['bbb']) + call assert_equal('foo/bbb', Func()) + + call assert_fails('call function(dict.MyFunc, ["bbb"], dict)', 'E924:') +endfunc diff --git a/src/version.c b/src/version.c index 5cc53c8a78..5c26ce6108 100644 --- a/src/version.c +++ b/src/version.c @@ -743,6 +743,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 1577, /**/ 1576, /**/ From 975b5271eed4fa0500c24a8f37be0b1797cb9db7 Mon Sep 17 00:00:00 2001 From: Bram Moolenaar Date: Tue, 15 Mar 2016 23:10:59 +0100 Subject: [PATCH 17/18] patch 7.4.1578 Problem: There is no way to invoke a function later or periodically. Solution: Add timer support. --- runtime/doc/eval.txt | 59 ++++++++++--- src/eval.c | 87 +++++++++++++++++++ src/ex_cmds2.c | 168 ++++++++++++++++++++++++++++++++++++ src/ex_docmd.c | 14 ++- src/feature.h | 7 ++ src/gui.c | 35 +++++++- src/proto/eval.pro | 1 + src/proto/ex_cmds2.pro | 8 +- src/proto/screen.pro | 1 + src/screen.c | 21 +++++ src/structs.h | 15 ++++ src/testdir/test_alot.vim | 1 + src/testdir/test_timers.vim | 32 +++++++ src/version.c | 7 ++ 14 files changed, 438 insertions(+), 18 deletions(-) create mode 100644 src/testdir/test_timers.vim diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt index 6cc82b445c..43e25faad1 100644 --- a/runtime/doc/eval.txt +++ b/runtime/doc/eval.txt @@ -1,4 +1,4 @@ -*eval.txt* For Vim version 7.4. Last change: 2016 Mar 14 +*eval.txt* For Vim version 7.4. Last change: 2016 Mar 15 VIM REFERENCE MANUAL by Bram Moolenaar @@ -350,10 +350,6 @@ This works like: > : let index = index + 1 :endwhile -Note that all items in the list should be of the same type, otherwise this -results in error |E706|. To avoid this |:unlet| the variable at the end of -the loop. - If all you want to do is modify each item in the list then the |map()| function will be a simpler method than a for loop. @@ -2133,9 +2129,12 @@ tabpagewinnr( {tabarg}[, {arg}]) Number number of current window in tab page taglist( {expr}) List list of tags matching {expr} tagfiles() List tags files used -tempname() String name for a temporary file tan( {expr}) Float tangent of {expr} tanh( {expr}) Float hyperbolic tangent of {expr} +tempname() String name for a temporary file +timer_start( {time}, {callback} [, {options}]) + Number create a timer +timer_stop( {timer}) none stop a timer 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} @@ -3572,8 +3571,15 @@ foreground() Move the Vim window to the foreground. Useful when sent from *function()* *E700* *E922* *E923* function({name} [, {arglist}] [, {dict}]) Return a |Funcref| variable that refers to function {name}. - {name} can be a user defined function or an internal function. + {name} can be the name of a user defined function or an + internal function. + {name} can also be a Funcref, also a partial. When it is a + partial the dict stored in it will be used and the {dict} + argument is not allowed. E.g.: > + let FuncWithArg = function(dict.Func, [arg]) + let Broken = function(dict.Func, [arg], dict) +< When {arglist} or {dict} is present this creates a partial. That mans the argument list and/or the dictionary is stored in the Funcref and will be used when the Funcref is called. @@ -3598,6 +3604,10 @@ function({name} [, {arglist}] [, {dict}]) let Func = function('Callback', context) ... call Func() " will echo: called for example +< The use of function() is not needed when there are no extra + arguments, these two are equivalent: > + let Func = function('Callback', context) + let Func = context.Callback < The argument list and the Dictionary can be combined: > function Callback(arg1, count) dict @@ -4523,13 +4533,13 @@ job_info({job}) *job_info()* "status" what |job_status()| returns "channel" what |job_getchannel()| returns "exitval" only valid when "status" is "dead" - "exit-cb" function to be called on exit + "exit_cb" function to be called on exit "stoponexit" |job-stoponexit| job_setoptions({job}, {options}) *job_setoptions()* Change options for {job}. Supported are: "stoponexit" |job-stoponexit| - "exit-cb" |job-exit-cb| + "exit_cb" |job-exit_cb| job_start({command} [, {options}]) *job_start()* Start a job and return a Job object. Unlike |system()| and @@ -6897,8 +6907,7 @@ systemlist({expr} [, {input}]) *systemlist()* is the same as |readfile()| will output with {binary} argument set to "b". - Returns an empty string on error, so be careful not to run - into |E706|. + Returns an empty string on error. tabpagebuflist([{arg}]) *tabpagebuflist()* @@ -7014,6 +7023,33 @@ tanh({expr}) *tanh()* {only available when compiled with the |+float| feature} + *timer_start()* +timer_start({time}, {callback} [, {options}]) + Create a timer and return the timer ID. + + {time} is the waiting time in milliseconds. This is the + minimum time before invoking the callback. When the system is + busy or Vim is not waiting for input the time will be longer. + + {callback} is the function to call. It can be the name of a + function or a Funcref. It is called with one argument, which + is the timer ID. The callback is only invoked when Vim is + waiting for input. + + {options} is a dictionary. Supported entries: + "repeat" Number of times to repeat calling the + callback. -1 means forever. + + Example: > + func MyHandler(timer) + echo 'Handler called' + endfunc + let timer = timer_start(500, 'MyHandler', + \ {'repeat': 3}) +< This will invoke MyHandler() three times at 500 msec + intervals. + {only available when compiled with the |+timers| feature} + tolower({expr}) *tolower()* The result is a copy of the String given, with all uppercase characters turned into lowercase (just like applying |gu| to @@ -7570,6 +7606,7 @@ termresponse Compiled with support for |t_RV| and |v:termresponse|. textobjects Compiled with support for |text-objects|. tgetent Compiled with tgetent support, able to use a termcap or terminfo file. +timers Compiled with |timer_start()| support. title Compiled with window title support |'title'|. toolbar Compiled with support for |gui-toolbar|. unix Unix version of Vim. diff --git a/src/eval.c b/src/eval.c index 38c192ed1b..506932403a 100644 --- a/src/eval.c +++ b/src/eval.c @@ -794,6 +794,10 @@ static void f_test(typval_T *argvars, typval_T *rettv); static void f_tan(typval_T *argvars, typval_T *rettv); static void f_tanh(typval_T *argvars, typval_T *rettv); #endif +#ifdef FEAT_TIMERS +static void f_timer_start(typval_T *argvars, typval_T *rettv); +static void f_timer_stop(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); static void f_tr(typval_T *argvars, typval_T *rettv); @@ -8404,6 +8408,10 @@ static struct fst #endif {"tempname", 0, 0, f_tempname}, {"test", 1, 1, f_test}, +#ifdef FEAT_TIMERS + {"timer_start", 2, 3, f_timer_start}, + {"timer_stop", 1, 1, f_timer_stop}, +#endif {"tolower", 1, 1, f_tolower}, {"toupper", 1, 1, f_toupper}, {"tr", 3, 3, f_tr}, @@ -13648,6 +13656,9 @@ f_has(typval_T *argvars, typval_T *rettv) #ifdef HAVE_TGETENT "tgetent", #endif +#ifdef FEAT_TIMERS + "timers", +#endif #ifdef FEAT_TITLE "title", #endif @@ -20077,6 +20088,82 @@ f_tanh(typval_T *argvars, typval_T *rettv) } #endif +#if defined(FEAT_JOB_CHANNEL) || defined(FEAT_TIMERS) || defined(PROTO) +/* + * Get a callback from "arg". It can be a Funcref or a function name. + * When "arg" is zero return an empty string. + * Return NULL for an invalid argument. + */ + char_u * +get_callback(typval_T *arg, partial_T **pp) +{ + if (arg->v_type == VAR_PARTIAL && arg->vval.v_partial != NULL) + { + *pp = arg->vval.v_partial; + return (*pp)->pt_name; + } + *pp = NULL; + if (arg->v_type == VAR_FUNC || arg->v_type == VAR_STRING) + return arg->vval.v_string; + if (arg->v_type == VAR_NUMBER && arg->vval.v_number == 0) + return (char_u *)""; + EMSG(_("E921: Invalid callback argument")); + return NULL; +} +#endif + +#ifdef FEAT_TIMERS +/* + * "timer_start(time, callback [, options])" function + */ + static void +f_timer_start(typval_T *argvars, typval_T *rettv) +{ + long msec = get_tv_number(&argvars[0]); + timer_T *timer; + int repeat = 0; + char_u *callback; + dict_T *dict; + + if (argvars[2].v_type != VAR_UNKNOWN) + { + if (argvars[2].v_type != VAR_DICT + || (dict = argvars[2].vval.v_dict) == NULL) + { + EMSG2(_(e_invarg2), get_tv_string(&argvars[2])); + return; + } + if (dict_find(dict, (char_u *)"repeat", -1) != NULL) + repeat = get_dict_number(dict, (char_u *)"repeat"); + } + + timer = create_timer(msec, repeat); + callback = get_callback(&argvars[1], &timer->tr_partial); + if (callback == NULL) + { + stop_timer(timer); + rettv->vval.v_number = -1; + } + else + { + timer->tr_callback = vim_strsave(callback); + rettv->vval.v_number = timer->tr_id; + } +} + +/* + * "timer_stop(timer)" function + */ + static void +f_timer_stop(typval_T *argvars, typval_T *rettv UNUSED) +{ + timer_T *timer = find_timer(get_tv_number(&argvars[0])); + + if (timer != NULL) + stop_timer(timer); +} +#endif + /* * "tolower(string)" function */ diff --git a/src/ex_cmds2.c b/src/ex_cmds2.c index d7bf60901e..018f44cc29 100644 --- a/src/ex_cmds2.c +++ b/src/ex_cmds2.c @@ -1088,6 +1088,174 @@ profile_zero(proftime_T *tm) # endif /* FEAT_PROFILE || FEAT_RELTIME */ +# if defined(FEAT_TIMERS) || defined(PROTO) +static timer_T *first_timer = NULL; +static int last_timer_id = 0; + +/* + * Insert a timer in the list of timers. + */ + static void +insert_timer(timer_T *timer) +{ + timer->tr_next = first_timer; + timer->tr_prev = NULL; + if (first_timer != NULL) + first_timer->tr_prev = timer; + first_timer = timer; +} + +/* + * Take a timer out of the list of timers. + */ + static void +remove_timer(timer_T *timer) +{ + if (timer->tr_prev == NULL) + first_timer = timer->tr_next; + else + timer->tr_prev->tr_next = timer->tr_next; + if (timer->tr_next != NULL) + timer->tr_next->tr_prev = timer->tr_prev; +} + + static void +free_timer(timer_T *timer) +{ + vim_free(timer->tr_callback); + partial_unref(timer->tr_partial); + vim_free(timer); +} + +/* + * Create a timer and return it. NULL if out of memory. + * Caller should set the callback. + */ + timer_T * +create_timer(long msec, int repeat) +{ + timer_T *timer = (timer_T *)alloc_clear(sizeof(timer_T)); + + if (timer == NULL) + return NULL; + timer->tr_id = ++last_timer_id; + insert_timer(timer); + if (repeat != 0) + { + timer->tr_repeat = repeat - 1; + timer->tr_interval = msec; + } + + profile_setlimit(msec, &timer->tr_due); + return timer; +} + +/* + * Invoke the callback of "timer". + */ + static void +timer_callback(timer_T *timer) +{ + typval_T rettv; + int dummy; + typval_T argv[2]; + + argv[0].v_type = VAR_NUMBER; + argv[0].vval.v_number = timer->tr_id; + argv[1].v_type = VAR_UNKNOWN; + + call_func(timer->tr_callback, (int)STRLEN(timer->tr_callback), + &rettv, 1, argv, 0L, 0L, &dummy, TRUE, + timer->tr_partial, NULL); + clear_tv(&rettv); +} + +/* + * Call timers that are due. + * Return the time in msec until the next timer is due. + */ + long +check_due_timer() +{ + timer_T *timer; + long this_due; + long next_due; + proftime_T now; + int did_one = FALSE; +# ifdef WIN3264 + LARGE_INTEGER fr; + + QueryPerformanceFrequency(&fr); +# endif + while (!got_int) + { + profile_start(&now); + next_due = -1; + for (timer = first_timer; timer != NULL; timer = timer->tr_next) + { +# ifdef WIN3264 + this_due = (long)(((double)(timer->tr_due.QuadPart - now.QuadPart) + / (double)fr.QuadPart) * 1000); +# else + this_due = (timer->tr_due.tv_sec - now.tv_sec) * 1000 + + (timer->tr_due.tv_usec - now.tv_usec) / 1000; +# endif + if (this_due <= 1) + { + remove_timer(timer); + timer_callback(timer); + did_one = TRUE; + if (timer->tr_repeat != 0) + { + profile_setlimit(timer->tr_interval, &timer->tr_due); + if (timer->tr_repeat > 0) + --timer->tr_repeat; + insert_timer(timer); + } + else + free_timer(timer); + /* the callback may do anything, start all over */ + break; + } + if (next_due == -1 || next_due > this_due) + next_due = this_due; + } + if (timer == NULL) + break; + } + + if (did_one) + redraw_after_callback(); + + return next_due; +} + +/* + * Find a timer by ID. Returns NULL if not found; + */ + timer_T * +find_timer(int id) +{ + timer_T *timer; + + for (timer = first_timer; timer != NULL; timer = timer->tr_next) + if (timer->tr_id == id) + break; + return timer; +} + + +/* + * Stop a timer and delete it. + */ + void +stop_timer(timer_T *timer) +{ + remove_timer(timer); + free_timer(timer); +} +# endif + #if defined(FEAT_SYN_HL) && defined(FEAT_RELTIME) && defined(FEAT_FLOAT) # if defined(HAVE_MATH_H) # include diff --git a/src/ex_docmd.c b/src/ex_docmd.c index 9b116e2bde..12730a93d2 100644 --- a/src/ex_docmd.c +++ b/src/ex_docmd.c @@ -8894,12 +8894,22 @@ ex_sleep(exarg_T *eap) do_sleep(long msec) { long done; + long wait_now; cursor_on(); out_flush(); - for (done = 0; !got_int && done < msec; done += 1000L) + for (done = 0; !got_int && done < msec; done += wait_now) { - ui_delay(msec - done > 1000L ? 1000L : msec - done, TRUE); + wait_now = msec - done > 1000L ? 1000L : msec - done; +#ifdef FEAT_TIMERS + { + long due_time = check_due_timer(); + + if (due_time > 0 && due_time < wait_now) + wait_now = due_time; + } +#endif + ui_delay(wait_now, TRUE); ui_breakcheck(); #ifdef MESSAGE_QUEUE /* Process the netbeans and clientserver messages that may have been diff --git a/src/feature.h b/src/feature.h index 957bbf27d4..455ab20ea0 100644 --- a/src/feature.h +++ b/src/feature.h @@ -399,6 +399,13 @@ # define FEAT_RELTIME #endif +/* + * +timers timer_start() + */ +#if defined(FEAT_RELTIME) && (defined(UNIX) || defined(WIN32)) +# define FEAT_TIMERS +#endif + /* * +textobjects Text objects: "vaw", "das", etc. */ diff --git a/src/gui.c b/src/gui.c index 2701265f1d..f52d217aa8 100644 --- a/src/gui.c +++ b/src/gui.c @@ -2849,6 +2849,35 @@ gui_insert_lines(int row, int count) } } + static int +gui_wait_for_chars_or_timer(long wtime) +{ +#ifdef FEAT_TIMERS + int due_time; + long remaining = wtime; + + /* When waiting very briefly don't trigger timers. */ + if (wtime >= 0 && wtime < 10L) + return gui_mch_wait_for_chars(wtime); + + while (wtime < 0 || remaining > 0) + { + /* Trigger timers and then get the time in wtime until the next one is + * due. Wait up to that time. */ + due_time = check_due_timer(); + if (due_time <= 0 || (wtime > 0 && due_time > remaining)) + due_time = remaining; + if (gui_mch_wait_for_chars(due_time)) + return TRUE; + if (wtime > 0) + remaining -= due_time; + } + return FALSE; +#else + return gui_mch_wait_for_chars(wtime); +#endif +} + /* * The main GUI input routine. Waits for a character from the keyboard. * wtime == -1 Wait forever. @@ -2885,7 +2914,7 @@ gui_wait_for_chars(long wtime) /* Blink when waiting for a character. Probably only does something * for showmatch() */ gui_mch_start_blink(); - retval = gui_mch_wait_for_chars(wtime); + retval = gui_wait_for_chars_or_timer(wtime); gui_mch_stop_blink(); return retval; } @@ -2901,7 +2930,7 @@ gui_wait_for_chars(long wtime) * 'updatetime' and if nothing is typed within that time put the * K_CURSORHOLD key in the input buffer. */ - if (gui_mch_wait_for_chars(p_ut) == OK) + if (gui_wait_for_chars_or_timer(p_ut) == OK) retval = OK; #ifdef FEAT_AUTOCMD else if (trigger_cursorhold()) @@ -2922,7 +2951,7 @@ gui_wait_for_chars(long wtime) { /* Blocking wait. */ before_blocking(); - retval = gui_mch_wait_for_chars(-1L); + retval = gui_wait_for_chars_or_timer(-1L); } gui_mch_stop_blink(); diff --git a/src/proto/eval.pro b/src/proto/eval.pro index dee95c4ed2..1de7a6d9dc 100644 --- a/src/proto/eval.pro +++ b/src/proto/eval.pro @@ -91,6 +91,7 @@ void partial_unref(partial_T *pt); void mzscheme_call_vim(char_u *name, typval_T *args, typval_T *rettv); float_T vim_round(float_T f); long do_searchpair(char_u *spat, char_u *mpat, char_u *epat, int dir, char_u *skip, int flags, pos_T *match_pos, linenr_T lnum_stop, long time_limit); +char_u *get_callback(typval_T *arg, partial_T **pp); void set_vim_var_nr(int idx, long val); long get_vim_var_nr(int idx); char_u *get_vim_var_str(int idx); diff --git a/src/proto/ex_cmds2.pro b/src/proto/ex_cmds2.pro index 14546b50f4..5e5b4d4b73 100644 --- a/src/proto/ex_cmds2.pro +++ b/src/proto/ex_cmds2.pro @@ -18,6 +18,10 @@ float_T profile_float(proftime_T *tm); void profile_setlimit(long msec, proftime_T *tm); int profile_passed_limit(proftime_T *tm); void profile_zero(proftime_T *tm); +timer_T *create_timer(long msec, int repeats); +long check_due_timer(void); +timer_T *find_timer(int id); +void stop_timer(timer_T *timer); void profile_divide(proftime_T *tm, int count, proftime_T *tm2); void profile_add(proftime_T *tm, proftime_T *tm2); void profile_self(proftime_T *self, proftime_T *total, proftime_T *children); @@ -60,9 +64,9 @@ void ex_argdelete(exarg_T *eap); void ex_listdo(exarg_T *eap); void ex_compiler(exarg_T *eap); void ex_runtime(exarg_T *eap); -int source_runtime(char_u *name, int all); +int source_runtime(char_u *name, int flags); int do_in_path(char_u *path, char_u *name, int flags, void (*callback)(char_u *fname, void *ck), void *cookie); -int do_in_runtimepath(char_u *name, int all, void (*callback)(char_u *fname, void *ck), void *cookie); +int do_in_runtimepath(char_u *name, int flags, void (*callback)(char_u *fname, void *ck), void *cookie); void ex_packloadall(exarg_T *eap); void ex_packadd(exarg_T *eap); void ex_options(exarg_T *eap); diff --git a/src/proto/screen.pro b/src/proto/screen.pro index 6330fdcbbf..aad8187a1d 100644 --- a/src/proto/screen.pro +++ b/src/proto/screen.pro @@ -6,6 +6,7 @@ void redraw_all_later(int type); void redraw_curbuf_later(int type); void redraw_buf_later(buf_T *buf, int type); int redraw_asap(int type); +void redraw_after_callback(void); void redrawWinline(linenr_T lnum, int invalid); void update_curbuf(int type); void update_screen(int type); diff --git a/src/screen.c b/src/screen.c index b293869cb2..c1eb1c459c 100644 --- a/src/screen.c +++ b/src/screen.c @@ -410,6 +410,27 @@ redraw_asap(int type) return ret; } +/* + * Invoked after an asynchronous callback is called. + * If an echo command was used the cursor needs to be put back where + * it belongs. If highlighting was changed a redraw is needed. + */ + void +redraw_after_callback() +{ + update_screen(0); + setcursor(); + cursor_on(); + out_flush(); +#ifdef FEAT_GUI + if (gui.in_use) + { + gui_update_cursor(TRUE, FALSE); + gui_mch_flush(); + } +#endif +} + /* * Changed something in the current window, at buffer line "lnum", that * requires that line and possibly other lines to be redrawn. diff --git a/src/structs.h b/src/structs.h index ab707d8c3f..6263242f69 100644 --- a/src/structs.h +++ b/src/structs.h @@ -2953,3 +2953,18 @@ struct js_reader void *js_cookie; /* can be used by js_fill */ }; typedef struct js_reader js_read_T; + +typedef struct timer_S timer_T; +struct timer_S +{ + int tr_id; +#ifdef FEAT_TIMERS + timer_T *tr_next; + timer_T *tr_prev; + proftime_T tr_due; /* when the callback is to be invoked */ + int tr_repeat; /* number of times to repeat, -1 forever */ + long tr_interval; /* only set when it repeats */ + char_u *tr_callback; /* allocated */ + partial_T *tr_partial; +#endif +}; diff --git a/src/testdir/test_alot.vim b/src/testdir/test_alot.vim index bd74afc4aa..361559868c 100644 --- a/src/testdir/test_alot.vim +++ b/src/testdir/test_alot.vim @@ -19,5 +19,6 @@ source test_searchpos.vim source test_set.vim source test_sort.vim source test_syn_attr.vim +source test_timers.vim source test_undolevels.vim source test_unlet.vim diff --git a/src/testdir/test_timers.vim b/src/testdir/test_timers.vim new file mode 100644 index 0000000000..9f58a35909 --- /dev/null +++ b/src/testdir/test_timers.vim @@ -0,0 +1,32 @@ +" Test for timers + +if !has('timers') + finish +endif + +func MyHandler(timer) + let s:val += 1 +endfunc + +func Test_oneshot() + let s:val = 0 + let timer = timer_start(50, 'MyHandler') + sleep 200m + call assert_equal(1, s:val) +endfunc + +func Test_repeat_three() + let s:val = 0 + let timer = timer_start(50, 'MyHandler', {'repeat': 3}) + sleep 500m + call assert_equal(3, s:val) +endfunc + +func Test_repeat_many() + let s: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) +endfunc diff --git a/src/version.c b/src/version.c index 5c26ce6108..2d033163df 100644 --- a/src/version.c +++ b/src/version.c @@ -626,6 +626,11 @@ static char *(features[]) = #else "-textobjects", #endif +#ifdef FEAT_TIMERS + "+timers", +#else + "-timers", +#endif #ifdef FEAT_TITLE "+title", #else @@ -743,6 +748,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 1578, /**/ 1577, /**/ From a3dc5e92dcb79bdc4f0103e6eb91de4c7a6ee9a7 Mon Sep 17 00:00:00 2001 From: Bram Moolenaar Date: Tue, 15 Mar 2016 23:19:14 +0100 Subject: [PATCH 18/18] patch 7.4.1579 Problem: Missing changes in channel.c Solution: Include the changes. --- src/channel.c | 36 +----------------------------------- src/version.c | 2 ++ 2 files changed, 3 insertions(+), 35 deletions(-) diff --git a/src/channel.c b/src/channel.c index e66be182f7..1f7ad6174e 100644 --- a/src/channel.c +++ b/src/channel.c @@ -1285,19 +1285,7 @@ invoke_callback(channel_T *channel, char_u *callback, partial_T *partial, &rettv, 2, argv, 0L, 0L, &dummy, TRUE, partial, NULL); clear_tv(&rettv); - /* If an echo command was used the cursor needs to be put back where - * it belongs. If highlighting was changed a redraw is needed. */ - update_screen(0); - setcursor(); - cursor_on(); - out_flush(); -#ifdef FEAT_GUI - if (gui.in_use) - { - gui_update_cursor(TRUE, FALSE); - gui_mch_flush(); - } -#endif + redraw_after_callback(); } /* @@ -3024,28 +3012,6 @@ channel_get_timeout(channel_T *channel, int part) return channel->ch_part[part].ch_timeout; } -/* - * Get a callback from "arg". It can be a Funcref or a function name. - * When "arg" is zero return an empty string. - * Return NULL for an invalid argument. - */ - static char_u * -get_callback(typval_T *arg, partial_T **pp) -{ - if (arg->v_type == VAR_PARTIAL && arg->vval.v_partial != NULL) - { - *pp = arg->vval.v_partial; - return (*pp)->pt_name; - } - *pp = NULL; - if (arg->v_type == VAR_FUNC || arg->v_type == VAR_STRING) - return arg->vval.v_string; - if (arg->v_type == VAR_NUMBER && arg->vval.v_number == 0) - return (char_u *)""; - EMSG(_("E921: Invalid callback argument")); - return NULL; -} - static int handle_mode(typval_T *item, jobopt_T *opt, ch_mode_T *modep, int jo) { diff --git a/src/version.c b/src/version.c index 2d033163df..e4c3412d77 100644 --- a/src/version.c +++ b/src/version.c @@ -748,6 +748,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 1579, /**/ 1578, /**/