Patch 8.2.0260
Problem:    Several lines of code are duplicated.
Solution:   Move duplicated code to a function. (Yegappan Lakshmanan,
            closes #5330)
Files:      src/option.c, src/os_unix.c, src/os_win32.c, src/proto/term.pro,
            src/quickfix.c, src/regexp.c, src/regexp_bt.c, src/regexp_nfa.c,
            src/term.c


*** ../vim-8.2.0259/src/option.c        2020-01-26 21:59:25.628718127 +0100
--- src/option.c        2020-02-15 22:42:40.100339562 +0100
***************
*** 2498,2503 ****
--- 2498,2558 ----
  }
  #endif
  
+ #if defined(FEAT_EVAL)
+ /*
+  * Apply the OptionSet autocommand.
+  */
+     static void
+ apply_optionset_autocmd(
+       int     opt_idx,
+       long    opt_flags,
+       long    oldval,
+       long    oldval_g,
+       long    newval,
+       char    *errmsg)
+ {
+     char_u buf_old[12], buf_old_global[12], buf_new[12], buf_type[12];
+ 
+     // Don't do this while starting up, failure or recursively.
+     if (starting || errmsg != NULL || *get_vim_var_str(VV_OPTION_TYPE) != NUL)
+       return;
+ 
+     vim_snprintf((char *)buf_old, sizeof(buf_old), "%ld", oldval);
+     vim_snprintf((char *)buf_old_global, sizeof(buf_old_global), "%ld",
+                                                       oldval_g);
+     vim_snprintf((char *)buf_new, sizeof(buf_new), "%ld", newval);
+     vim_snprintf((char *)buf_type, sizeof(buf_type), "%s",
+                               (opt_flags & OPT_LOCAL) ? "local" : "global");
+     set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
+     set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
+     set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
+     if (opt_flags & OPT_LOCAL)
+     {
+       set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"setlocal", -1);
+       set_vim_var_string(VV_OPTION_OLDLOCAL, buf_old, -1);
+     }
+     if (opt_flags & OPT_GLOBAL)
+     {
+       set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"setglobal", -1);
+       set_vim_var_string(VV_OPTION_OLDGLOBAL, buf_old, -1);
+     }
+     if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
+     {
+       set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"set", -1);
+       set_vim_var_string(VV_OPTION_OLDLOCAL, buf_old, -1);
+       set_vim_var_string(VV_OPTION_OLDGLOBAL, buf_old_global, -1);
+     }
+     if (opt_flags & OPT_MODELINE)
+     {
+       set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"modeline", -1);
+       set_vim_var_string(VV_OPTION_OLDLOCAL, buf_old, -1);
+     }
+     apply_autocmds(EVENT_OPTIONSET, (char_u *)options[opt_idx].fullname,
+           NULL, FALSE, NULL);
+     reset_v_option_vars();
+ }
+ #endif
+ 
  /*
   * Set the value of a boolean option, and take care of side effects.
   * Returns NULL for success, or an error message for an error.
***************
*** 3071,3115 ****
      options[opt_idx].flags |= P_WAS_SET;
  
  #if defined(FEAT_EVAL)
!     // Don't do this while starting up or recursively.
!     if (!starting && *get_vim_var_str(VV_OPTION_TYPE) == NUL)
!     {
!       char_u buf_old[2], buf_old_global[2], buf_new[2], buf_type[7];
! 
!       vim_snprintf((char *)buf_old, 2, "%d", old_value ? TRUE: FALSE);
!       vim_snprintf((char *)buf_old_global, 2, "%d",
!                                              old_global_value ? TRUE: FALSE);
!       vim_snprintf((char *)buf_new, 2, "%d", value ? TRUE: FALSE);
!       vim_snprintf((char *)buf_type, 7, "%s",
!                                (opt_flags & OPT_LOCAL) ? "local" : "global");
!       set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
!       set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
!       set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
!       if (opt_flags & OPT_LOCAL)
!       {
!           set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"setlocal", -1);
!           set_vim_var_string(VV_OPTION_OLDLOCAL, buf_old, -1);
!       }
!       if (opt_flags & OPT_GLOBAL)
!       {
!           set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"setglobal", -1);
!           set_vim_var_string(VV_OPTION_OLDGLOBAL, buf_old, -1);
!       }
!       if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
!       {
!           set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"set", -1);
!           set_vim_var_string(VV_OPTION_OLDLOCAL, buf_old, -1);
!           set_vim_var_string(VV_OPTION_OLDGLOBAL, buf_old_global, -1);
!       }
!       if (opt_flags & OPT_MODELINE)
!       {
!           set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"modeline", -1);
!           set_vim_var_string(VV_OPTION_OLDLOCAL, buf_old, -1);
!       }
!       apply_autocmds(EVENT_OPTIONSET, (char_u *)options[opt_idx].fullname,
!                                                           NULL, FALSE, NULL);
!       reset_v_option_vars();
!     }
  #endif
  
      comp_col();                           // in case 'ruler' or 'showcmd' 
changed
--- 3126,3135 ----
      options[opt_idx].flags |= P_WAS_SET;
  
  #if defined(FEAT_EVAL)
!     apply_optionset_autocmd(opt_idx, opt_flags,
!                               (long)(old_value ? TRUE : FALSE),
!                               (long)(old_global_value ? TRUE : FALSE),
!                               (long)(value ? TRUE : FALSE), NULL);
  #endif
  
      comp_col();                           // in case 'ruler' or 'showcmd' 
changed
***************
*** 3666,3707 ****
      options[opt_idx].flags |= P_WAS_SET;
  
  #if defined(FEAT_EVAL)
!     // Don't do this while starting up, failure or recursively.
!     if (!starting && errmsg == NULL && *get_vim_var_str(VV_OPTION_TYPE) == 
NUL)
!     {
!       char_u buf_old[11], buf_old_global[11], buf_new[11], buf_type[7];
!       vim_snprintf((char *)buf_old, 10, "%ld", old_value);
!       vim_snprintf((char *)buf_old_global, 10, "%ld", old_global_value);
!       vim_snprintf((char *)buf_new, 10, "%ld", value);
!       vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? 
"local" : "global");
!       set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
!       set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
!       set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
!       if (opt_flags & OPT_LOCAL)
!       {
!           set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"setlocal", -1);
!           set_vim_var_string(VV_OPTION_OLDLOCAL, buf_old, -1);
!       }
!       if (opt_flags & OPT_GLOBAL)
!       {
!           set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"setglobal", -1);
!           set_vim_var_string(VV_OPTION_OLDGLOBAL, buf_old, -1);
!       }
!       if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
!       {
!           set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"set", -1);
!           set_vim_var_string(VV_OPTION_OLDLOCAL, buf_old, -1);
!           set_vim_var_string(VV_OPTION_OLDGLOBAL, buf_old_global, -1);
!       }
!       if (opt_flags & OPT_MODELINE)
!       {
!           set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"modeline", -1);
!           set_vim_var_string(VV_OPTION_OLDLOCAL, buf_old, -1);
!       }
!       apply_autocmds(EVENT_OPTIONSET, (char_u *)options[opt_idx].fullname,
!                                                           NULL, FALSE, NULL);
!       reset_v_option_vars();
!     }
  #endif
  
      comp_col();                           // in case 'columns' or 'ls' changed
--- 3686,3693 ----
      options[opt_idx].flags |= P_WAS_SET;
  
  #if defined(FEAT_EVAL)
!     apply_optionset_autocmd(opt_idx, opt_flags, old_value, old_global_value,
!                                                               value, errmsg);
  #endif
  
      comp_col();                           // in case 'columns' or 'ls' changed
*** ../vim-8.2.0259/src/os_unix.c       2020-01-26 21:59:25.628718127 +0100
--- src/os_unix.c       2020-02-15 22:42:40.100339562 +0100
***************
*** 4980,5008 ****
                            }
                        }
  
!                       // replace K_BS by <BS> and K_DEL by <DEL>
!                       for (i = ta_len; i < ta_len + len; ++i)
!                       {
!                           if (ta_buf[i] == CSI && len - i > 2)
!                           {
!                               c = TERMCAP2KEY(ta_buf[i + 1], ta_buf[i + 2]);
!                               if (c == K_DEL || c == K_KDEL || c == K_BS)
!                               {
!                                   mch_memmove(ta_buf + i + 1, ta_buf + i + 3,
!                                                      (size_t)(len - i - 2));
!                                   if (c == K_DEL || c == K_KDEL)
!                                       ta_buf[i] = DEL;
!                                   else
!                                       ta_buf[i] = Ctrl_H;
!                                   len -= 2;
!                               }
!                           }
!                           else if (ta_buf[i] == '\r')
!                               ta_buf[i] = '\n';
!                           if (has_mbyte)
!                               i += (*mb_ptr2len_len)(ta_buf + i,
!                                                       ta_len + len - i) - 1;
!                       }
  
                        /*
                         * For pipes: echo the typed characters.
--- 4980,4986 ----
                            }
                        }
  
!                       term_replace_bs_del_keycode(ta_buf, ta_len, len);
  
                        /*
                         * For pipes: echo the typed characters.
*** ../vim-8.2.0259/src/os_win32.c      2020-02-10 22:06:28.724574110 +0100
--- src/os_win32.c      2020-02-15 22:42:40.104339546 +0100
***************
*** 4173,4179 ****
      int               ta_len = 0;             // valid bytes in ta_buf[]
  
      DWORD     i;
-     int               c;
      int               noread_cnt = 0;
      garray_T  ga;
      int               delay = 1;
--- 4173,4178 ----
***************
*** 4312,4340 ****
                        }
                    }
  
!                   // replace K_BS by <BS> and K_DEL by <DEL>
!                   for (i = ta_len; i < ta_len + len; ++i)
!                   {
!                       if (ta_buf[i] == CSI && len - i > 2)
!                       {
!                           c = TERMCAP2KEY(ta_buf[i + 1], ta_buf[i + 2]);
!                           if (c == K_DEL || c == K_KDEL || c == K_BS)
!                           {
!                               mch_memmove(ta_buf + i + 1, ta_buf + i + 3,
!                                           (size_t)(len - i - 2));
!                               if (c == K_DEL || c == K_KDEL)
!                                   ta_buf[i] = DEL;
!                               else
!                                   ta_buf[i] = Ctrl_H;
!                               len -= 2;
!                           }
!                       }
!                       else if (ta_buf[i] == '\r')
!                           ta_buf[i] = '\n';
!                       if (has_mbyte)
!                           i += (*mb_ptr2len_len)(ta_buf + i,
!                                                   ta_len + len - i) - 1;
!                   }
  
                    /*
                     * For pipes: echo the typed characters.  For a pty this
--- 4311,4317 ----
                        }
                    }
  
!                   term_replace_bs_del_keycode(ta_buf, ta_len, len);
  
                    /*
                     * For pipes: echo the typed characters.  For a pty this
*** ../vim-8.2.0259/src/proto/term.pro  2020-01-24 20:21:15.389142318 +0100
--- src/proto/term.pro  2020-02-15 22:42:40.104339546 +0100
***************
*** 77,80 ****
--- 77,81 ----
  guicolor_T gui_get_color_cmn(char_u *name);
  guicolor_T gui_get_rgb_color_cmn(int r, int g, int b);
  void cterm_color2rgb(int nr, char_u *r, char_u *g, char_u *b, char_u 
*ansi_idx);
+ void term_replace_bs_del_keycode(char_u *ta_buf, int ta_len, int len);
  /* vim: set ft=c : */
