patch 9.1.1402: multi-byte mappings not properly stored in session file

Commit: 
https://github.com/vim/vim/commit/5b07aff2f665f290f2ec4a5e6bcf9873a178149a
Author: GuyBrush <miguel.ba...@live.com>
Date:   Thu May 22 22:19:25 2025 +0200

    patch 9.1.1402: multi-byte mappings not properly stored in session file
    
    Problem:  multi-byte mappings not properly stored in session file
    Solution: unescape the mapping before writing out the mapping, prefer
              single-byte mapping name if possible (Miguel Barro)
    
    closes: #17355
    
    Signed-off-by: GuyBrush <miguel.ba...@live.com>
    Signed-off-by: Christian Brabandt <c...@256bit.org>

diff --git a/src/map.c b/src/map.c
index 209d9d237..2d378b55c 100644
--- a/src/map.c
+++ b/src/map.c
@@ -2180,7 +2180,18 @@ put_escstr(FILE *fd, char_u *strstart, int what)
            {
                modifiers = str[2];
                str += 3;
-               c = *str;
+
+               // Modifiers can be applied too to multi-byte characters.
+               p = mb_unescape(&str);
+
+               if (p == NULL)
+                   c = *str;
+               else
+               {
+                   // retrieve codepoint (character number) from unescaped 
string
+                   c = (*mb_ptr2char)(p);
+                   --str;
+               }
            }
            if (c == K_SPECIAL)
            {
diff --git a/src/misc2.c b/src/misc2.c
index 79125771e..11eb51bcf 100644
--- a/src/misc2.c
+++ b/src/misc2.c
@@ -1213,7 +1213,7 @@ handle_x_keys(int key)
 get_special_key_name(int c, int modifiers)
 {
     static char_u string[MAX_KEY_NAME_LEN + 1];
-    int            i, idx;
+    int            i, idx, len;
     int            table_idx;
 
     string[0] = '<';
@@ -1286,10 +1286,11 @@ get_special_key_name(int c, int modifiers)
        // Not a special key, only modifiers, output directly
        else
        {
-           if (has_mbyte && (*mb_char2len)(c) > 1)
-               idx += (*mb_char2bytes)(c, string + idx);
-           else if (vim_isprintc(c))
+           len = (*mb_char2len)(c);
+           if (len == 1 && vim_isprintc(c))
                string[idx++] = c;
+           else if (has_mbyte && len > 1)
+               idx += (*mb_char2bytes)(c, string + idx);
            else
            {
                char_u  *s = transchar(c);
diff --git a/src/testdir/test_mksession_utf8.vim 
b/src/testdir/test_mksession_utf8.vim
index 4e593cc21..36cb38bea 100644
--- a/src/testdir/test_mksession_utf8.vim
+++ b/src/testdir/test_mksession_utf8.vim
@@ -102,4 +102,35 @@ func Test_mksession_utf8()
   set sessionoptions& splitbelow& fileencoding&
 endfunc
 
+func Test_session_multibyte_mappings()
+
+  " some characters readily available on european keyboards
+  let entries = [
+        \ ['n', '<M-ç>', '<M-ç>'],
+        \ ['n', '<M-º>', '<M-º>'],
+        \ ['n', '<M-¡>', '<M-¡>'],
+        \ ]
+  for entry in entries
+    exe entry[0] .. 'map ' .. entry[1] .. ' ' .. entry[2]
+  endfor
+
+  mkvimrc Xtestvimrc
+
+  nmapclear
+
+  for entry in entries
+    call assert_equal('', maparg(entry[1], entry[0]))
+  endfor
+
+  source Xtestvimrc
+
+  for entry in entries
+    call assert_equal(entry[2], maparg(entry[1], entry[0]))
+  endfor
+
+  nmapclear
+
+  call delete('Xtestvimrc')
+endfunc
+
 " vim: shiftwidth=2 sts=2 expandtab
diff --git a/src/version.c b/src/version.c
index 252c1437b..1f5cd0222 100644
--- a/src/version.c
+++ b/src/version.c
@@ -709,6 +709,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1402,
 /**/
     1401,
 /**/

-- 
-- 
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 vim_dev+unsubscr...@googlegroups.com.
To view this discussion visit 
https://groups.google.com/d/msgid/vim_dev/E1uICmm-009NmK-Eb%40256bit.org.

Raspunde prin e-mail lui