To: vim_dev@googlegroups.com Subject: Patch 9.0.1130 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 9.0.1130 Problem: Unexpected output when autoloading a script for an interactive operation. Solution: Reset "KeyTyped" while loading a script and when handling a nested function. (closes #11773) Files: src/scriptfile.c, src/vim9compile.c, src/testdir/test_vim9_func.vim, src/testdir/dumps/Test_keytyped_in_nested_func.dump *** ../vim-9.0.1129/src/scriptfile.c 2022-11-02 13:30:37.538314551 +0000 --- src/scriptfile.c 2023-01-02 12:42:24.588306555 +0000 *************** *** 1334,1343 **** * When "ret_sid" is not NULL and we loaded the script before, don't load it * again. * ! * The 'eap' argument is used when sourcing lines from a buffer instead of a * file. * ! * If 'clearvars' is TRUE, then for scripts which are loaded more than * once, clear all the functions and variables previously defined in that * script. * --- 1334,1343 ---- * When "ret_sid" is not NULL and we loaded the script before, don't load it * again. * ! * The "eap" argument is used when sourcing lines from a buffer instead of a * file. * ! * If "clearvars" is TRUE, then for scripts which are loaded more than * once, clear all the functions and variables previously defined in that * script. * *************** *** 1538,1543 **** --- 1538,1544 ---- current_sctx.sc_version = SCRIPT_VERSION_VIM9; else current_sctx.sc_version = 1; // default script version + current_sctx.sc_lnum = 0; #ifdef FEAT_EVAL # ifdef FEAT_PROFILE *************** *** 1549,1555 **** // Also starts profiling timer for nested script. save_funccal(&funccalp_entry); ! current_sctx.sc_lnum = 0; // Check if this script was sourced before to find its SID. // Always use a new sequence number. --- 1550,1559 ---- // Also starts profiling timer for nested script. save_funccal(&funccalp_entry); ! // Reset "KeyTyped" to avoid some commands thinking they are invoked ! // interactively. E.g. defining a function would output indent. ! int save_KeyTyped = KeyTyped; ! KeyTyped = FALSE; // Check if this script was sourced before to find its SID. // Always use a new sequence number. *************** *** 1765,1770 **** --- 1769,1775 ---- # endif #endif current_sctx = save_current_sctx; + KeyTyped = save_KeyTyped; if (cookie.fp != NULL) fclose(cookie.fp); *** ../vim-9.0.1129/src/vim9compile.c 2023-01-01 19:53:26.582445815 +0000 --- src/vim9compile.c 2023-01-02 13:04:23.477773408 +0000 *************** *** 987,993 **** --- 987,1000 ---- goto theend; } + // Make sure "KeyTyped" is not set, it may cause indent to be written. + int save_KeyTyped = KeyTyped; + KeyTyped = FALSE; + ufunc = define_function(eap, lambda_name, lines_to_free, FALSE); + + KeyTyped = save_KeyTyped; + if (ufunc == NULL) { r = eap->skip ? OK : FAIL; *** ../vim-9.0.1129/src/testdir/test_vim9_func.vim 2022-12-31 14:01:20.830671637 +0000 --- src/testdir/test_vim9_func.vim 2023-01-02 13:02:10.481936302 +0000 *************** *** 4413,4418 **** --- 4413,4460 ---- delfunc g:Ttwo enddef + func Test_keytyped_in_nested_function() + CheckRunVimInTerminal + + call Run_Test_keytyped_in_nested_function() + endfunc + + def Run_Test_keytyped_in_nested_function() + var lines =<< trim END + vim9script + autocmd CmdlineEnter * sample#Init() + + exe 'set rtp=' .. getcwd() .. '/Xrtpdir' + END + writefile(lines, 'Xkeytyped', 'D') + + var dir = 'Xrtpdir/autoload' + mkdir(dir, 'pR') + + lines =<< trim END + vim9script + export def Init(): void + cnoremap " Quote('"') + enddef + def Quote(str: string): string + def InPair(): number + return 0 + enddef + return str + enddef + END + writefile(lines, dir .. '/sample.vim') + + var buf = g:RunVimInTerminal('-S Xkeytyped', {rows: 6}) + + term_sendkeys(buf, ':"') + g:VerifyScreenDump(buf, 'Test_keytyped_in_nested_func', {}) + + # clean up + term_sendkeys(buf, "\") + g:StopVimInTerminal(buf) + enddef + " The following messes up syntax highlight, keep near the end. if has('python3') def Test_python3_command() *** ../vim-9.0.1129/src/testdir/dumps/Test_keytyped_in_nested_func.dump 2023-01-02 13:09:14.461438605 +0000 --- src/testdir/dumps/Test_keytyped_in_nested_func.dump 2023-01-02 13:02:13.397932645 +0000 *************** *** 0 **** --- 1,6 ---- + | +0&#ffffff0@74 + |~+0#4040ff13&| @73 + |~| @73 + |~| @73 + |~| @73 + |:+0#0000000&|"> @72 *** ../vim-9.0.1129/src/version.c 2023-01-02 11:59:22.352412451 +0000 --- src/version.c 2023-01-02 12:41:09.484589125 +0000 *************** *** 697,698 **** --- 697,700 ---- { /* Add new patch number below this line */ + /**/ + 1130, /**/ -- Communication is one of the most compli..., eh, well, it's hard. You know what I mean. Not? /// 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 ///