*** ../vim-8.2.0259/src/quickfix.c      2020-02-10 22:56:51.418141128 +0100
--- src/quickfix.c      2020-02-15 22:56:11.713149549 +0100
***************
*** 980,990 ****
  }
  
  /*
!  * Parse the match for '%+' format pattern. The whole matching line is 
included
!  * in the error string.  Return the matched line in "fields->errmsg".
   */
      static int
! qf_parse_fmt_plus(char_u *linebuf, int linelen, qffields_T *fields)
  {
      char_u    *p;
  
--- 980,990 ----
  }
  
  /*
!  * Copy a non-error line into the error string.  Return the matched line in
!  * "fields->errmsg".
   */
      static int
! copy_nonerror_line(char_u *linebuf, int linelen, qffields_T *fields)
  {
      char_u    *p;
  
***************
*** 996,1002 ****
--- 996,1004 ----
        fields->errmsg = p;
        fields->errmsglen = linelen + 1;
      }
+     // copy whole line to error message
      vim_strncpy(fields->errmsg, linebuf, linelen);
+ 
      return QF_OK;
  }
  
***************
*** 1180,1186 ****
        else if (i == 5)
        {
            if (fmt_ptr->flags == '+' && !qf_multiscan) // %+
!               status = qf_parse_fmt_plus(linebuf, linelen, fields);
            else if (midx > 0)                          // %m
                status = qf_parse_fmt_m(regmatch, midx, fields);
        }
