vim-patch:9.0.0568: autocmd code is indented more than needed (#20318)

Problem:    Autocmd code is indented more than needed.
Solution:   Break out sooner. (Yegappan Lakshmanan, closes vim/vim#11208)
            Also in user function code.
e9dcf13a30
This commit is contained in:
zeertzjq
2022-09-24 19:20:03 +08:00
committed by GitHub
parent f8b656c582
commit db056de29a
2 changed files with 60 additions and 56 deletions

View File

@@ -478,34 +478,37 @@ void augroup_del(char *name, bool stupid_legacy_mode)
int i = augroup_find(name);
if (i == AUGROUP_ERROR) { // the group doesn't exist
semsg(_("E367: No such group: \"%s\""), name);
} else if (i == current_augroup) {
return;
}
if (i == current_augroup) {
emsg(_("E936: Cannot delete the current group"));
} else {
if (stupid_legacy_mode) {
FOR_ALL_AUEVENTS(event) {
FOR_ALL_AUPATS_IN_EVENT(event, ap) {
if (ap->group == i && ap->pat != NULL) {
give_warning(_("W19: Deleting augroup that is still in use"), true);
map_put(String, int)(&map_augroup_name_to_id, cstr_as_string(name), AUGROUP_DELETED);
augroup_map_del(ap->group, NULL);
return;
}
}
}
} else {
FOR_ALL_AUEVENTS(event) {
FOR_ALL_AUPATS_IN_EVENT(event, ap) {
if (ap->group == i) {
aupat_del(ap);
}
return;
}
if (stupid_legacy_mode) {
FOR_ALL_AUEVENTS(event) {
FOR_ALL_AUPATS_IN_EVENT(event, ap) {
if (ap->group == i && ap->pat != NULL) {
give_warning(_("W19: Deleting augroup that is still in use"), true);
map_put(String, int)(&map_augroup_name_to_id, cstr_as_string(name), AUGROUP_DELETED);
augroup_map_del(ap->group, NULL);
return;
}
}
}
} else {
FOR_ALL_AUEVENTS(event) {
FOR_ALL_AUPATS_IN_EVENT(event, ap) {
if (ap->group == i) {
aupat_del(ap);
}
}
}
// Remove the group because it's not currently in use.
augroup_map_del(i, name);
au_cleanup();
}
// Remove the group because it's not currently in use.
augroup_map_del(i, name);
au_cleanup();
}
/// Find the ID of an autocmd group name.
@@ -733,7 +736,6 @@ char *au_event_disable(char *what)
}
set_string_option_direct("ei", -1, new_ei, OPT_FREE, SID_NONE);
xfree(new_ei);
return save_ei;
}
@@ -837,13 +839,15 @@ void do_autocmd(char *arg_in, int forceit)
bool invalid_flags = false;
for (size_t i = 0; i < 2; i++) {
if (*cmd != NUL) {
invalid_flags |= arg_autocmd_flag_get(&once, &cmd, "++once", 6);
invalid_flags |= arg_autocmd_flag_get(&nested, &cmd, "++nested", 8);
// Check the deprecated "nested" flag.
invalid_flags |= arg_autocmd_flag_get(&nested, &cmd, "nested", 6);
if (*cmd == NUL) {
continue;
}
invalid_flags |= arg_autocmd_flag_get(&once, &cmd, "++once", 6);
invalid_flags |= arg_autocmd_flag_get(&nested, &cmd, "++nested", 8);
// Check the deprecated "nested" flag.
invalid_flags |= arg_autocmd_flag_get(&nested, &cmd, "nested", 6);
}
if (invalid_flags) {
@@ -1275,6 +1279,7 @@ void ex_doautoall(exarg_T *eap)
if (buf->b_ml.ml_mfp == NULL || buf == curbuf) {
continue;
}
// Find a window for this buffer and save some values.
aucmd_prepbuf(&aco, buf);
set_bufref(&bufref, buf);

View File

@@ -515,35 +515,34 @@ static char *fname_trans_sid(const char *const name, char *const fname_buf, char
int *const error)
FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT
{
char *fname;
const int llen = eval_fname_script(name);
if (llen > 0) {
fname_buf[0] = (char)K_SPECIAL;
fname_buf[1] = (char)KS_EXTRA;
fname_buf[2] = KE_SNR;
int i = 3;
if (eval_fname_sid(name)) { // "<SID>" or "s:"
if (current_sctx.sc_sid <= 0) {
*error = FCERR_SCRIPT;
} else {
snprintf(fname_buf + i, (size_t)(FLEN_FIXED + 1 - i), "%" PRId64 "_",
(int64_t)current_sctx.sc_sid);
i = (int)strlen(fname_buf);
}
}
if ((size_t)i + strlen(name + llen) < FLEN_FIXED) {
STRCPY(fname_buf + i, name + llen);
fname = fname_buf;
} else {
fname = xmalloc((size_t)i + strlen(name + llen) + 1);
*tofree = fname;
memmove(fname, fname_buf, (size_t)i);
STRCPY(fname + i, name + llen);
}
} else {
fname = (char *)name;
if (llen == 0) {
return (char *)name; // no prefix
}
fname_buf[0] = (char)K_SPECIAL;
fname_buf[1] = (char)KS_EXTRA;
fname_buf[2] = KE_SNR;
int i = 3;
if (eval_fname_sid(name)) { // "<SID>" or "s:"
if (current_sctx.sc_sid <= 0) {
*error = FCERR_SCRIPT;
} else {
snprintf(fname_buf + i, (size_t)(FLEN_FIXED + 1 - i), "%" PRId64 "_",
(int64_t)current_sctx.sc_sid);
i = (int)strlen(fname_buf);
}
}
char *fname;
if ((size_t)i + strlen(name + llen) < FLEN_FIXED) {
STRCPY(fname_buf + i, name + llen);
fname = fname_buf;
} else {
fname = xmalloc((size_t)i + strlen(name + llen) + 1);
*tofree = fname;
memmove(fname, fname_buf, (size_t)i);
STRCPY(fname + i, name + llen);
}
return fname;
}