Skip to content

Commit

Permalink
patch 8.2.4345: <amatch> is expanded like a file name for DirChangedPre
Browse files Browse the repository at this point in the history
Problem:    <amatch> is expanded like a file name for DirChangedPre.
Solution:   Do not expand <amatch>. (closes #9742)  Also for the User event.
  • Loading branch information
brammool committed Feb 11, 2022
1 parent 14f2312 commit f6246f5
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/autocmd.c
Expand Up @@ -2043,7 +2043,7 @@ apply_autocmds_group(
{
sfname = vim_strsave(fname);
// Don't try expanding FileType, Syntax, FuncUndefined, WindowID,
// ColorScheme, QuickFixCmd* or DirChanged
// ColorScheme, QuickFixCmd*, DirChanged and similar.
if (event == EVENT_FILETYPE
|| event == EVENT_SYNTAX
|| event == EVENT_CMDLINECHANGED
Expand All @@ -2061,7 +2061,9 @@ apply_autocmds_group(
|| event == EVENT_OPTIONSET
|| event == EVENT_QUICKFIXCMDPOST
|| event == EVENT_DIRCHANGED
|| event == EVENT_DIRCHANGEDPRE
|| event == EVENT_MODECHANGED
|| event == EVENT_USER
|| event == EVENT_WINCLOSED)
{
fname = vim_strsave(fname);
Expand Down
12 changes: 10 additions & 2 deletions src/testdir/test_autocmd.vim
Expand Up @@ -1899,6 +1899,14 @@ func Test_autocommand_all_events()
call assert_fails('au! * x bwipe', 'E1155:')
endfunc

func Test_autocmd_user()
au User MyEvent let s:res = [expand("<afile>"), expand("<amatch>")]
doautocmd User MyEvent
call assert_equal(['MyEvent', 'MyEvent'], s:res)
au! User
unlet s:res
endfunc

function s:Before_test_dirchanged()
augroup test_dirchanged
autocmd!
Expand All @@ -1922,11 +1930,11 @@ endfunc

function Test_dirchanged_global()
call s:Before_test_dirchanged()
autocmd test_dirchanged DirChangedPre global call add(s:li, "pre cd " .. v:event.directory)
autocmd test_dirchanged DirChangedPre global call add(s:li, expand("<amatch>") .. " pre cd " .. v:event.directory)
autocmd test_dirchanged DirChanged global call add(s:li, "cd:")
autocmd test_dirchanged DirChanged global call add(s:li, expand("<afile>"))
call chdir(s:dir_foo)
let expected = ["pre cd " .. s:dir_foo, "cd:", s:dir_foo]
let expected = ["global pre cd " .. s:dir_foo, "cd:", s:dir_foo]
call assert_equal(expected, s:li)
call chdir(s:dir_foo)
call assert_equal(expected, s:li)
Expand Down
2 changes: 2 additions & 0 deletions src/version.c
Expand Up @@ -746,6 +746,8 @@ static char *(features[]) =

static int included_patches[] =
{ /* Add new patch number below this line */
/**/
4345,
/**/
4344,
/**/
Expand Down

0 comments on commit f6246f5

Please sign in to comment.