--- 1182,1188 ----
        else if (i == 5)
        {
            if (fmt_ptr->flags == '+' && !qf_multiscan) // %+
!               status = copy_nonerror_line(linebuf, linelen, fields);
            else if (midx > 0)                          // %m
                status = qf_parse_fmt_m(regmatch, midx, fields);
        }
***************
*** 1307,1329 ****
      static int
  qf_parse_line_nomatch(char_u *linebuf, int linelen, qffields_T *fields)
  {
-     char_u    *p;
- 
      fields->namebuf[0] = NUL; // no match found, remove file name
      fields->lnum = 0;         // don't jump to this line
      fields->valid = FALSE;
-     if (linelen >= fields->errmsglen)
-     {
-       // linelen + null terminator
-       if ((p = vim_realloc(fields->errmsg, linelen + 1)) == NULL)
-           return QF_NOMEM;
-       fields->errmsg = p;
-       fields->errmsglen = linelen + 1;
-     }
-     // copy whole line to error message
-     vim_strncpy(fields->errmsg, linebuf, linelen);
  
!     return QF_OK;
  }
  
  /*
--- 1309,1319 ----
      static int
  qf_parse_line_nomatch(char_u *linebuf, int linelen, qffields_T *fields)
  {
      fields->namebuf[0] = NUL; // no match found, remove file name
      fields->lnum = 0;         // don't jump to this line
      fields->valid = FALSE;
  
!     return copy_nonerror_line(linebuf, linelen, fields);
  }
  
  /*
*** ../vim-8.2.0259/src/regexp.c        2020-02-12 22:15:14.856205206 +0100
--- src/regexp.c        2020-02-15 22:42:40.104339546 +0100
***************
*** 2511,2516 ****
--- 2511,2538 ----
  }
  #endif
  
+ /*
+  * Initialize the values used for matching against multiple lines
+  */
+     static void
+ init_regexec_multi(
+       regmmatch_T     *rmp,
+       win_T           *win,   // window in which to search or NULL
+       buf_T           *buf,   // buffer in which to search
+       linenr_T        lnum)   // nr of line to start looking for match
+ {
+     rex.reg_match = NULL;
+     rex.reg_mmatch = rmp;
+     rex.reg_buf = buf;
+     rex.reg_win = win;
+     rex.reg_firstlnum = lnum;
+     rex.reg_maxline = rex.reg_buf->b_ml.ml_line_count - lnum;
+     rex.reg_line_lbr = FALSE;
+     rex.reg_ic = rmp->rmm_ic;
+     rex.reg_icombine = FALSE;
+     rex.reg_maxcol = rmp->rmm_maxcol;
+ }
+ 
  #include "regexp_bt.c"
  
  static regengine_T bt_regengine =
