To: vim_dev@googlegroups.com Subject: Patch 8.2.1347 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.1347 Problem: Cannot easily get the script ID. Solution: Support expand(''). Files: runtime/doc/map.txt, src/ex_docmd.c, src/testdir/test_expand_func.vim *** ../vim-8.2.1346/runtime/doc/map.txt 2019-12-12 12:49:06.000000000 +0100 --- runtime/doc/map.txt 2020-08-01 19:57:13.739275860 +0200 *************** *** 1164,1169 **** --- 1167,1176 ---- the script it was defined in. This makes it possible that the command calls a local function or uses a local mapping. + In case the value is used in a context where cannot be correctly + expanded, use the expand() function: > + let &includexpr = expand('') .. 'My_includeexpr()' + Otherwise, using "" outside of a script context is an error. If you need to get the script number to use in a complicated script, you can *** ../vim-8.2.1346/src/ex_docmd.c 2020-08-01 19:23:40.422284128 +0200 --- src/ex_docmd.c 2020-08-01 20:08:09.355016419 +0200 *************** *** 8302,8310 **** #define SPEC_AMATCH (SPEC_ABUF + 1) "", // script file line number #define SPEC_SFLNUM (SPEC_AMATCH + 1) #ifdef FEAT_CLIENTSERVER "" ! # define SPEC_CLIENT (SPEC_SFLNUM + 1) #endif }; --- 8302,8312 ---- #define SPEC_AMATCH (SPEC_ABUF + 1) "", // script file line number #define SPEC_SFLNUM (SPEC_AMATCH + 1) + "", // script ID: 123_ + #define SPEC_SID (SPEC_SFLNUM + 1) #ifdef FEAT_CLIENTSERVER "" ! # define SPEC_CLIENT (SPEC_SID + 1) #endif }; *************** *** 8581,8586 **** --- 8583,8598 ---- break; #endif + case SPEC_SID: + if (current_sctx.sc_sid <= 0) + { + *errormsg = _(e_usingsid); + return NULL; + } + sprintf((char *)strbuf, "%d_", current_sctx.sc_sid); + result = strbuf; + break; + #ifdef FEAT_CLIENTSERVER case SPEC_CLIENT: // Source of last submitted input sprintf((char *)strbuf, PRINTF_HEX_LONG_U, *** ../vim-8.2.1346/src/testdir/test_expand_func.vim 2020-07-26 15:36:12.963172976 +0200 --- src/testdir/test_expand_func.vim 2020-08-01 20:40:28.549065737 +0200 *************** *** 1,5 **** --- 1,7 ---- " Tests for expand() + source shared.vim + let s:sfile = expand('') let s:slnum = str2nr(expand('')) let s:sflnum = str2nr(expand('')) *************** *** 18,37 **** " This test depends on the location in the test file, put it first. func Test_expand_sflnum() ! call assert_equal(5, s:sflnum) ! call assert_equal(22, str2nr(expand(''))) " Line-continuation call assert_equal( ! \ 25, \ str2nr(expand(''))) " Call in script-local function ! call assert_equal(16, s:expand_sflnum()) " Call in command command Flnum echo expand('') ! call assert_equal(34, str2nr(trim(execute('Flnum')))) delcommand Flnum endfunc --- 20,39 ---- " This test depends on the location in the test file, put it first. func Test_expand_sflnum() ! call assert_equal(7, s:sflnum) ! call assert_equal(24, str2nr(expand(''))) " Line-continuation call assert_equal( ! \ 27, \ str2nr(expand(''))) " Call in script-local function ! call assert_equal(18, s:expand_sflnum()) " Call in command command Flnum echo expand('') ! call assert_equal(36, str2nr(trim(execute('Flnum')))) delcommand Flnum endfunc *************** *** 60,66 **** endfunc func Test_expand_slnum() ! call assert_equal(4, s:slnum) call assert_equal(2, str2nr(expand(''))) " Line-continuation --- 62,68 ---- endfunc func Test_expand_slnum() ! call assert_equal(6, s:slnum) call assert_equal(2, str2nr(expand(''))) " Line-continuation *************** *** 86,91 **** --- 88,104 ---- quit endfunc + func s:sid_test() + return 'works' + endfunc + + func Test_expand_SID() + let sid = expand('') + execute 'let g:sid_result = ' .. sid .. 'sid_test()' + call assert_equal('works', g:sid_result) + endfunc + + " Test for 'wildignore' with expand() func Test_expand_wildignore() set wildignore=*.vim *** ../vim-8.2.1346/src/version.c 2020-08-01 19:23:40.422284128 +0200 --- src/version.c 2020-08-01 20:44:15.916289439 +0200 *************** *** 756,757 **** --- 756,759 ---- { /* Add new patch number below this line */ + /**/ + 1347, /**/ -- hundred-and-one symptoms of being an internet addict: 102. When filling out your driver's license application, you give your IP address. /// 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 ///