summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorYegappan Lakshmanan <yegappan@yahoo.com>2022-05-24 11:40:11 +0100
committerBram Moolenaar <Bram@vim.org>2022-05-24 11:40:11 +0100
commit971f6825ee845828bd5c8869487928a3f32cd467 (patch)
tree05a3c033c0ed013b0b4f80feb4d163aa1d2f1e14 /src
parentc9a431c7638ecebb6f2cb3eabd0e1b2b5e269c1e (diff)
patch 8.2.5011: Replacing an autocommand requires several linesv8.2.5011
Problem: Replacing an autocommand requires several lines. Solution: Add the "replace" flag to autocmd_add(). (Yegappan Lakshmanan, closes #10473)
Diffstat (limited to 'src')
-rw-r--r--src/autocmd.c8
-rw-r--r--src/testdir/test_autocmd.vim12
-rw-r--r--src/version.c2
3 files changed, 20 insertions, 2 deletions
diff --git a/src/autocmd.c b/src/autocmd.c
index 5bcf3ab561..c9733ba5d3 100644
--- a/src/autocmd.c
+++ b/src/autocmd.c
@@ -2766,6 +2766,7 @@ autocmd_add_or_delete(typval_T *argvars, typval_T *rettv, int delete)
char_u *end;
int once;
int nested;
+ int replace; // replace the cmd for a group/event
int retval = VVAL_TRUE;
int save_augroup = current_augroup;
@@ -2877,6 +2878,9 @@ autocmd_add_or_delete(typval_T *argvars, typval_T *rettv, int delete)
once = dict_get_bool(event_dict, (char_u *)"once", FALSE);
nested = dict_get_bool(event_dict, (char_u *)"nested", FALSE);
+ // if 'replace' is true, then remove all the commands associated with
+ // this autocmd event/group and add the new command.
+ replace = dict_get_bool(event_dict, (char_u *)"replace", FALSE);
cmd = dict_get_string(event_dict, (char_u *)"cmd", TRUE);
if (cmd == NULL)
@@ -2903,8 +2907,8 @@ autocmd_add_or_delete(typval_T *argvars, typval_T *rettv, int delete)
}
else
{
- if (do_autocmd_event(event, pat, once, nested, cmd, delete, group,
- 0) == FAIL)
+ if (do_autocmd_event(event, pat, once, nested, cmd,
+ delete | replace, group, 0) == FAIL)
{
retval = VVAL_FALSE;
break;
diff --git a/src/testdir/test_autocmd.vim b/src/testdir/test_autocmd.vim
index c6c5f2172c..e3df115a6d 100644
--- a/src/testdir/test_autocmd.vim
+++ b/src/testdir/test_autocmd.vim
@@ -3413,6 +3413,18 @@ func Test_autocmd_add()
\ nested: v:false, once: v:false, event: 'BufHidden'}],
\ autocmd_get(#{group: 'TestAcSet'}))
+ " Test for replacing a cmd for an event in a group
+ call autocmd_delete([#{group: 'TestAcSet'}])
+ call autocmd_add([#{replace: v:true, group: 'TestAcSet', event: 'BufEnter',
+ \ pattern: '*.py', cmd: 'echo "bufenter"'}])
+ call autocmd_add([#{replace: v:true, group: 'TestAcSet', event: 'BufEnter',
+ \ pattern: '*.py', cmd: 'echo "bufenter"'}])
+ call assert_equal([
+ \ #{cmd: 'echo "bufenter"', group: 'TestAcSet', pattern: '*.py',
+ \ nested: v:false, once: v:false, event: 'BufEnter'}],
+ \ autocmd_get(#{group: 'TestAcSet'}))
+
+ " Test for adding a command for an unsupported autocmd event
let l = [#{group: 'TestAcSet', event: 'abc', pattern: '*.sh',
\ cmd: 'echo "bufadd"'}]
call assert_fails('call autocmd_add(l)', 'E216:')
diff --git a/src/version.c b/src/version.c
index 110535c9b5..5ea047ac37 100644
--- a/src/version.c
+++ b/src/version.c
@@ -735,6 +735,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 5011,
+/**/
5010,
/**/
5009,