Mirror of the Vim source from https://github.com/vim/vim
Révision | 5daca8504c633bdc2e1a3138ddf99c792f8ea0bf (tree) |
---|---|
l'heure | 2020-08-02 04:00:04 |
Auteur | Bram Moolenaar <Bram@vim....> |
Commiter | Bram Moolenaar |
patch 8.2.1347: cannot easily get the script ID
Commit: https://github.com/vim/vim/commit/909443028b57d7514ce3c71f00e9d808f2126b4f
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Aug 1 20:45:11 2020 +0200
@@ -1167,6 +1167,10 @@ | ||
1167 | 1167 | the script it was defined in. This makes it possible that the command calls a |
1168 | 1168 | local function or uses a local mapping. |
1169 | 1169 | |
1170 | +In case the value is used in a context where <SID> cannot be correctly | |
1171 | +expanded, use the expand() function: > | |
1172 | + let &includexpr = expand('<SID>') .. 'My_includeexpr()' | |
1173 | + | |
1170 | 1174 | Otherwise, using "<SID>" outside of a script context is an error. |
1171 | 1175 | |
1172 | 1176 | If you need to get the script number to use in a complicated script, you can |
@@ -8302,9 +8302,11 @@ | ||
8302 | 8302 | #define SPEC_AMATCH (SPEC_ABUF + 1) |
8303 | 8303 | "<sflnum>", // script file line number |
8304 | 8304 | #define SPEC_SFLNUM (SPEC_AMATCH + 1) |
8305 | + "<SID>", // script ID: <SNR>123_ | |
8306 | +#define SPEC_SID (SPEC_SFLNUM + 1) | |
8305 | 8307 | #ifdef FEAT_CLIENTSERVER |
8306 | 8308 | "<client>" |
8307 | -# define SPEC_CLIENT (SPEC_SFLNUM + 1) | |
8309 | +# define SPEC_CLIENT (SPEC_SID + 1) | |
8308 | 8310 | #endif |
8309 | 8311 | }; |
8310 | 8312 |
@@ -8581,6 +8583,16 @@ | ||
8581 | 8583 | break; |
8582 | 8584 | #endif |
8583 | 8585 | |
8586 | + case SPEC_SID: | |
8587 | + if (current_sctx.sc_sid <= 0) | |
8588 | + { | |
8589 | + *errormsg = _(e_usingsid); | |
8590 | + return NULL; | |
8591 | + } | |
8592 | + sprintf((char *)strbuf, "<SNR>%d_", current_sctx.sc_sid); | |
8593 | + result = strbuf; | |
8594 | + break; | |
8595 | + | |
8584 | 8596 | #ifdef FEAT_CLIENTSERVER |
8585 | 8597 | case SPEC_CLIENT: // Source of last submitted input |
8586 | 8598 | sprintf((char *)strbuf, PRINTF_HEX_LONG_U, |
@@ -1,5 +1,7 @@ | ||
1 | 1 | " Tests for expand() |
2 | 2 | |
3 | +source shared.vim | |
4 | + | |
3 | 5 | let s:sfile = expand('<sfile>') |
4 | 6 | let s:slnum = str2nr(expand('<slnum>')) |
5 | 7 | let s:sflnum = str2nr(expand('<sflnum>')) |
@@ -18,20 +20,20 @@ | ||
18 | 20 | |
19 | 21 | " This test depends on the location in the test file, put it first. |
20 | 22 | func Test_expand_sflnum() |
21 | - call assert_equal(5, s:sflnum) | |
22 | - call assert_equal(22, str2nr(expand('<sflnum>'))) | |
23 | + call assert_equal(7, s:sflnum) | |
24 | + call assert_equal(24, str2nr(expand('<sflnum>'))) | |
23 | 25 | |
24 | 26 | " Line-continuation |
25 | 27 | call assert_equal( |
26 | - \ 25, | |
28 | + \ 27, | |
27 | 29 | \ str2nr(expand('<sflnum>'))) |
28 | 30 | |
29 | 31 | " Call in script-local function |
30 | - call assert_equal(16, s:expand_sflnum()) | |
32 | + call assert_equal(18, s:expand_sflnum()) | |
31 | 33 | |
32 | 34 | " Call in command |
33 | 35 | command Flnum echo expand('<sflnum>') |
34 | - call assert_equal(34, str2nr(trim(execute('Flnum')))) | |
36 | + call assert_equal(36, str2nr(trim(execute('Flnum')))) | |
35 | 37 | delcommand Flnum |
36 | 38 | endfunc |
37 | 39 |
@@ -60,7 +62,7 @@ | ||
60 | 62 | endfunc |
61 | 63 | |
62 | 64 | func Test_expand_slnum() |
63 | - call assert_equal(4, s:slnum) | |
65 | + call assert_equal(6, s:slnum) | |
64 | 66 | call assert_equal(2, str2nr(expand('<slnum>'))) |
65 | 67 | |
66 | 68 | " Line-continuation |
@@ -86,6 +88,17 @@ | ||
86 | 88 | quit |
87 | 89 | endfunc |
88 | 90 | |
91 | +func s:sid_test() | |
92 | + return 'works' | |
93 | +endfunc | |
94 | + | |
95 | +func Test_expand_SID() | |
96 | + let sid = expand('<SID>') | |
97 | + execute 'let g:sid_result = ' .. sid .. 'sid_test()' | |
98 | + call assert_equal('works', g:sid_result) | |
99 | +endfunc | |
100 | + | |
101 | + | |
89 | 102 | " Test for 'wildignore' with expand() |
90 | 103 | func Test_expand_wildignore() |
91 | 104 | set wildignore=*.vim |
@@ -755,6 +755,8 @@ | ||
755 | 755 | static int included_patches[] = |
756 | 756 | { /* Add new patch number below this line */ |
757 | 757 | /**/ |
758 | + 1347, | |
759 | +/**/ | |
758 | 760 | 1346, |
759 | 761 | /**/ |
760 | 762 | 1345, |