From aa681df25fc1b1c22182c8150e53952fefa63e10 Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Wed, 22 May 2019 23:44:57 -0400 Subject: vim-patch:8.1.0729: there is a SourcePre autocommand event but not a SourcePost Problem: There is a SourcePre autocommand event but not a SourcePost. Solution: Add the SourcePost autocommand event. (closes vim/vim#3739) https://github.com/vim/vim/commit/2b6185287adf53343ed5f49e967ae402c64063e4 --- src/nvim/auevents.lua | 1 + src/nvim/ex_cmds2.c | 13 +++++++++++++ src/nvim/testdir/test_source.vim | 37 +++++++++++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+) (limited to 'src') diff --git a/src/nvim/auevents.lua b/src/nvim/auevents.lua index ef528f72b8..12fc8fd02a 100644 --- a/src/nvim/auevents.lua +++ b/src/nvim/auevents.lua @@ -77,6 +77,7 @@ return { 'Signal', -- after nvim process received a signal 'SourceCmd', -- sourcing a Vim script using command 'SourcePre', -- before sourcing a Vim script + 'SourcePost', -- after sourcing a Vim script 'SpellFileMissing', -- spell file missing 'StdinReadPost', -- after reading from stdin 'StdinReadPre', -- before reading from stdin diff --git a/src/nvim/ex_cmds2.c b/src/nvim/ex_cmds2.c index 2fb818760a..71c9290027 100644 --- a/src/nvim/ex_cmds2.c +++ b/src/nvim/ex_cmds2.c @@ -3039,6 +3039,7 @@ int do_source(char_u *fname, int check_other, int is_vimrc) int save_debug_break_level = debug_break_level; scriptitem_T *si = NULL; proftime_T wait_start; + bool trigger_source_post = false; p = expand_env_save(fname); if (p == NULL) { @@ -3059,6 +3060,10 @@ int do_source(char_u *fname, int check_other, int is_vimrc) && apply_autocmds(EVENT_SOURCECMD, fname_exp, fname_exp, false, curbuf)) { retval = aborting() ? FAIL : OK; + if (retval == OK) { + // Apply SourcePost autocommands. + apply_autocmds(EVENT_SOURCEPOST, fname_exp, fname_exp, false, curbuf); + } goto theend; } @@ -3261,6 +3266,10 @@ int do_source(char_u *fname, int check_other, int is_vimrc) time_pop(rel_time); } + if (!got_int) { + trigger_source_post = true; + } + // After a "finish" in debug mode, need to break at first command of next // sourced file. if (save_debug_break_level > ex_nesting_level @@ -3278,6 +3287,10 @@ int do_source(char_u *fname, int check_other, int is_vimrc) xfree(firstline); convert_setup(&cookie.conv, NULL, NULL); + if (trigger_source_post) { + apply_autocmds(EVENT_SOURCEPOST, si->sn_name, si->sn_name, false, curbuf); + } + theend: xfree(fname_exp); return retval; diff --git a/src/nvim/testdir/test_source.vim b/src/nvim/testdir/test_source.vim index 42ac0c4d0f..697b552df4 100644 --- a/src/nvim/testdir/test_source.vim +++ b/src/nvim/testdir/test_source.vim @@ -8,3 +8,40 @@ func Test_source_sandbox() call assert_fails('sandbox source! Xsourcehello', 'E48:') bwipe! endfunc + +func Test_source_autocmd() + call writefile([ + \ 'let did_source = 1', + \ ], 'Xsourced') + au SourcePre *source* let did_source_pre = 1 + au SourcePost *source* let did_source_post = 1 + + source Xsourced + + call assert_equal(g:did_source, 1) + call assert_equal(g:did_source_pre, 1) + call assert_equal(g:did_source_post, 1) + + call delete('Xsourced') + au! SourcePre + au! SourcePost + unlet g:did_source + unlet g:did_source_pre + unlet g:did_source_post +endfunc + +func Test_source_cmd() + au SourceCmd *source* let did_source = expand('') + au SourcePre *source* let did_source_pre = 2 + au SourcePost *source* let did_source_post = 2 + + source Xsourced + + call assert_equal(g:did_source, 'Xsourced') + call assert_false(exists('g:did_source_pre')) + call assert_equal(g:did_source_post, 2) + + au! SourceCmd + au! SourcePre + au! SourcePost +endfunc -- cgit From fdfdc0a228b896a3ce606fb523f5677092490dcc Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Wed, 17 Jul 2019 20:24:35 -0400 Subject: vim-patch:8.1.0732: cannot build without the eval feature Problem: Cannot build without the eval feature. Solution: Make a copy of the sourced file name. https://github.com/vim/vim/commit/ea56e167c87352f07a77d3661425e336817a7141 --- src/nvim/ex_cmds2.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/nvim/ex_cmds2.c b/src/nvim/ex_cmds2.c index 71c9290027..c092036ce9 100644 --- a/src/nvim/ex_cmds2.c +++ b/src/nvim/ex_cmds2.c @@ -3186,7 +3186,7 @@ int do_source(char_u *fname, int check_other, int is_vimrc) } si = &SCRIPT_ITEM(current_SID); si->sn_name = fname_exp; - fname_exp = NULL; + fname_exp = vim_strsave(si->sn_name); // used for autocmd if (file_id_ok) { si->file_id_valid = true; si->file_id = file_id; @@ -3288,7 +3288,7 @@ int do_source(char_u *fname, int check_other, int is_vimrc) convert_setup(&cookie.conv, NULL, NULL); if (trigger_source_post) { - apply_autocmds(EVENT_SOURCEPOST, si->sn_name, si->sn_name, false, curbuf); + apply_autocmds(EVENT_SOURCEPOST, fname_exp, fname_exp, false, curbuf); } theend: -- cgit