Skip to content

Commit f2c4c39

Browse files
committed
patch 7.4.2117
Problem: Deleting an augroup that still has autocmds does not give a warning. The next defined augroup takes its place. Solution: Give a warning and prevent the index being used for another group name.
1 parent c73e447 commit f2c4c39

3 files changed

Lines changed: 62 additions & 6 deletions

File tree

src/fileio.c

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7758,6 +7758,7 @@ static AutoPatCmd *active_apc_list = NULL; /* stack of active autocommands */
77587758
*/
77597759
static garray_T augroups = {0, 0, sizeof(char_u *), 10, NULL};
77607760
#define AUGROUP_NAME(i) (((char_u **)augroups.ga_data)[i])
7761+
static char_u *deleted_augroup = NULL;
77617762

77627763
/*
77637764
* The ID of the current group. Group 0 is the default one.
@@ -7812,7 +7813,7 @@ show_autocmd(AutoPat *ap, event_T event)
78127813
if (ap->group != AUGROUP_DEFAULT)
78137814
{
78147815
if (AUGROUP_NAME(ap->group) == NULL)
7815-
msg_puts_attr((char_u *)_("--Deleted--"), hl_attr(HLF_E));
7816+
msg_puts_attr(deleted_augroup, hl_attr(HLF_E));
78167817
else
78177818
msg_puts_attr(AUGROUP_NAME(ap->group), hl_attr(HLF_T));
78187819
msg_puts((char_u *)" ");
@@ -8009,8 +8010,31 @@ au_del_group(char_u *name)
80098010
EMSG2(_("E367: No such group: \"%s\""), name);
80108011
else
80118012
{
8013+
event_T event;
8014+
AutoPat *ap;
8015+
int in_use = FALSE;
8016+
8017+
for (event = (event_T)0; (int)event < (int)NUM_EVENTS;
8018+
event = (event_T)((int)event + 1))
8019+
{
8020+
for (ap = first_autopat[(int)event]; ap != NULL; ap = ap->next)
8021+
if (ap->group == i)
8022+
{
8023+
give_warning((char_u *)_("W19: Deleting augroup that is still in use"), TRUE);
8024+
in_use = TRUE;
8025+
event = NUM_EVENTS;
8026+
break;
8027+
}
8028+
}
80128029
vim_free(AUGROUP_NAME(i));
8013-
AUGROUP_NAME(i) = NULL;
8030+
if (in_use)
8031+
{
8032+
if (deleted_augroup == NULL)
8033+
deleted_augroup = (char_u *)_("--Deleted--");
8034+
AUGROUP_NAME(i) = deleted_augroup;
8035+
}
8036+
else
8037+
AUGROUP_NAME(i) = NULL;
80148038
}
80158039
}
80168040

@@ -8024,7 +8048,8 @@ au_find_group(char_u *name)
80248048
int i;
80258049

80268050
for (i = 0; i < augroups.ga_len; ++i)
8027-
if (AUGROUP_NAME(i) != NULL && STRCMP(AUGROUP_NAME(i), name) == 0)
8051+
if (AUGROUP_NAME(i) != NULL && AUGROUP_NAME(i) != deleted_augroup
8052+
&& STRCMP(AUGROUP_NAME(i), name) == 0)
80288053
return i;
80298054
return AUGROUP_ERROR;
80308055
}
@@ -8081,10 +8106,20 @@ do_augroup(char_u *arg, int del_group)
80818106
void
80828107
free_all_autocmds(void)
80838108
{
8109+
int i;
8110+
char_u *s;
8111+
80848112
for (current_augroup = -1; current_augroup < augroups.ga_len;
80858113
++current_augroup)
80868114
do_autocmd((char_u *)"", TRUE);
8087-
ga_clear_strings(&augroups);
8115+
8116+
for (i = 0; i < augroups.ga_len; ++i)
8117+
{
8118+
s = ((char_u **)(augroups.ga_data))[i];
8119+
if (s != deleted_augroup)
8120+
vim_free(s);
8121+
}
8122+
ga_clear(&augroups);
80888123
}
80898124
#endif
80908125

@@ -9830,7 +9865,8 @@ get_augroup_name(expand_T *xp UNUSED, int idx)
98309865
return (char_u *)"END";
98319866
if (idx >= augroups.ga_len) /* end of list */
98329867
return NULL;
9833-
if (AUGROUP_NAME(idx) == NULL) /* skip deleted entries */
9868+
if (AUGROUP_NAME(idx) == NULL || AUGROUP_NAME(idx) == deleted_augroup)
9869+
/* skip deleted entries */
98349870
return (char_u *)"";
98359871
return AUGROUP_NAME(idx); /* return a name */
98369872
}
@@ -9894,7 +9930,8 @@ get_event_name(expand_T *xp UNUSED, int idx)
98949930
{
98959931
if (idx < augroups.ga_len) /* First list group names, if wanted */
98969932
{
9897-
if (!include_groups || AUGROUP_NAME(idx) == NULL)
9933+
if (!include_groups || AUGROUP_NAME(idx) == NULL
9934+
|| AUGROUP_NAME(idx) == deleted_augroup)
98989935
return (char_u *)""; /* skip deleted entries */
98999936
return AUGROUP_NAME(idx); /* return a name */
99009937
}

src/testdir/test_autocmd.vim

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,3 +151,20 @@ func Test_early_bar()
151151
au! vimBarTest|echo 'hello'
152152
call assert_equal(1, len(split(execute('au vimBarTest'), "\n")))
153153
endfunc
154+
155+
func Test_augroup_warning()
156+
augroup TheWarning
157+
au VimEnter * echo 'entering'
158+
augroup END
159+
call assert_true(match(execute('au VimEnter'), "TheWarning.*VimEnter") >= 0)
160+
redir => res
161+
augroup! TheWarning
162+
redir END
163+
call assert_true(match(res, "W19:") >= 0)
164+
call assert_true(match(execute('au VimEnter'), "-Deleted-.*VimEnter") >= 0)
165+
166+
" check "Another" does not take the pace of the deleted entry
167+
augroup Another
168+
augroup END
169+
call assert_true(match(execute('au VimEnter'), "-Deleted-.*VimEnter") >= 0)
170+
endfunc

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -758,6 +758,8 @@ static char *(features[]) =
758758

759759
static int included_patches[] =
760760
{ /* Add new patch number below this line */
761+
/**/
762+
2117,
761763
/**/
762764
2116,
763765
/**/

0 commit comments

Comments
 (0)