• R/O
  • SSH

vim: コミット

Mirror of the Vim source from https://github.com/vim/vim


コミットメタ情報

リビジョン5daca8504c633bdc2e1a3138ddf99c792f8ea0bf (tree)
日時2020-08-02 04:00:04
作者Bram Moolenaar <Bram@vim....>
コミッター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

patch 8.2.1347: cannot easily get the script ID
Problem: Cannot easily get the script ID.
Solution: Support expand('<SID>').

変更サマリ

差分

diff -r 6015f5f423ba -r 5daca8504c63 runtime/doc/map.txt
--- a/runtime/doc/map.txt Sat Aug 01 19:30:04 2020 +0200
+++ b/runtime/doc/map.txt Sat Aug 01 21:00:04 2020 +0200
@@ -1167,6 +1167,10 @@
11671167 the script it was defined in. This makes it possible that the command calls a
11681168 local function or uses a local mapping.
11691169
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+
11701174 Otherwise, using "<SID>" outside of a script context is an error.
11711175
11721176 If you need to get the script number to use in a complicated script, you can
diff -r 6015f5f423ba -r 5daca8504c63 src/ex_docmd.c
--- a/src/ex_docmd.c Sat Aug 01 19:30:04 2020 +0200
+++ b/src/ex_docmd.c Sat Aug 01 21:00:04 2020 +0200
@@ -8302,9 +8302,11 @@
83028302 #define SPEC_AMATCH (SPEC_ABUF + 1)
83038303 "<sflnum>", // script file line number
83048304 #define SPEC_SFLNUM (SPEC_AMATCH + 1)
8305+ "<SID>", // script ID: <SNR>123_
8306+#define SPEC_SID (SPEC_SFLNUM + 1)
83058307 #ifdef FEAT_CLIENTSERVER
83068308 "<client>"
8307-# define SPEC_CLIENT (SPEC_SFLNUM + 1)
8309+# define SPEC_CLIENT (SPEC_SID + 1)
83088310 #endif
83098311 };
83108312
@@ -8581,6 +8583,16 @@
85818583 break;
85828584 #endif
85838585
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+
85848596 #ifdef FEAT_CLIENTSERVER
85858597 case SPEC_CLIENT: // Source of last submitted input
85868598 sprintf((char *)strbuf, PRINTF_HEX_LONG_U,
diff -r 6015f5f423ba -r 5daca8504c63 src/testdir/test_expand_func.vim
--- a/src/testdir/test_expand_func.vim Sat Aug 01 19:30:04 2020 +0200
+++ b/src/testdir/test_expand_func.vim Sat Aug 01 21:00:04 2020 +0200
@@ -1,5 +1,7 @@
11 " Tests for expand()
22
3+source shared.vim
4+
35 let s:sfile = expand('<sfile>')
46 let s:slnum = str2nr(expand('<slnum>'))
57 let s:sflnum = str2nr(expand('<sflnum>'))
@@ -18,20 +20,20 @@
1820
1921 " This test depends on the location in the test file, put it first.
2022 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>')))
2325
2426 " Line-continuation
2527 call assert_equal(
26- \ 25,
28+ \ 27,
2729 \ str2nr(expand('<sflnum>')))
2830
2931 " Call in script-local function
30- call assert_equal(16, s:expand_sflnum())
32+ call assert_equal(18, s:expand_sflnum())
3133
3234 " Call in command
3335 command Flnum echo expand('<sflnum>')
34- call assert_equal(34, str2nr(trim(execute('Flnum'))))
36+ call assert_equal(36, str2nr(trim(execute('Flnum'))))
3537 delcommand Flnum
3638 endfunc
3739
@@ -60,7 +62,7 @@
6062 endfunc
6163
6264 func Test_expand_slnum()
63- call assert_equal(4, s:slnum)
65+ call assert_equal(6, s:slnum)
6466 call assert_equal(2, str2nr(expand('<slnum>')))
6567
6668 " Line-continuation
@@ -86,6 +88,17 @@
8688 quit
8789 endfunc
8890
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+
89102 " Test for 'wildignore' with expand()
90103 func Test_expand_wildignore()
91104 set wildignore=*.vim
diff -r 6015f5f423ba -r 5daca8504c63 src/version.c
--- a/src/version.c Sat Aug 01 19:30:04 2020 +0200
+++ b/src/version.c Sat Aug 01 21:00:04 2020 +0200
@@ -755,6 +755,8 @@
755755 static int included_patches[] =
756756 { /* Add new patch number below this line */
757757 /**/
758+ 1347,
759+/**/
758760 1346,
759761 /**/
760762 1345,
旧リポジトリブラウザで表示