changeset 30465:b3367a7a3914 v9.0.0568

patch 9.0.0568: autocmd code is indented more than needed Commit: https://github.com/vim/vim/commit/e9dcf13a3007d4f603e007e0526b0005fd026bc5 Author: Yegappan Lakshmanan <yegappan@yahoo.com> Date: Sat Sep 24 11:30:41 2022 +0100 patch 9.0.0568: autocmd code is indented more than needed Problem: Autocmd code is indented more than needed. Solution: Break out sooner. (Yegappan Lakshmanan, closes https://github.com/vim/vim/issues/11208) Also in user function code.
author Bram Moolenaar <Bram@vim.org>
date Sat, 24 Sep 2022 12:45:03 +0200
parents 00e127edb23a
children adb1bc2b3cb6
files src/autocmd.c src/userfunc.c src/version.c
diffstat 3 files changed, 161 insertions(+), 154 deletions(-) [+]
line wrap: on
line diff
--- 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 (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);
+#endif
+	if (got_int)
+	    return;
+	if (ac->next != NULL)
 	{
-	    if (msg_col >= 14)
-		msg_putchar('\n');
-	    msg_col = 14;
+	    msg_putchar('\n');
 	    if (got_int)
 		return;
-	    msg_outtrans(ac->cmd);
-#ifdef FEAT_EVAL
-	    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;
-	    }
 	}
     }
 }
@@ -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)
+	return;
+    }
+    if (i == current_augroup)
+    {
 	emsg(_(e_cannot_delete_current_group));
-    else
-    {
-	event_T	event;
-	AutoPat	*ap;
-	int	in_use = FALSE;
+	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,
 	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]))
 	    {
-		// 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);
-		}
+		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 "++nested" flag.
+	    if ((STRNCMP(cmd, "++nested", 8) == 0 && VIM_ISWHITE(cmd[8])))
+	    {
+		if (nested)
 		{
-		    if (nested)
-		    {
-			semsg(_(e_duplicate_argument_str), "++nested");
-			return;
-		    }
-		    nested = TRUE;
-		    cmd = skipwhite(cmd + 8);
+		    semsg(_(e_duplicate_argument_str), "++nested");
+		    return;
 		}
+		nested = TRUE;
+		cmd = skipwhite(cmd + 8);
+	    }
 
-		// Check for the old "nested" flag in legacy script.
-		if (STRNCMP(cmd, "nested", 6) == 0 && VIM_ISWHITE(cmd[6]))
+	    // Check for the old "nested" flag in legacy script.
+	    if (STRNCMP(cmd, "nested", 6) == 0 && VIM_ISWHITE(cmd[6]))
+	    {
+		if (in_vim9script())
 		{
-		    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);
+		    // 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);
 	    }
 	}
 
@@ -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);
+
+	// execute the autocommands for this buffer
+	retval = do_doautocmd(arg, FALSE, &did_aucmd);
 
-	    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);
+	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);
 
-	    // restore the current window
-	    aucmd_restbuf(&aco);
+	// 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;
-	    }
+	// stop if there is some error or buffer was deleted
+	if (retval == FAIL || !bufref_valid(&bufref))
+	{
+	    retval = FAIL;
+	    break;
 	}
     }
 
--- 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 *fn
     int		i;
 
     llen = eval_fname_script(name);
-    if (llen > 0)
-    {
-	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)
-	{
-	    STRCPY(fname_buf + i, name + llen);
-	    fname = fname_buf;
-	}
+    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:"
+    {
+	if (current_sctx.sc_sid <= 0)
+	    *error = FCERR_SCRIPT;
 	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);
-	    }
+	    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 = name;
+    {
+	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);
+	}
+    }
     return fname;
 }
 
--- 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,