To: vim_dev@googlegroups.com Subject: Patch 8.2.3835 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.3835 Problem: The inline-function example does not work. Solution: Drop ":let". Add EX_EXPR_ARG to CMD_var. (issue #9352) Files: runtime/doc/vim9.txt, src/ex_cmds.h, src/testdir/test_vim9_expr.vim *** ../vim-8.2.3834/runtime/doc/vim9.txt 2021-12-01 09:26:29.923616562 +0000 --- runtime/doc/vim9.txt 2021-12-17 12:39:47.806028345 +0000 *************** *** 321,326 **** --- 334,358 ---- } echo temp # Error! + This is especially useful in a user command: > + + command -range Rename { + var save = @a + @a = 'some expression' + echo 'do something with ' .. @a + @a = save + } + + And with autocommands: > + + au BufWritePre *.go { + var save = winsaveview() + silent! exe ':%! some formatting command' + winrestview(save) + } + + Although using a :def function probably works better. + Declaring a variable with a type but without an initializer will initialize to zero, false or empty. *************** *** 499,504 **** --- 567,590 ---- }) No command can follow the "{", only a comment can be used there. + *command-block* + The block can also be used for defining a user command. Inside the block Vim9 + syntax will be used. + + If the statements include a dictionary, its closing bracket must not be + written at the start of a line. Otherwise, it would be parsed as the end of + the block. This does not work: > + command NewCommand { + g:mydict = { + 'key': 'value', + } # ERROR: will be recognized as the end of the block + } + Put the '}' after the last item to avoid this: > + command NewCommand { + g:mydict = { + 'key': 'value' } + } + Rationale: The "}" cannot be after a command because it would require parsing the commands to find it. For consistency with that no command can follow the "{". Unfortunately this means using "() => { command }" does not work, line *** ../vim-8.2.3834/src/ex_cmds.h 2021-12-15 17:53:36.360946452 +0000 --- src/ex_cmds.h 2021-12-17 12:16:38.492532132 +0000 *************** *** 1691,1697 **** EX_RANGE|EX_WHOLEFOLD|EX_EXTRA|EX_DFLALL|EX_CMDWIN|EX_LOCK_OK|EX_NONWHITE_OK, ADDR_LINES), EXCMD(CMD_var, "var", ex_var, ! EX_EXTRA|EX_NOTRLCOM|EX_SBOXOK|EX_CMDWIN|EX_LOCK_OK, ADDR_NONE), EXCMD(CMD_version, "version", ex_version, EX_EXTRA|EX_TRLBAR|EX_CMDWIN|EX_LOCK_OK, --- 1691,1697 ---- EX_RANGE|EX_WHOLEFOLD|EX_EXTRA|EX_DFLALL|EX_CMDWIN|EX_LOCK_OK|EX_NONWHITE_OK, ADDR_LINES), EXCMD(CMD_var, "var", ex_var, ! EX_EXTRA|EX_NOTRLCOM|EX_EXPR_ARG|EX_SBOXOK|EX_CMDWIN|EX_LOCK_OK, ADDR_NONE), EXCMD(CMD_version, "version", ex_version, EX_EXTRA|EX_TRLBAR|EX_CMDWIN|EX_LOCK_OK, *** ../vim-8.2.3834/src/testdir/test_vim9_expr.vim 2021-12-15 15:41:41.085254846 +0000 --- src/testdir/test_vim9_expr.vim 2021-12-17 12:35:46.926504573 +0000 *************** *** 2557,2566 **** --- 2557,2575 ---- k: 0, } } MyCommand + + command YourCommand { + g:global = { + key: 'value' } + } + YourCommand + assert_equal({key: 'value'}, g:global) + unlet g:global END CheckScriptSuccess(lines) delcommand MyCommand + delcommand YourCommand enddef def Test_expr7_call_2bool() *** ../vim-8.2.3834/src/version.c 2021-12-17 11:44:29.640404079 +0000 --- src/version.c 2021-12-17 12:41:00.893882732 +0000 *************** *** 751,752 **** --- 751,754 ---- { /* Add new patch number below this line */ + /**/ + 3835, /**/ -- Never go to the toilet in a paperless office. /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// \\\ \\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///