*** ../vim-8.2.0259/src/regexp_bt.c     2019-12-22 19:40:36.906100063 +0100
--- src/regexp_bt.c     2020-02-15 22:42:40.104339546 +0100
***************
*** 4854,4870 ****
      proftime_T        *tm,            // timeout limit or NULL
      int               *timed_out)     // flag set on timeout or NULL
  {
!     rex.reg_match = NULL;
!     rex.reg_mmatch = rmp;
!     rex.reg_buf = buf;
!     rex.reg_win = win;
!     rex.reg_firstlnum = lnum;
!     rex.reg_maxline = rex.reg_buf->b_ml.ml_line_count - lnum;
!     rex.reg_line_lbr = FALSE;
!     rex.reg_ic = rmp->rmm_ic;
!     rex.reg_icombine = FALSE;
!     rex.reg_maxcol = rmp->rmm_maxcol;
! 
      return bt_regexec_both(NULL, col, tm, timed_out);
  }
  
--- 4854,4860 ----
      proftime_T        *tm,            // timeout limit or NULL
      int               *timed_out)     // flag set on timeout or NULL
  {
!     init_regexec_multi(rmp, win, buf, lnum);
      return bt_regexec_both(NULL, col, tm, timed_out);
  }
  
*** ../vim-8.2.0259/src/regexp_nfa.c    2019-12-22 19:40:36.910100058 +0100
--- src/regexp_nfa.c    2020-02-15 22:42:40.104339546 +0100
***************
*** 7409,7425 ****
      proftime_T        *tm,            // timeout limit or NULL
      int               *timed_out)     // flag set on timeout or NULL
  {
!     rex.reg_match = NULL;
!     rex.reg_mmatch = rmp;
!     rex.reg_buf = buf;
!     rex.reg_win = win;
!     rex.reg_firstlnum = lnum;
!     rex.reg_maxline = rex.reg_buf->b_ml.ml_line_count - lnum;
!     rex.reg_line_lbr = FALSE;
!     rex.reg_ic = rmp->rmm_ic;
!     rex.reg_icombine = FALSE;
!     rex.reg_maxcol = rmp->rmm_maxcol;
! 
      return nfa_regexec_both(NULL, col, tm, timed_out);
  }
  
