Mercurial > vim
diff src/autocmd.c @ 28978:3c3bdb8069f5 v8.2.5011
patch 8.2.5011: Replacing an autocommand requires several lines
Commit: https://github.com/vim/vim/commit/971f6825ee845828bd5c8869487928a3f32cd467
Author: Yegappan Lakshmanan <yegappan@yahoo.com>
Date: Tue May 24 11:40:11 2022 +0100
patch 8.2.5011: Replacing an autocommand requires several lines
Problem: Replacing an autocommand requires several lines.
Solution: Add the "replace" flag to autocmd_add(). (Yegappan Lakshmanan,
closes #10473)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Tue, 24 May 2022 12:45:05 +0200 |
parents | c5862dfaf0bd |
children | aadeddf38d9b |
line wrap: on
line diff
--- a/src/autocmd.c +++ b/src/autocmd.c @@ -2766,6 +2766,7 @@ autocmd_add_or_delete(typval_T *argvars, 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, 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, } 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;