To: vim_dev@googlegroups.com Subject: Patch 8.2.1934 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.1934 Problem: Vim9: command modifiers in :def function not tested. Solution: Add tests. Fix using modifier before filter command. Files: src/ex_docmd.c, src/vim9compile.c, src/testdir/test_vim9_cmd.vim *** ../vim-8.2.1933/src/ex_docmd.c 2020-10-29 20:24:31.556056458 +0100 --- src/ex_docmd.c 2020-11-01 16:55:15.868458040 +0100 *************** *** 1782,1795 **** */ cmd = ea.cmd; #ifdef FEAT_EVAL ! // In Vim9 script a colon is required before the range. ! may_have_range = !vim9script || starts_with_colon; if (may_have_range) #endif ea.cmd = skip_range(ea.cmd, TRUE, NULL); #ifdef FEAT_EVAL ! if (vim9script && !starts_with_colon) { if (ea.cmd == cmd + 1 && *cmd == '$') // should be "$VAR = val" --- 1782,1808 ---- */ cmd = ea.cmd; #ifdef FEAT_EVAL ! // In Vim9 script a colon is required before the range. This may also be ! // after command modifiers. ! if (vim9script) ! { ! may_have_range = FALSE; ! for (p = ea.cmd; p >= *cmdlinep; --p) ! { ! if (*p == ':') ! may_have_range = TRUE; ! if (p < ea.cmd && !VIM_ISWHITE(*p)) ! break; ! } ! } ! else ! may_have_range = TRUE; if (may_have_range) #endif ea.cmd = skip_range(ea.cmd, TRUE, NULL); #ifdef FEAT_EVAL ! if (vim9script && !may_have_range) { if (ea.cmd == cmd + 1 && *cmd == '$') // should be "$VAR = val" *** ../vim-8.2.1933/src/vim9compile.c 2020-10-30 20:46:22.670118038 +0100 --- src/vim9compile.c 2020-11-01 16:38:34.447330919 +0100 *************** *** 2642,2647 **** --- 2642,2648 ---- type_T *type = ((type_T **)stack->ga_data)[ stack->ga_len - 2]; + // add() can be compiled to instructions if we know the type if (type->tt_type == VAR_LIST) { // inline "add(list, item)" so that the type can be checked *************** *** 7173,7182 **** continue; } break; - - case ':': - starts_with_colon = TRUE; - break; } /* --- 7174,7179 ---- *************** *** 7195,7200 **** --- 7192,7207 ---- generate_cmdmods(&cctx, &local_cmdmod); undo_cmdmod(&local_cmdmod); + // Check if there was a colon after the last command modifier or before + // the current position. + for (p = ea.cmd; p >= line; --p) + { + if (*p == ':') + starts_with_colon = TRUE; + if (p < ea.cmd && !VIM_ISWHITE(*p)) + break; + } + // Skip ":call" to get to the function name. p = ea.cmd; if (checkforcmd(&ea.cmd, "call", 3)) *** ../vim-8.2.1933/src/testdir/test_vim9_cmd.vim 2020-10-29 20:24:31.556056458 +0100 --- src/testdir/test_vim9_cmd.vim 2020-11-01 16:56:23.284266898 +0100 *************** *** 2,7 **** --- 2,8 ---- source check.vim source vim9.vim + source term_util.vim source view_util.vim def Test_edit_wildcards() *************** *** 312,318 **** assert_equal([#{x: 3, y: 4}], tags) enddef ! def Test_filter_is_recognized() var lines =<< trim END final expected = "\nType Name Content\n c \"c piyo" @a = 'hoge' --- 313,319 ---- assert_equal([#{x: 3, y: 4}], tags) enddef ! def Test_command_modifier_filter() var lines =<< trim END final expected = "\nType Name Content\n c \"c piyo" @a = 'hoge' *************** *** 324,329 **** --- 325,459 ---- CheckDefAndScriptSuccess(lines) enddef + def Test_win_command_modifiers() + assert_equal(1, winnr('$')) + + set splitright + vsplit + assert_equal(2, winnr()) + close + aboveleft vsplit + assert_equal(1, winnr()) + close + set splitright& + + vsplit + assert_equal(1, winnr()) + close + belowright vsplit + assert_equal(2, winnr()) + close + rightbelow vsplit + assert_equal(2, winnr()) + close + + browse set + assert_equal('option-window', expand('%')) + close + + vsplit + botright split + assert_equal(3, winnr()) + assert_equal(&columns, winwidth(0)) + close + close + + vsplit + topleft split + assert_equal(1, winnr()) + assert_equal(&columns, winwidth(0)) + close + close + + gettabinfo()->len()->assert_equal(1) + tab split + gettabinfo()->len()->assert_equal(2) + tabclose + + vertical new + assert_inrange(&columns / 2 - 2, &columns / 2 + 1, winwidth(0)) + close + enddef + + func Test_command_modifier_confirm() + CheckNotGui + CheckRunVimInTerminal + + " Test for saving all the modified buffers + let lines =<< trim END + call setline(1, 'changed') + def Getout() + confirm write Xfile + enddef + END + call writefile(lines, 'Xconfirmscript') + call writefile(['empty'], 'Xfile') + let buf = RunVimInTerminal('-S Xconfirmscript', {'rows': 8}) + call term_sendkeys(buf, ":call Getout()\n") + call WaitForAssert({-> assert_match('(Y)es, \[N\]o: ', term_getline(buf, 8))}, 1000) + call term_sendkeys(buf, "y") + call StopVimInTerminal(buf) + + call assert_equal(['changed'], readfile('Xfile')) + call delete('Xfile') + call delete('Xconfirmscript') + endfunc + + def Test_command_modifiers_keep() + if has('unix') + def DoTest(addRflag: bool, keepMarks: bool, hasMarks: bool) + new + setline(1, ['one', 'two', 'three']) + normal 1Gma + normal 2Gmb + normal 3Gmc + if addRflag + set cpo+=R + else + set cpo-=R + endif + if keepMarks + keepmarks :%!cat + else + :%!cat + endif + if hasMarks + assert_equal(1, line("'a")) + assert_equal(2, line("'b")) + assert_equal(3, line("'c")) + else + assert_equal(0, line("'a")) + assert_equal(0, line("'b")) + assert_equal(0, line("'c")) + endif + quit! + enddef + DoTest(false, false, true) + DoTest(true, false, false) + DoTest(false, true, true) + DoTest(true, true, true) + set cpo&vim + endif + + # TODO + # lockmarks + # keepalt + # keeppatterns + # keepjumps + enddef + + def Test_command_modifier_other() + # TODO + # hide + # noautocmd + # noswapfile + # sandbox + # silent + # silent! + # unsilent + # verbose + enddef + def Test_eval_command() var from = 3 var to = 5 *** ../vim-8.2.1933/src/version.c 2020-11-01 13:57:37.551988657 +0100 --- src/version.c 2020-11-01 14:21:48.914645232 +0100 *************** *** 752,753 **** --- 752,755 ---- { /* Add new patch number below this line */ + /**/ + 1934, /**/ -- hundred-and-one symptoms of being an internet addict: 172. You join listservers just for the extra e-mail. /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///