Patch 8.2.3252
Problem:    Duplicated code for adding buffer lines.
Solution:   Move code to a common function.  Also move map functions to map.c.
            (Yegappan Lakshmanan, closes #8665)
Files:      src/evalbuffer.c, src/evalfunc.c, src/map.c, src/proto/map.pro


*** ../vim-8.2.3251/src/evalbuffer.c    2021-07-27 22:00:39.741712405 +0200
--- src/evalbuffer.c    2021-07-30 21:25:39.877259730 +0200
***************
*** 287,296 ****
  }
  
  /*
!  * "appendbufline(buf, lnum, string/list)" function
   */
!     void
! f_appendbufline(typval_T *argvars, typval_T *rettv)
  {
      linenr_T  lnum;
      buf_T     *buf;
--- 287,296 ----
  }
  
  /*
!  * Set or append lines to a buffer.
   */
!     static void
! buf_set_append_line(typval_T *argvars, typval_T *rettv, int append)
  {
      linenr_T  lnum;
      buf_T     *buf;
***************
*** 307,317 ****
      else
      {
        lnum = tv_get_lnum_buf(&argvars[1], buf);
!       set_buffer_lines(buf, lnum, TRUE, &argvars[2], rettv);
      }
  }
  
  /*
   * "bufadd(expr)" function
   */
      void
--- 307,326 ----
      else
      {
        lnum = tv_get_lnum_buf(&argvars[1], buf);
!       set_buffer_lines(buf, lnum, append, &argvars[2], rettv);
      }
  }
  
  /*
+  * "appendbufline(buf, lnum, string/list)" function
+  */
+     void
+ f_appendbufline(typval_T *argvars, typval_T *rettv)
+ {
+     buf_set_append_line(argvars, rettv, TRUE);
+ }
+ 
+ /*
   * "bufadd(expr)" function
   */
      void
***************
*** 837,859 ****
      void
  f_setbufline(typval_T *argvars, typval_T *rettv)
  {
!     linenr_T  lnum;
!     buf_T     *buf;
! 
!     if (in_vim9script()
!           && (check_for_buffer_arg(argvars, 0) == FAIL
!               || check_for_lnum_arg(argvars, 1) == FAIL
!               || check_for_string_or_number_or_list_arg(argvars, 2) == FAIL))
!       return;
! 
!     buf = tv_get_buf(&argvars[0], FALSE);
!     if (buf == NULL)
!       rettv->vval.v_number = 1; // FAIL
!     else
!     {
!       lnum = tv_get_lnum_buf(&argvars[1], buf);
!       set_buffer_lines(buf, lnum, FALSE, &argvars[2], rettv);
!     }
  }
  
  /*
--- 846,852 ----
      void
  f_setbufline(typval_T *argvars, typval_T *rettv)
  {
!     buf_set_append_line(argvars, rettv, FALSE);
  }
  
  /*
*** ../vim-8.2.3251/src/evalfunc.c      2021-07-27 22:00:39.741712405 +0200
--- src/evalfunc.c      2021-07-30 21:25:39.877259730 +0200
***************
*** 98,105 ****
  #ifdef FEAT_LUA
  static void f_luaeval(typval_T *argvars, typval_T *rettv);
  #endif
- static void f_maparg(typval_T *argvars, typval_T *rettv);
- static void f_mapcheck(typval_T *argvars, typval_T *rettv);
  static void f_match(typval_T *argvars, typval_T *rettv);
  static void f_matchend(typval_T *argvars, typval_T *rettv);
  static void f_matchlist(typval_T *argvars, typval_T *rettv);
--- 98,103 ----
***************
*** 6734,6773 ****
  }
  #endif
  
- /*
-  * "maparg()" function
-  */
-     static void
- f_maparg(typval_T *argvars, typval_T *rettv)
- {
-     if (in_vim9script()
-           && (check_for_string_arg(argvars, 0) == FAIL
-               || check_for_opt_string_arg(argvars, 1) == FAIL
-               || (argvars[1].v_type != VAR_UNKNOWN
-                   && (check_for_opt_bool_arg(argvars, 2) == FAIL
-                       || (argvars[2].v_type != VAR_UNKNOWN
-                           && check_for_opt_bool_arg(argvars, 3) == FAIL)))))
-               return;
- 
-     get_maparg(argvars, rettv, TRUE);
- }
- 
- /*
-  * "mapcheck()" function
-  */
-     static void
- f_mapcheck(typval_T *argvars, typval_T *rettv)
- {
-     if (in_vim9script()
-           && (check_for_string_arg(argvars, 0) == FAIL
-               || check_for_opt_string_arg(argvars, 1) == FAIL
-               || (argvars[1].v_type != VAR_UNKNOWN
-                   && check_for_opt_bool_arg(argvars, 2) == FAIL)))
-       return;
- 
-     get_maparg(argvars, rettv, FALSE);
- }
- 
  typedef enum
  {
      MATCH_END,            // matchend()
--- 6732,6737 ----
*** ../vim-8.2.3251/src/map.c   2021-07-20 21:07:32.964058857 +0200
--- src/map.c   2021-07-30 21:25:39.877259730 +0200
***************
*** 2184,2190 ****
      return NULL;
  }
  
