0
0
mirror of https://github.com/vim/vim.git synced 2025-07-26 11:04:33 -04:00

Merge 2415443f5111e99178c7957b372981193046c1ae into a494ce1c64a2637719a5c1339abf19ec7c48089c

This commit is contained in:
Maxim Kim 2025-07-04 11:10:32 +02:00 committed by GitHub
commit fc1694c82c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 58 additions and 1 deletions

View File

@ -1420,7 +1420,8 @@ The output of ":mksession" is like ":mkvimrc", but additional commands are
added to the file. Which ones depends on the 'sessionoptions' option. The
resulting file, when executed with a ":source" command:
1. Restores global mappings and options, if 'sessionoptions' contains
"options". Script-local mappings will not be written.
"options". Script-local mappings and mappings defined in vim9script context
will not be written.
2. Restores global variables that start with an uppercase letter and contain
at least one lowercase letter, if 'sessionoptions' contains "globals".
3. Closes all windows in the current tab page, except the current one; closes

View File

@ -1968,6 +1968,13 @@ makemap(
for ( ; mp; mp = mp->m_next)
{
#ifdef FEAT_EVAL
// skip mappings defined in vim9script context
if (mp->m_script_ctx.sc_version == SCRIPT_VERSION_VIM9)
continue;
#endif
// skip script-local mappings
if (mp->m_noremap == REMAP_SCRIPT)
continue;

View File

@ -1335,4 +1335,53 @@ func Test_mkview_default_home()
endif
endfunc
" Test vim mappings
func Test_mksession_vim_mappings()
call s:ClearMappings()
let lines =<< trim END
nmap <space>q2 <scriptcmd>call FormatRange(1, 100)<cr>
map <space>q1 <cmd>echo "hello world"<cr>
cnoremap <expr> <space>q3 getcmdtype() =~ '[/?]' ? '.\{-}' : "<space>"
END
new
call append(0, lines)
:%source
mksession! mappings_test
call s:ClearMappings()
let li = filter(readfile('mappings_test'), {_, val -> val =~# '^\s*\(n\|cnore\)\?map'})
call assert_equal(
\ ["map \x16 q1 <Cmd>echo \"hello world\"\x16",
\ "nmap \x16 q2 <ScriptCmd>call FormatRange(1, 100)\x16",
\ "cnoremap <expr> \x16 q3 getcmdtype() =~ '[/?]' ? '.\\{-}' : \" \""],
\ li)
bwipe!
call delete('mappings_test')
endfunc
" Test vim9 mappings
func Test_mksession_no_vim9_mappings()
call s:ClearMappings()
let lines =<< trim END
vim9script
import autoload "dist/json.vim"
map <space>q1 <cmd>echo "hello world"<cr>
nmap <space>q2 <scriptcmd>json.FormatRange(1, 100)<cr>
cnoremap <expr> <space>q3 getcmdtype() =~ '[/?]' ? '.\{-}' : "<space>"
END
new
call append(0, lines)
:%source
mksession! mappings_test_v9
call s:ClearMappings()
let li = filter(readfile('mappings_test_v9'), 'v:val =~# "^\\s*map|nmap|cnoremap"')
call assert_equal([], li)
bwipe!
call delete('mappings_test_v9')
endfunc
" vim: shiftwidth=2 sts=2 expandtab