• R/O
  • SSH

vim: Commit

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


Commit MetaInfo

Révision67194006cad88030761f1258a46f7287fdcc3f44 (tree)
l'heure2022-01-16 22:45:03
AuteurBram Moolenaar <Bram@vim....>
CommiterBram Moolenaar

Message de Log

patch 8.2.4107: script context not restored after using <ScriptCmd>

Commit: https://github.com/vim/vim/commit/a9725221ac4650b7e9219bf6e3682826fe2e0096
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Jan 16 13:30:33 2022 +0000

patch 8.2.4107: script context not restored after using <ScriptCmd>
Problem: Script context not restored after using <ScriptCmd>.
Solution: Also restore context when not in a script. (closes https://github.com/vim/vim/issues/9536)
Add the 'c' flag to feedkeys() to be able to test this.

Change Summary

Modification

diff -r 1ebb45dd9232 -r 67194006cad8 runtime/doc/builtin.txt
--- a/runtime/doc/builtin.txt Sun Jan 16 12:45:04 2022 +0100
+++ b/runtime/doc/builtin.txt Sun Jan 16 14:45:03 2022 +0100
@@ -2394,6 +2394,9 @@
23942394 Note that if you manage to call feedkeys() while
23952395 executing commands, thus calling it recursively, then
23962396 all typeahead will be consumed by the last call.
2397+ 'c' Remove any script context when executing, so that
2398+ legacy script syntax applies, "s:var" does not work,
2399+ etc.
23972400 '!' When used with 'x' will not end Insert mode. Can be
23982401 used in a test when a timer is set to exit Insert mode
23992402 a little later. Useful for testing CursorHoldI.
diff -r 1ebb45dd9232 -r 67194006cad8 src/evalfunc.c
--- a/src/evalfunc.c Sun Jan 16 12:45:04 2022 +0100
+++ b/src/evalfunc.c Sun Jan 16 14:45:03 2022 +0100
@@ -3932,6 +3932,7 @@
39323932 char_u nbuf[NUMBUFLEN];
39333933 int typed = FALSE;
39343934 int execute = FALSE;
3935+ int context = FALSE;
39353936 int dangerous = FALSE;
39363937 int lowlevel = FALSE;
39373938 char_u *keys_esc;
@@ -3961,6 +3962,7 @@
39613962 case 't': typed = TRUE; break;
39623963 case 'i': insert = TRUE; break;
39633964 case 'x': execute = TRUE; break;
3965+ case 'c': context = TRUE; break;
39643966 case '!': dangerous = TRUE; break;
39653967 case 'L': lowlevel = TRUE; break;
39663968 }
@@ -4007,11 +4009,19 @@
40074009
40084010 if (execute)
40094011 {
4010- int save_msg_scroll = msg_scroll;
4012+ int save_msg_scroll = msg_scroll;
4013+ sctx_T save_sctx;
40114014
40124015 // Avoid a 1 second delay when the keys start Insert mode.
40134016 msg_scroll = FALSE;
40144017
4018+ if (context)
4019+ {
4020+ save_sctx = current_sctx;
4021+ current_sctx.sc_sid = 0;
4022+ current_sctx.sc_version = 0;
4023+ }
4024+
40154025 if (!dangerous)
40164026 {
40174027 ++ex_normal_busy;
@@ -4025,6 +4035,9 @@
40254035 }
40264036
40274037 msg_scroll |= save_msg_scroll;
4038+
4039+ if (context)
4040+ current_sctx = save_sctx;
40284041 }
40294042 }
40304043 }
diff -r 1ebb45dd9232 -r 67194006cad8 src/getchar.c
--- a/src/getchar.c Sun Jan 16 12:45:04 2022 +0100
+++ b/src/getchar.c Sun Jan 16 14:45:03 2022 +0100
@@ -3797,7 +3797,7 @@
37973797 }
37983798 }
37993799 else
3800- ga_append(&line_ga, (char)c1);
3800+ ga_append(&line_ga, c1);
38013801
38023802 cmod = 0;
38033803 }
@@ -3815,7 +3815,7 @@
38153815 {
38163816 int res;
38173817 #ifdef FEAT_EVAL
3818- sctx_T save_current_sctx = {0, 0, 0, 0};
3818+ sctx_T save_current_sctx = {-1, 0, 0, 0};
38193819
38203820 if (key == K_SCRIPT_COMMAND && last_used_map != NULL)
38213821 {
@@ -3827,7 +3827,7 @@
38273827 res = do_cmdline(NULL, getcmdkeycmd, NULL, flags);
38283828
38293829 #ifdef FEAT_EVAL
3830- if (save_current_sctx.sc_sid > 0)
3830+ if (save_current_sctx.sc_sid >= 0)
38313831 current_sctx = save_current_sctx;
38323832 #endif
38333833
diff -r 1ebb45dd9232 -r 67194006cad8 src/testdir/test_mapping.vim
--- a/src/testdir/test_mapping.vim Sun Jan 16 12:45:04 2022 +0100
+++ b/src/testdir/test_mapping.vim Sun Jan 16 14:45:03 2022 +0100
@@ -4,6 +4,7 @@
44 source check.vim
55 source screendump.vim
66 source term_util.vim
7+source vim9.vim
78
89 func Test_abbreviation()
910 " abbreviation with 0x80 should work
@@ -1397,6 +1398,19 @@
13971398 ounmap i-
13981399 endfunc
13991400
1401+func Test_map_script_cmd_restore()
1402+ let lines =<< trim END
1403+ vim9script
1404+ nnoremap <F3> <ScriptCmd>eval 1 + 2<CR>
1405+ END
1406+ call CheckScriptSuccess(lines)
1407+ call feedkeys("\<F3>:let g:result = 3+4\<CR>", 'xtc')
1408+ call assert_equal(7, g:result)
1409+
1410+ nunmap <F3>
1411+ unlet g:result
1412+endfunc
1413+
14001414 " Test for using <script> with a map to remap characters in rhs
14011415 func Test_script_local_remap()
14021416 new
diff -r 1ebb45dd9232 -r 67194006cad8 src/version.c
--- a/src/version.c Sun Jan 16 12:45:04 2022 +0100
+++ b/src/version.c Sun Jan 16 14:45:03 2022 +0100
@@ -751,6 +751,8 @@
751751 static int included_patches[] =
752752 { /* Add new patch number below this line */
753753 /**/
754+ 4107,
755+/**/
754756 4106,
755757 /**/
756758 4105,
Afficher sur ancien navigateur de dépôt.