diff src/map.c @ 28602:398c5b3211f9 v8.2.4825

patch 8.2.4825: can only get a list of mappings Commit: https://github.com/vim/vim/commit/09661203ecefbee6a6f09438afcff1843e9dbfb4 Author: Ernie Rael <errael@raelity.com> Date: Mon Apr 25 14:40:44 2022 +0100 patch 8.2.4825: can only get a list of mappings Problem: Can only get a list of mappings. Solution: Add the optional {abbr} argument. (Ernie Rael, closes https://github.com/vim/vim/issues/10277) Rename to maplist(). Rename test file.
author Bram Moolenaar <Bram@vim.org>
date Mon, 25 Apr 2022 15:45:03 +0200
parents 17251b82b69a
children 893af4a8fc08
line wrap: on
line diff
--- a/src/map.c
+++ b/src/map.c
@@ -2389,10 +2389,10 @@ get_maparg(typval_T *argvars, typval_T *
 }
 
 /*
- * "getmappings()" function
+ * "maplist()" function
  */
     void
-f_getmappings(typval_T *argvars UNUSED, typval_T *rettv)
+f_maplist(typval_T *argvars UNUSED, typval_T *rettv)
 {
     dict_T	*d;
     mapblock_T	*mp;
@@ -2402,6 +2402,12 @@ f_getmappings(typval_T *argvars UNUSED, 
     int		hash;
     char_u	*lhs;
     const int	flags = REPTERM_FROM_PART | REPTERM_DO_LT;
+    int		abbr = FALSE;
+
+    if (in_vim9script() && check_for_opt_bool_arg(argvars, 0) == FAIL)
+	return;
+    if (argvars[0].v_type != VAR_UNKNOWN)
+	abbr = tv_get_bool(&argvars[0]);
 
     if (rettv_list_alloc(rettv) != OK)
 	return;
@@ -2413,7 +2419,16 @@ f_getmappings(typval_T *argvars UNUSED, 
     {
 	for (hash = 0; hash < 256; ++hash)
 	{
-	    if (buffer_local)
+	    if (abbr)
+	    {
+		if (hash > 0)		// there is only one abbr list
+		    break;
+		if (buffer_local)
+		    mp = curbuf->b_first_abbr;
+		else
+		    mp = first_abbr;
+	    }
+	    else if (buffer_local)
 		mp = curbuf->b_maphash[hash];
 	    else
 		mp = maphash[hash];