Patch 9.0.0568
Problem:    Autocmd code is indented more than needed.
Solution:   Break out sooner. (Yegappan Lakshmanan, closes #11208)
            Also in user function code.
Files:      src/autocmd.c, src/userfunc.c


*** ../vim-9.0.0567/src/autocmd.c       2022-08-28 19:16:11.976716179 +0100
--- src/autocmd.c       2022-09-24 11:25:16.977336189 +0100
***************
*** 320,345 ****
  
      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);
  #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;
-           }
        }
      }
  }
--- 320,345 ----
  
      for (ac = ap->cmds; ac != NULL; ac = ac->next)
      {
!       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)
+       {
+           msg_putchar('\n');
            if (got_int)
                return;
        }
      }
  }
***************
*** 492,512 ****
      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;
  
!       AUGROUP_NAME(i) = vim_strsave(name);
        if (AUGROUP_NAME(i) == NULL)
!           return AUGROUP_ERROR;
!       if (i == augroups.ga_len)
!           ++augroups.ga_len;
!     }
  
      return i;
  }
--- 492,512 ----
      int               i;
  
      i = au_find_group(name);
!     if (i != AUGROUP_ERROR)
!       return i;
  
!     // 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;
! 
!     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,550 ****
      static void
  au_del_group(char_u *name)
  {
!     int           i;
  
      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
      {
!       event_T event;
!       AutoPat *ap;
!       int     in_use = FALSE;
  
!       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;
      }
  }
  
  /*
--- 514,554 ----
      static void
  au_del_group(char_u *name)
  {
!     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);
!       return;
!     }
!     if (i == current_augroup)
      {
!       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;
  }
  
  /*
***************
*** 768,787 ****
      char_u    *save_ei;
  
      save_ei = vim_strsave(p_ei);
!     if (save_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);
!       }
      }
      return save_ei;
  }
  
--- 772,794 ----
      char_u    *save_ei;
  
      save_ei = vim_strsave(p_ei);
!     if (save_ei == NULL)
!       return NULL;
! 
!     new_ei = vim_strnsave(p_ei, STRLEN(p_ei) + STRLEN(what));
!     if (new_ei == NULL)
      {
!       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,955 ****
        cmd = skipwhite(cmd);
        for (i = 0; i < 2; i++)
        {
!           if (*cmd != NUL)
            {
!               // 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])))
                {
!                   if (nested)
!                   {
!                       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]))
                {
!                   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);
                }
            }
        }
  
--- 915,962 ----
        cmd = skipwhite(cmd);
        for (i = 0; i < 2; i++)
        {
!           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])))
!           {
!               if (nested)
                {
!                   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]))
!           {
!               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);
            }
        }
  
***************
*** 1407,1436 ****
      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);
! 
!           // 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);
  
!           // 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;
!           }
        }
      }
  
--- 1414,1443 ----
      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)
!           continue;
  
!       // 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);
  
!       // 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;
        }
      }
  
*** ../vim-9.0.0567/src/userfunc.c      2022-09-22 22:03:11.256114607 +0100
--- src/userfunc.c      2022-09-24 11:29:14.449640904 +0100
***************
*** 1881,1887 ****
   * 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).
   */
      char_u *
  fname_trans_sid(char_u *name, char_u *fname_buf, char_u **tofree, int *error)
--- 1881,1887 ----
   * 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
!  * and set "tofree".
   */
      char_u *
  fname_trans_sid(char_u *name, char_u *fname_buf, char_u **tofree, int *error)
***************
*** 1891,1933 ****
      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;
        }
        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);
!           }
        }
      }
-     else
-       fname = name;
      return fname;
  }
  
--- 1891,1931 ----
      int               i;
  
      llen = eval_fname_script(name);
!     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
        {
!           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
        {
!           *tofree = fname;
!           mch_memmove(fname, fname_buf, (size_t)i);
!           STRCPY(fname + i, name + llen);
        }
      }
      return fname;
  }
  
*** ../vim-9.0.0567/src/version.c       2022-09-24 11:17:48.373970710 +0100
--- src/version.c       2022-09-24 11:23:04.260813600 +0100
***************
*** 701,702 ****
--- 701,704 ----
  {   /* Add new patch number below this line */
+ /**/
+     568,
  /**/

-- 
hundred-and-one symptoms of being an internet addict:
157. You fum through a magazine, you first check to see if it has a web
     address.

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///                                                                      \\\
\\\        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/20220924103110.1263B1C0728%40moolenaar.net.

Raspunde prin e-mail lui