aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2022-09-24 19:20:03 +0800
committerGitHub <noreply@github.com>2022-09-24 19:20:03 +0800
commitdb056de29ad2d57ee8e1ba841d969560f9bc6714 (patch)
tree8349928ad4fdbd8156a2caee82d9334f09025783 /src
parentf8b656c582c6f0d9cb35523ac2d2f3d0edbcd52b (diff)
downloadrneovim-db056de29ad2d57ee8e1ba841d969560f9bc6714.tar.gz
rneovim-db056de29ad2d57ee8e1ba841d969560f9bc6714.tar.bz2
rneovim-db056de29ad2d57ee8e1ba841d969560f9bc6714.zip
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. https://github.com/vim/vim/commit/e9dcf13a3007d4f603e007e0526b0005fd026bc5
Diffstat (limited to 'src')
-rw-r--r--src/nvim/autocmd.c61
-rw-r--r--src/nvim/eval/userfunc.c47
2 files changed, 56 insertions, 52 deletions
diff --git a/src/nvim/autocmd.c b/src/nvim/autocmd.c
index 644f892f3c..1f23e7ab79 100644
--- a/src/nvim/autocmd.c
+++ b/src/nvim/autocmd.c
@@ -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;
- }
+ 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);
- }
+ }
+ } 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);
diff --git a/src/nvim/eval/userfunc.c b/src/nvim/eval/userfunc.c
index f28af5a6cc..72d6a1394e 100644
--- a/src/nvim/eval/userfunc.c
+++ b/src/nvim/eval/userfunc.c
@@ -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;
+ 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 {
- fname = xmalloc((size_t)i + strlen(name + llen) + 1);
- *tofree = fname;
- memmove(fname, fname_buf, (size_t)i);
- STRCPY(fname + i, name + llen);
+ 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 = (char *)name;
+ 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;
}