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,9 +478,13 @@ void augroup_del(char *name, bool stupid_legacy_mode)
int i = augroup_find(name); int i = augroup_find(name);
if (i == AUGROUP_ERROR) { // the group doesn't exist if (i == AUGROUP_ERROR) { // the group doesn't exist
semsg(_("E367: No such group: \"%s\""), name); semsg(_("E367: No such group: \"%s\""), name);
} else if (i == current_augroup) { return;
}
if (i == current_augroup) {
emsg(_("E936: Cannot delete the current group")); emsg(_("E936: Cannot delete the current group"));
} else { return;
}
if (stupid_legacy_mode) { if (stupid_legacy_mode) {
FOR_ALL_AUEVENTS(event) { FOR_ALL_AUEVENTS(event) {
FOR_ALL_AUPATS_IN_EVENT(event, ap) { FOR_ALL_AUPATS_IN_EVENT(event, ap) {
@@ -506,7 +510,6 @@ void augroup_del(char *name, bool stupid_legacy_mode)
augroup_map_del(i, name); augroup_map_del(i, name);
au_cleanup(); au_cleanup();
} }
}
/// Find the ID of an autocmd group name. /// 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); set_string_option_direct("ei", -1, new_ei, OPT_FREE, SID_NONE);
xfree(new_ei); xfree(new_ei);
return save_ei; return save_ei;
} }
@@ -837,14 +839,16 @@ void do_autocmd(char *arg_in, int forceit)
bool invalid_flags = false; bool invalid_flags = false;
for (size_t i = 0; i < 2; i++) { for (size_t i = 0; i < 2; i++) {
if (*cmd != NUL) { if (*cmd == NUL) {
continue;
}
invalid_flags |= arg_autocmd_flag_get(&once, &cmd, "++once", 6); invalid_flags |= arg_autocmd_flag_get(&once, &cmd, "++once", 6);
invalid_flags |= arg_autocmd_flag_get(&nested, &cmd, "++nested", 8); invalid_flags |= arg_autocmd_flag_get(&nested, &cmd, "++nested", 8);
// Check the deprecated "nested" flag. // Check the deprecated "nested" flag.
invalid_flags |= arg_autocmd_flag_get(&nested, &cmd, "nested", 6); invalid_flags |= arg_autocmd_flag_get(&nested, &cmd, "nested", 6);
} }
}
if (invalid_flags) { if (invalid_flags) {
return; return;
@@ -1275,6 +1279,7 @@ void ex_doautoall(exarg_T *eap)
if (buf->b_ml.ml_mfp == NULL || buf == curbuf) { if (buf->b_ml.ml_mfp == NULL || buf == curbuf) {
continue; continue;
} }
// Find a window for this buffer and save some values. // Find a window for this buffer and save some values.
aucmd_prepbuf(&aco, buf); aucmd_prepbuf(&aco, buf);
set_bufref(&bufref, buf); set_bufref(&bufref, buf);

View File

@@ -515,9 +515,11 @@ static char *fname_trans_sid(const char *const name, char *const fname_buf, char
int *const error) int *const error)
FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT
{ {
char *fname;
const int llen = eval_fname_script(name); const int llen = eval_fname_script(name);
if (llen > 0) { if (llen == 0) {
return (char *)name; // no prefix
}
fname_buf[0] = (char)K_SPECIAL; fname_buf[0] = (char)K_SPECIAL;
fname_buf[1] = (char)KS_EXTRA; fname_buf[1] = (char)KS_EXTRA;
fname_buf[2] = KE_SNR; fname_buf[2] = KE_SNR;
@@ -531,6 +533,7 @@ static char *fname_trans_sid(const char *const name, char *const fname_buf, char
i = (int)strlen(fname_buf); i = (int)strlen(fname_buf);
} }
} }
char *fname;
if ((size_t)i + strlen(name + llen) < FLEN_FIXED) { if ((size_t)i + strlen(name + llen) < FLEN_FIXED) {
STRCPY(fname_buf + i, name + llen); STRCPY(fname_buf + i, name + llen);
fname = fname_buf; fname = fname_buf;
@@ -540,10 +543,6 @@ static char *fname_trans_sid(const char *const name, char *const fname_buf, char
memmove(fname, fname_buf, (size_t)i); memmove(fname, fname_buf, (size_t)i);
STRCPY(fname + i, name + llen); STRCPY(fname + i, name + llen);
} }
} else {
fname = (char *)name;
}
return fname; return fname;
} }