forked from aniani/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 #3739)
This commit is contained in:
@@ -925,6 +925,12 @@ ShellFilterPost After executing a shell command with
|
|||||||
*SourcePre*
|
*SourcePre*
|
||||||
SourcePre Before sourcing a Vim script. |:source|
|
SourcePre Before sourcing a Vim script. |:source|
|
||||||
<afile> is the name of the file being sourced.
|
<afile> is the name of the file being sourced.
|
||||||
|
*SourcePost*
|
||||||
|
SourcePost After sourcing a Vim script. |:source|
|
||||||
|
<afile> is the name of the file being sourced.
|
||||||
|
Not triggered when sourcing was interrupted.
|
||||||
|
Also triggered after a SourceCmd autocommand
|
||||||
|
was triggered.
|
||||||
*SourceCmd*
|
*SourceCmd*
|
||||||
SourceCmd When sourcing a Vim script. |:source|
|
SourceCmd When sourcing a Vim script. |:source|
|
||||||
<afile> is the name of the file being sourced.
|
<afile> is the name of the file being sourced.
|
||||||
|
@@ -4360,6 +4360,7 @@ do_source(
|
|||||||
#ifdef FEAT_PROFILE
|
#ifdef FEAT_PROFILE
|
||||||
proftime_T wait_start;
|
proftime_T wait_start;
|
||||||
#endif
|
#endif
|
||||||
|
int trigger_source_post = FALSE;
|
||||||
|
|
||||||
p = expand_env_save(fname);
|
p = expand_env_save(fname);
|
||||||
if (p == NULL)
|
if (p == NULL)
|
||||||
@@ -4384,6 +4385,10 @@ do_source(
|
|||||||
#else
|
#else
|
||||||
retval = OK;
|
retval = OK;
|
||||||
#endif
|
#endif
|
||||||
|
if (retval == OK)
|
||||||
|
// Apply SourcePost autocommands.
|
||||||
|
apply_autocmds(EVENT_SOURCEPOST, fname_exp, fname_exp,
|
||||||
|
FALSE, curbuf);
|
||||||
goto theend;
|
goto theend;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -4653,6 +4658,9 @@ do_source(
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
if (!got_int)
|
||||||
|
trigger_source_post = TRUE;
|
||||||
|
|
||||||
#ifdef FEAT_EVAL
|
#ifdef FEAT_EVAL
|
||||||
/*
|
/*
|
||||||
* After a "finish" in debug mode, need to break at first command of next
|
* After a "finish" in debug mode, need to break at first command of next
|
||||||
@@ -4679,6 +4687,10 @@ almosttheend:
|
|||||||
convert_setup(&cookie.conv, NULL, NULL);
|
convert_setup(&cookie.conv, NULL, NULL);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
if (trigger_source_post)
|
||||||
|
apply_autocmds(EVENT_SOURCEPOST, si->sn_name, si->sn_name,
|
||||||
|
FALSE, curbuf);
|
||||||
|
|
||||||
theend:
|
theend:
|
||||||
vim_free(fname_exp);
|
vim_free(fname_exp);
|
||||||
return retval;
|
return retval;
|
||||||
|
@@ -7795,8 +7795,9 @@ static struct event_name
|
|||||||
{"SessionLoadPost", EVENT_SESSIONLOADPOST},
|
{"SessionLoadPost", EVENT_SESSIONLOADPOST},
|
||||||
{"ShellCmdPost", EVENT_SHELLCMDPOST},
|
{"ShellCmdPost", EVENT_SHELLCMDPOST},
|
||||||
{"ShellFilterPost", EVENT_SHELLFILTERPOST},
|
{"ShellFilterPost", EVENT_SHELLFILTERPOST},
|
||||||
{"SourcePre", EVENT_SOURCEPRE},
|
|
||||||
{"SourceCmd", EVENT_SOURCECMD},
|
{"SourceCmd", EVENT_SOURCECMD},
|
||||||
|
{"SourcePre", EVENT_SOURCEPRE},
|
||||||
|
{"SourcePost", EVENT_SOURCEPOST},
|
||||||
{"SpellFileMissing",EVENT_SPELLFILEMISSING},
|
{"SpellFileMissing",EVENT_SPELLFILEMISSING},
|
||||||
{"StdinReadPost", EVENT_STDINREADPOST},
|
{"StdinReadPost", EVENT_STDINREADPOST},
|
||||||
{"StdinReadPre", EVENT_STDINREADPRE},
|
{"StdinReadPre", EVENT_STDINREADPRE},
|
||||||
|
@@ -222,6 +222,7 @@ NEW_TESTS = \
|
|||||||
test_signs \
|
test_signs \
|
||||||
test_smartindent \
|
test_smartindent \
|
||||||
test_sort \
|
test_sort \
|
||||||
|
test_source \
|
||||||
test_source_utf8 \
|
test_source_utf8 \
|
||||||
test_spell \
|
test_spell \
|
||||||
test_startup \
|
test_startup \
|
||||||
@@ -376,6 +377,7 @@ NEW_TESTS_RES = \
|
|||||||
test_shortpathname.res \
|
test_shortpathname.res \
|
||||||
test_signs.res \
|
test_signs.res \
|
||||||
test_smartindent.res \
|
test_smartindent.res \
|
||||||
|
test_source.res \
|
||||||
test_spell.res \
|
test_spell.res \
|
||||||
test_startup.res \
|
test_startup.res \
|
||||||
test_stat.res \
|
test_stat.res \
|
||||||
|
38
src/testdir/test_source.vim
Normal file
38
src/testdir/test_source.vim
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
" Tests for the :source command.
|
||||||
|
|
||||||
|
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('<afile>')
|
||||||
|
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
|
@@ -795,6 +795,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
729,
|
||||||
/**/
|
/**/
|
||||||
728,
|
728,
|
||||||
/**/
|
/**/
|
||||||
|
@@ -1324,6 +1324,7 @@ enum auto_event
|
|||||||
EVENT_SHELLFILTERPOST, // after ":1,2!cmd", ":w !cmd", ":r !cmd".
|
EVENT_SHELLFILTERPOST, // after ":1,2!cmd", ":w !cmd", ":r !cmd".
|
||||||
EVENT_SOURCECMD, // sourcing a Vim script using command
|
EVENT_SOURCECMD, // sourcing a Vim script using command
|
||||||
EVENT_SOURCEPRE, // before sourcing a Vim script
|
EVENT_SOURCEPRE, // before sourcing a Vim script
|
||||||
|
EVENT_SOURCEPOST, // after sourcing a Vim script
|
||||||
EVENT_SPELLFILEMISSING, // spell file missing
|
EVENT_SPELLFILEMISSING, // spell file missing
|
||||||
EVENT_STDINREADPOST, // after reading from stdin
|
EVENT_STDINREADPOST, // after reading from stdin
|
||||||
EVENT_STDINREADPRE, // before reading from stdin
|
EVENT_STDINREADPRE, // before reading from stdin
|
||||||
|
Reference in New Issue
Block a user