diff src/map.c @ 29318:fcf524e1e97e v9.0.0002

patch 9.0.0002: map functionality outside of map.c Commit: https://github.com/vim/vim/commit/c207fd2535717030d78f9b92839e5f2ac004cc78 Author: zeertzjq <zeertzjq@outlook.com> Date: Wed Jun 29 10:37:40 2022 +0100 patch 9.0.0002: map functionality outside of map.c Problem: Map functionality outside of map.c. Solution: Move f_hasmapto() to map.c. Rename a function. (closes https://github.com/vim/vim/issues/10611)
author Bram Moolenaar <Bram@vim.org>
date Wed, 29 Jun 2022 11:45:04 +0200
parents 35a30cb18005
children 827d9f2b7a71
line wrap: on
line diff
--- a/src/map.c
+++ b/src/map.c
@@ -908,13 +908,13 @@ get_map_mode(char_u **cmdp, int forceit)
 }
 
 /*
- * Clear all mappings or abbreviations.
- * 'abbr' should be FALSE for mappings, TRUE for abbreviations.
+ * Clear all mappings (":mapclear") or abbreviations (":abclear").
+ * "abbr" should be FALSE for mappings, TRUE for abbreviations.
  */
     static void
 map_clear(
     char_u	*cmdp,
-    char_u	*arg UNUSED,
+    char_u	*arg,
     int		forceit,
     int		abbr)
 {
@@ -929,14 +929,14 @@ map_clear(
     }
 
     mode = get_map_mode(&cmdp, forceit);
-    map_clear_int(curbuf, mode, local, abbr);
+    map_clear_mode(curbuf, mode, local, abbr);
 }
 
 /*
  * Clear all mappings in "mode".
  */
     void
-map_clear_int(
+map_clear_mode(
     buf_T	*buf,		// buffer for local mappings
     int		mode,		// mode in which to delete
     int		local,		// TRUE for buffer-local mappings
@@ -2273,6 +2273,40 @@ check_map(
 }
 
 /*
+ * "hasmapto()" function
+ */
+    void
+f_hasmapto(typval_T *argvars, typval_T *rettv)
+{
+    char_u	*name;
+    char_u	*mode;
+    char_u	buf[NUMBUFLEN];
+    int		abbr = FALSE;
+
+    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;
+
+    name = tv_get_string(&argvars[0]);
+    if (argvars[1].v_type == VAR_UNKNOWN)
+	mode = (char_u *)"nvo";
+    else
+    {
+	mode = tv_get_string_buf(&argvars[1], buf);
+	if (argvars[2].v_type != VAR_UNKNOWN)
+	    abbr = (int)tv_get_bool(&argvars[2]);
+    }
+
+    if (map_to_exists(name, mode, abbr))
+	rettv->vval.v_number = TRUE;
+    else
+	rettv->vval.v_number = FALSE;
+}
+
+/*
  * Fill in the empty dictionary with items as defined by maparg builtin.
  */
     static void