summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYegappan Lakshmanan <yegappan@yahoo.com>2022-09-24 11:30:41 +0100
committerBram Moolenaar <Bram@vim.org>2022-09-24 11:30:41 +0100
commite9dcf13a3007d4f603e007e0526b0005fd026bc5 (patch)
treeb0e990dff3986cd6d729c1fb4ee924479666d566
parent87af60c91503e37c9144f8e48022b12994ce2c85 (diff)
downloadvim-git-e9dcf13a3007d4f603e007e0526b0005fd026bc5.tar.gz
patch 9.0.0568: autocmd code is indented more than neededv9.0.0568
Problem: Autocmd code is indented more than needed. Solution: Break out sooner. (Yegappan Lakshmanan, closes #11208) Also in user function code.
-rw-r--r--src/autocmd.c245
-rw-r--r--src/userfunc.c60
-rw-r--r--src/version.c2
3 files changed, 157 insertions, 150 deletions
diff --git a/src/autocmd.c b/src/autocmd.c
index 2e3026217..599db46c7 100644
--- a/src/autocmd.c
+++ b/src/autocmd.c
@@ -320,26 +320,26 @@ show_autocmd(AutoPat *ap, event_T event)
for (ac = ap->cmds; ac != NULL; ac = ac->next)
{
- if (ac->cmd != NULL) // skip removed commands
- {
- if (msg_col >= 14)
- msg_putchar('\n');
- msg_col = 14;
- if (got_int)
- return;
- msg_outtrans(ac->cmd);
+ if (ac->cmd == NULL) // skip removed commands
+ continue;
+
+ if (msg_col >= 14)
+ msg_putchar('\n');
+ msg_col = 14;
+ if (got_int)
+ return;
+ msg_outtrans(ac->cmd);
#ifdef FEAT_EVAL
- if (p_verbose > 0)
- last_set_msg(ac->script_ctx);
+ if (p_verbose > 0)
+ last_set_msg(ac->script_ctx);
#endif
+ if (got_int)
+ return;
+ if (ac->next != NULL)
+ {
+ msg_putchar('\n');
if (got_int)
return;
- if (ac->next != NULL)
- {
- msg_putchar('\n');
- if (got_int)
- return;
- }
}
}
}
@@ -492,21 +492,21 @@ au_new_group(char_u *name)
int i;
i = au_find_group(name);
- if (i == AUGROUP_ERROR) // the group doesn't exist yet, add it
- {
- // First try using a free entry.
- for (i = 0; i < augroups.ga_len; ++i)
- if (AUGROUP_NAME(i) == NULL)
- break;
- if (i == augroups.ga_len && ga_grow(&augroups, 1) == FAIL)
- return AUGROUP_ERROR;
+ if (i != AUGROUP_ERROR)
+ return i;
- AUGROUP_NAME(i) = vim_strsave(name);
+ // the group doesn't exist yet, add it. First try using a free entry.
+ for (i = 0; i < augroups.ga_len; ++i)
if (AUGROUP_NAME(i) == NULL)
- return AUGROUP_ERROR;
- if (i == augroups.ga_len)
- ++augroups.ga_len;
- }
+ break;
+ if (i == augroups.ga_len && ga_grow(&augroups, 1) == FAIL)
+ return AUGROUP_ERROR;
+
+ AUGROUP_NAME(i) = vim_strsave(name);
+ if (AUGROUP_NAME(i) == NULL)
+ return AUGROUP_ERROR;
+ if (i == augroups.ga_len)
+ ++augroups.ga_len;
return i;
}
@@ -514,37 +514,41 @@ au_new_group(char_u *name)
static void
au_del_group(char_u *name)
{
- int i;
+ int i;
+ event_T event;
+ AutoPat *ap;
+ int in_use = FALSE;
+
i = au_find_group(name);
if (i == AUGROUP_ERROR) // the group doesn't exist
+ {
semsg(_(e_no_such_group_str), name);
- else if (i == current_augroup)
- emsg(_(e_cannot_delete_current_group));
- else
+ return;
+ }
+ if (i == current_augroup)
{
- event_T event;
- AutoPat *ap;
- int in_use = FALSE;
+ emsg(_(e_cannot_delete_current_group));
+ return;
+ }
- for (event = (event_T)0; (int)event < NUM_EVENTS;
- event = (event_T)((int)event + 1))
- {
- FOR_ALL_AUTOCMD_PATTERNS(event, ap)
- if (ap->group == i && ap->pat != NULL)
- {
- give_warning((char_u *)_("W19: Deleting augroup that is still in use"), TRUE);
- in_use = TRUE;
- event = NUM_EVENTS;
- break;
- }
- }
- vim_free(AUGROUP_NAME(i));
- if (in_use)
- AUGROUP_NAME(i) = get_deleted_augroup();
- else
- AUGROUP_NAME(i) = NULL;
+ for (event = (event_T)0; (int)event < NUM_EVENTS;
+ event = (event_T)((int)event + 1))
+ {
+ FOR_ALL_AUTOCMD_PATTERNS(event, ap)
+ if (ap->group == i && ap->pat != NULL)
+ {
+ give_warning((char_u *)_("W19: Deleting augroup that is still in use"), TRUE);
+ in_use = TRUE;
+ event = NUM_EVENTS;
+ break;
+ }
}
+ vim_free(AUGROUP_NAME(i));
+ if (in_use)
+ AUGROUP_NAME(i) = get_deleted_augroup();
+ else
+ AUGROUP_NAME(i) = NULL;
}
/*
@@ -768,20 +772,23 @@ au_event_disable(char *what)
char_u *save_ei;
save_ei = vim_strsave(p_ei);
- if (save_ei != NULL)
+ if (save_ei == NULL)
+ return NULL;
+
+ new_ei = vim_strnsave(p_ei, STRLEN(p_ei) + STRLEN(what));
+ if (new_ei == NULL)
{
- new_ei = vim_strnsave(p_ei, STRLEN(p_ei) + STRLEN(what));
- if (new_ei != NULL)
- {
- if (*what == ',' && *p_ei == NUL)
- STRCPY(new_ei, what + 1);
- else
- STRCAT(new_ei, what);
- set_string_option_direct((char_u *)"ei", -1, new_ei,
- OPT_FREE, SID_NONE);
- vim_free(new_ei);
- }
+ vim_free(save_ei);
+ return NULL;
}
+
+ if (*what == ',' && *p_ei == NUL)
+ STRCPY(new_ei, what + 1);
+ else
+ STRCAT(new_ei, what);
+ set_string_option_direct((char_u *)"ei", -1, new_ei,
+ OPT_FREE, SID_NONE);
+ vim_free(new_ei);
return save_ei;
}
@@ -908,48 +915,48 @@ do_autocmd(exarg_T *eap, char_u *arg_in, int forceit)
cmd = skipwhite(cmd);
for (i = 0; i < 2; i++)
{
- if (*cmd != NUL)
+ if (*cmd == NUL)
+ continue;
+
+ // Check for "++once" flag.
+ if (STRNCMP(cmd, "++once", 6) == 0 && VIM_ISWHITE(cmd[6]))
+ {
+ if (once)
+ semsg(_(e_duplicate_argument_str), "++once");
+ once = TRUE;
+ cmd = skipwhite(cmd + 6);
+ }
+
+ // Check for "++nested" flag.
+ if ((STRNCMP(cmd, "++nested", 8) == 0 && VIM_ISWHITE(cmd[8])))
{
- // Check for "++once" flag.
- if (STRNCMP(cmd, "++once", 6) == 0 && VIM_ISWHITE(cmd[6]))
+ if (nested)
{
- if (once)
- semsg(_(e_duplicate_argument_str), "++once");
- once = TRUE;
- cmd = skipwhite(cmd + 6);
+ semsg(_(e_duplicate_argument_str), "++nested");
+ return;
}
+ nested = TRUE;
+ cmd = skipwhite(cmd + 8);
+ }
- // Check for "++nested" flag.
- if ((STRNCMP(cmd, "++nested", 8) == 0 && VIM_ISWHITE(cmd[8])))
+ // Check for the old "nested" flag in legacy script.
+ if (STRNCMP(cmd, "nested", 6) == 0 && VIM_ISWHITE(cmd[6]))
+ {
+ if (in_vim9script())
{
- if (nested)
- {
- semsg(_(e_duplicate_argument_str), "++nested");
- return;
- }
- nested = TRUE;
- cmd = skipwhite(cmd + 8);
+ // If there ever is a :nested command this error should
+ // be removed and "nested" accepted as the start of the
+ // command.
+ emsg(_(e_invalid_command_nested_did_you_mean_plusplus_nested));
+ return;
}
-
- // Check for the old "nested" flag in legacy script.
- if (STRNCMP(cmd, "nested", 6) == 0 && VIM_ISWHITE(cmd[6]))
+ if (nested)
{
- if (in_vim9script())
- {
- // If there ever is a :nested command this error should
- // be removed and "nested" accepted as the start of the
- // command.
- emsg(_(e_invalid_command_nested_did_you_mean_plusplus_nested));
- return;
- }
- if (nested)
- {
- semsg(_(e_duplicate_argument_str), "nested");
- return;
- }
- nested = TRUE;
- cmd = skipwhite(cmd + 6);
+ semsg(_(e_duplicate_argument_str), "nested");
+ return;
}
+ nested = TRUE;
+ cmd = skipwhite(cmd + 6);
}
}
@@ -1407,30 +1414,30 @@ ex_doautoall(exarg_T *eap)
FOR_ALL_BUFFERS(buf)
{
// Only do loaded buffers and skip the current buffer, it's done last.
- if (buf->b_ml.ml_mfp != NULL && buf != curbuf)
- {
- // find a window for this buffer and save some values
- aucmd_prepbuf(&aco, buf);
- set_bufref(&bufref, buf);
+ if (buf->b_ml.ml_mfp == NULL || buf == curbuf)
+ continue;
- // execute the autocommands for this buffer
- retval = do_doautocmd(arg, FALSE, &did_aucmd);
+ // find a window for this buffer and save some values
+ aucmd_prepbuf(&aco, buf);
+ set_bufref(&bufref, buf);
- if (call_do_modelines && did_aucmd)
- // Execute the modeline settings, but don't set window-local
- // options if we are using the current window for another
- // buffer.
- do_modelines(curwin == aucmd_win ? OPT_NOWIN : 0);
+ // execute the autocommands for this buffer
+ retval = do_doautocmd(arg, FALSE, &did_aucmd);
- // restore the current window
- aucmd_restbuf(&aco);
+ if (call_do_modelines && did_aucmd)
+ // Execute the modeline settings, but don't set window-local
+ // options if we are using the current window for another
+ // buffer.
+ do_modelines(curwin == aucmd_win ? OPT_NOWIN : 0);
- // stop if there is some error or buffer was deleted
- if (retval == FAIL || !bufref_valid(&bufref))
- {
- retval = FAIL;
- break;
- }
+ // restore the current window
+ aucmd_restbuf(&aco);
+
+ // stop if there is some error or buffer was deleted
+ if (retval == FAIL || !bufref_valid(&bufref))
+ {
+ retval = FAIL;
+ break;
}
}
diff --git a/src/userfunc.c b/src/userfunc.c
index cc90b95b7..0f194d57e 100644
--- a/src/userfunc.c
+++ b/src/userfunc.c
@@ -1881,7 +1881,7 @@ eval_fname_sid(char_u *p)
* In a script change <SID>name() and s:name() to K_SNR 123_name().
* Change <SNR>123_name() to K_SNR 123_name().
* Use "fname_buf[FLEN_FIXED + 1]" when it fits, otherwise allocate memory
- * (slow).
+ * and set "tofree".
*/
char_u *
fname_trans_sid(char_u *name, char_u *fname_buf, char_u **tofree, int *error)
@@ -1891,43 +1891,41 @@ fname_trans_sid(char_u *name, char_u *fname_buf, char_u **tofree, int *error)
int i;
llen = eval_fname_script(name);
- if (llen > 0)
+ if (llen == 0)
+ return name; // no prefix
+
+ fname_buf[0] = K_SPECIAL;
+ fname_buf[1] = KS_EXTRA;
+ fname_buf[2] = (int)KE_SNR;
+ i = 3;
+ if (eval_fname_sid(name)) // "<SID>" or "s:"
{
- fname_buf[0] = K_SPECIAL;
- fname_buf[1] = KS_EXTRA;
- fname_buf[2] = (int)KE_SNR;
- i = 3;
- if (eval_fname_sid(name)) // "<SID>" or "s:"
- {
- if (current_sctx.sc_sid <= 0)
- *error = FCERR_SCRIPT;
- else
- {
- sprintf((char *)fname_buf + 3, "%ld_",
- (long)current_sctx.sc_sid);
- i = (int)STRLEN(fname_buf);
- }
- }
- if (i + STRLEN(name + llen) < FLEN_FIXED)
+ if (current_sctx.sc_sid <= 0)
+ *error = FCERR_SCRIPT;
+ else
{
- STRCPY(fname_buf + i, name + llen);
- fname = fname_buf;
+ sprintf((char *)fname_buf + 3, "%ld_",
+ (long)current_sctx.sc_sid);
+ i = (int)STRLEN(fname_buf);
}
+ }
+ if (i + STRLEN(name + llen) < FLEN_FIXED)
+ {
+ STRCPY(fname_buf + i, name + llen);
+ fname = fname_buf;
+ }
+ else
+ {
+ fname = alloc(i + STRLEN(name + llen) + 1);
+ if (fname == NULL)
+ *error = FCERR_OTHER;
else
{
- fname = alloc(i + STRLEN(name + llen) + 1);
- if (fname == NULL)
- *error = FCERR_OTHER;
- else
- {
- *tofree = fname;
- mch_memmove(fname, fname_buf, (size_t)i);
- STRCPY(fname + i, name + llen);
- }
+ *tofree = fname;
+ mch_memmove(fname, fname_buf, (size_t)i);
+ STRCPY(fname + i, name + llen);
}
}
- else
- fname = name;
return fname;
}
diff --git a/src/version.c b/src/version.c
index bf58a7aca..e8d6253e0 100644
--- a/src/version.c
+++ b/src/version.c
@@ -700,6 +700,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 568,
+/**/
567,
/**/
566,