Patch 8.2.2804
Problem:    Setting buffer local mapping with mapset() changes global mapping.
Solution:   Only set the local mapping. (closes #8143)
Files:      src/map.c, src/testdir/test_maparg.vim


*** ../vim-8.2.2803/src/map.c   2021-01-03 19:51:01.396063220 +0100
--- src/map.c   2021-04-24 13:08:36.847124820 +0200
***************
*** 2295,2300 ****
--- 2295,2301 ----
      int               noremap;
      int               expr;
      int               silent;
+     int               buffer;
      scid_T    sid;
      linenr_T  lnum;
      mapblock_T        **map_table = maphash;
***************
*** 2336,2353 ****
      silent = dict_get_number(d, (char_u *)"silent") != 0;
      sid = dict_get_number(d, (char_u *)"sid");
      lnum = dict_get_number(d, (char_u *)"lnum");
!     if (dict_get_number(d, (char_u *)"buffer"))
      {
        map_table = curbuf->b_maphash;
        abbr_table = &curbuf->b_first_abbr;
      }
-     nowait = dict_get_number(d, (char_u *)"nowait") != 0;
-     // mode from the dict is not used
  
      // Delete any existing mapping for this lhs and mode.
!     arg = vim_strsave(lhs);
!     if (arg == NULL)
!       return;
      do_map(1, arg, mode, is_abbr);
      vim_free(arg);
  
--- 2337,2367 ----
      silent = dict_get_number(d, (char_u *)"silent") != 0;
      sid = dict_get_number(d, (char_u *)"sid");
      lnum = dict_get_number(d, (char_u *)"lnum");
!     buffer = dict_get_number(d, (char_u *)"buffer");
!     nowait = dict_get_number(d, (char_u *)"nowait") != 0;
!     // mode from the dict is not used
! 
!     if (buffer)
      {
        map_table = curbuf->b_maphash;
        abbr_table = &curbuf->b_first_abbr;
      }
  
      // Delete any existing mapping for this lhs and mode.
!     if (buffer)
!     {
!       arg = alloc(STRLEN(lhs) + STRLEN("<buffer>") + 1);
!       if (arg == NULL)
!           return;
!       STRCPY(arg, "<buffer>");
!       STRCPY(arg + 8, lhs);
!     }
!     else
!     {
!       arg = vim_strsave(lhs);
!       if (arg == NULL)
!           return;
!     }
      do_map(1, arg, mode, is_abbr);
      vim_free(arg);
  
*** ../vim-8.2.2803/src/testdir/test_maparg.vim 2021-02-20 19:21:31.955986987 
+0100
--- src/testdir/test_maparg.vim 2021-04-24 13:09:51.890887805 +0200
***************
*** 254,259 ****
--- 254,280 ----
    endif
  endfunc
  
+ func Test_map_local()
+   nmap a global
+   nmap <buffer>a local
+ 
+   let prev_map_list = split(execute('nmap a'), "\n")
+   call assert_match('n\s*a\s*@local', prev_map_list[0])
+   call assert_match('n\s*a\s*global', prev_map_list[1])
+ 
+   let mapping = maparg('a', 'n', 0, 1)
+   call assert_equal(1, mapping.buffer)
+   let mapping.rhs = 'new_local'
+   call mapset('n', 0, mapping)
+ 
+   " Check that the global mapping is left untouched.
+   let map_list = split(execute('nmap a'), "\n")
+   call assert_match('n\s*a\s*@new_local', map_list[0])
+   call assert_match('n\s*a\s*global', map_list[1])
+ 
+   nunmap a
+ endfunc
+ 
  func Test_map_restore()
    " Test restoring map with alternate keycode
    nmap <C-B> back
*** ../vim-8.2.2803/src/version.c       2021-04-23 21:01:30.649469081 +0200
--- src/version.c       2021-04-24 13:01:02.176510445 +0200
***************
*** 752,753 ****
--- 752,755 ----
  {   /* Add new patch number below this line */
+ /**/
+     2804,
  /**/

-- 
Microsoft says that MS-Windows is much better for you than Linux.
That's like the Pope saying that catholicism is much better for
you than protestantism.

 /// 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/202104241113.13OBDFL31877224%40masaka.moolenaar.net.

Raspunde prin e-mail lui