]> granicus.if.org Git - vim/commitdiff
patch 8.2.3252: duplicated code for adding buffer lines v8.2.3252
authorYegappan Lakshmanan <yegappan@yahoo.com>
Fri, 30 Jul 2021 19:32:45 +0000 (21:32 +0200)
committerBram Moolenaar <Bram@vim.org>
Fri, 30 Jul 2021 19:32:45 +0000 (21:32 +0200)
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)

src/evalbuffer.c
src/evalfunc.c
src/map.c
src/proto/map.pro
src/version.c

index 3fb037c5f10f09e120b01a19607fa18e81c44711..77acf8fe90a7add573ff6233df8d624bcbace3e6 100644 (file)
@@ -287,10 +287,10 @@ f_append(typval_T *argvars, typval_T *rettv)
 }
 
 /*
- * "appendbufline(buf, lnum, string/list)" function
+ * Set or append lines to a buffer.
  */
-    void
-f_appendbufline(typval_T *argvars, typval_T *rettv)
+    static void
+buf_set_append_line(typval_T *argvars, typval_T *rettv, int append)
 {
     linenr_T   lnum;
     buf_T      *buf;
@@ -307,10 +307,19 @@ f_appendbufline(typval_T *argvars, typval_T *rettv)
     else
     {
        lnum = tv_get_lnum_buf(&argvars[1], buf);
-       set_buffer_lines(buf, lnum, TRUE, &argvars[2], rettv);
+       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
  */
@@ -837,23 +846,7 @@ f_getline(typval_T *argvars, typval_T *rettv)
     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);
-    }
+    buf_set_append_line(argvars, rettv, FALSE);
 }
 
 /*
index 7fc1821c6cba1c890837e557c5b14c57ed409082..87b498a4967b1fefc40041a86f1677af2db3d343 100644 (file)
@@ -98,8 +98,6 @@ static void f_line2byte(typval_T *argvars, typval_T *rettv);
 #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);
@@ -6734,40 +6732,6 @@ f_luaeval(typval_T *argvars, typval_T *rettv)
 }
 #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()
index 09339a28c1c32b7b933dee88c9649df73e20a958..47874008c16944c560b9144ed51afe693bb29566 100644 (file)
--- a/src/map.c
+++ b/src/map.c
@@ -2184,7 +2184,7 @@ check_map(
     return NULL;
 }
 
-    void
+    static void
 get_maparg(typval_T *argvars, typval_T *rettv, int exact)
 {
     char_u     *keys;
@@ -2287,6 +2287,40 @@ get_maparg(typval_T *argvars, typval_T *rettv, int exact)
     vim_free(alt_keys_buf);
 }
 
+/*
+ * "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
  */
index 6da455a7e47163f58085a6aafc50399bf212a0fb..3592623543b47aba205fed5419299a46da0d6e0d 100644 (file)
@@ -17,7 +17,8 @@ int makemap(FILE *fd, buf_T *buf);
 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_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);
index 046d1e74445e31f531af7d1e5f59ff5bcea7ea6e..ebd2c565d25c901a259f49b007996a9eb1bbbfd4 100644 (file)
@@ -755,6 +755,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    3252,
 /**/
     3251,
 /**/