--- 7409,7415 ----
      proftime_T        *tm,            // timeout limit or NULL
      int               *timed_out)     // flag set on timeout or NULL
  {
!     init_regexec_multi(rmp, win, buf, lnum);
      return nfa_regexec_both(NULL, col, tm, timed_out);
  }
  
*** ../vim-8.2.0259/src/term.c  2020-02-08 14:22:49.448630165 +0100
--- src/term.c  2020-02-15 22:42:40.104339546 +0100
***************
*** 6390,6392 ****
--- 6390,6423 ----
  }
  #endif
  
+ /*
+  * Replace K_BS by <BS> and K_DEL by <DEL>
+  */
+     void
+ term_replace_bs_del_keycode(char_u *ta_buf, int ta_len, int len)
+ {
+     int               i;
+     int               c;
+ 
+     for (i = ta_len; i < ta_len + len; ++i)
+     {
+       if (ta_buf[i] == CSI && len - i > 2)
+       {
+           c = TERMCAP2KEY(ta_buf[i + 1], ta_buf[i + 2]);
+           if (c == K_DEL || c == K_KDEL || c == K_BS)
+           {
+               mch_memmove(ta_buf + i + 1, ta_buf + i + 3,
+                       (size_t)(len - i - 2));
+               if (c == K_DEL || c == K_KDEL)
+                   ta_buf[i] = DEL;
+               else
+                   ta_buf[i] = Ctrl_H;
+               len -= 2;
+           }
+       }
+       else if (ta_buf[i] == '\r')
+           ta_buf[i] = '\n';
+       if (has_mbyte)
+           i += (*mb_ptr2len_len)(ta_buf + i, ta_len + len - i) - 1;
+     }
+ }
*** ../vim-8.2.0259/src/version.c       2020-02-14 17:05:12.472074109 +0100
--- src/version.c       2020-02-15 23:00:28.220175154 +0100
***************
*** 744,745 ****
--- 744,747 ----
  {   /* Add new patch number below this line */
+ /**/
+     260,
  /**/

-- 
hundred-and-one symptoms of being an internet addict:
88. Every single time you press the 'Get mail' button...it does get new mail.

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
 \\\            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/202002152208.01FM8MKO020421%40masaka.moolenaar.net.

Raspunde prin e-mail lui