!     void
  get_maparg(typval_T *argvars, typval_T *rettv, int exact)
  {
      char_u    *keys;
--- 2184,2190 ----
      return NULL;
  }
  
!     static void
  get_maparg(typval_T *argvars, typval_T *rettv, int exact)
  {
      char_u    *keys;
***************
*** 2288,2293 ****
--- 2288,2327 ----
  }
  
  /*
+  * "maparg()" function
+  */
+     void
+ f_maparg(typval_T *argvars, typval_T *rettv)
+ {
+     if (in_vim9script()
+           && (check_for_string_arg(argvars, 0) == FAIL
+               || check_for_opt_string_arg(argvars, 1) == FAIL
+               || (argvars[1].v_type != VAR_UNKNOWN
+                   && (check_for_opt_bool_arg(argvars, 2) == FAIL
+                       || (argvars[2].v_type != VAR_UNKNOWN
+                           && check_for_opt_bool_arg(argvars, 3) == FAIL)))))
+               return;
+ 
+     get_maparg(argvars, rettv, TRUE);
+ }
+ 
+ /*
+  * "mapcheck()" function
+  */
+     void
+ f_mapcheck(typval_T *argvars, typval_T *rettv)
+ {
+     if (in_vim9script()
+           && (check_for_string_arg(argvars, 0) == FAIL
+               || check_for_opt_string_arg(argvars, 1) == FAIL
+               || (argvars[1].v_type != VAR_UNKNOWN
+                   && check_for_opt_bool_arg(argvars, 2) == FAIL)))
+       return;
+ 
+     get_maparg(argvars, rettv, FALSE);
+ }
+ 
+ /*
   * "mapset()" function
   */
      void
*** ../vim-8.2.3251/src/proto/map.pro   2020-05-22 13:09:55.320226061 +0200
--- src/proto/map.pro   2021-07-30 21:30:50.692885989 +0200
***************
*** 17,23 ****
  int put_escstr(FILE *fd, char_u *strstart, int what);
  void check_map_keycodes(void);
  char_u *check_map(char_u *keys, int mode, int exact, int ign_mod, int abbr, 
mapblock_T **mp_ptr, int *local_ptr);
! void get_maparg(typval_T *argvars, typval_T *rettv, int exact);
  void f_mapset(typval_T *argvars, typval_T *rettv);
  void init_mappings(void);
  void add_map(char_u *map, int mode);
--- 17,24 ----
  int put_escstr(FILE *fd, char_u *strstart, int what);
  void check_map_keycodes(void);
  char_u *check_map(char_u *keys, int mode, int exact, int ign_mod, int abbr, 
mapblock_T **mp_ptr, int *local_ptr);
! void f_maparg(typval_T *argvars, typval_T *rettv);
! void f_mapcheck(typval_T *argvars, typval_T *rettv);
  void f_mapset(typval_T *argvars, typval_T *rettv);
  void init_mappings(void);
  void add_map(char_u *map, int mode);
*** ../vim-8.2.3251/src/version.c       2021-07-30 21:17:59.142134917 +0200
--- src/version.c       2021-07-30 21:27:17.605158755 +0200
***************
*** 757,758 ****
--- 757,760 ----
  {   /* Add new patch number below this line */
+ /**/
+     3252,
  /**/

-- 
Facepalm reply #3: "I had a great time in Manhattan" "I thought you were
going to New York?"

 /// 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/202107301933.16UJXHO12483517%40masaka.moolenaar.net.

Raspunde prin e-mail lui