Mercurial > vim
changeset 27223:ea2b4cb4515b v8.2.4140
patch 8.2.4140: maparg() does not indicate the type of script
Commit: https://github.com/vim/vim/commit/a9528b39a666dbaa026320f73bae4b1628a7fe51
Author: Bram Moolenaar <Bram@vim.org>
Date: Tue Jan 18 20:51:35 2022 +0000
patch 8.2.4140: maparg() does not indicate the type of script
Problem: maparg() does not indicate the type of script where it was defined.
Solution: Add "scriptversion".
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Tue, 18 Jan 2022 22:00:05 +0100 |
parents | 20f098f8b3e6 |
children | 1af153e99343 |
files | runtime/doc/builtin.txt src/map.c src/testdir/test_maparg.vim src/version.c |
diffstat | 4 files changed, 23 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/runtime/doc/builtin.txt +++ b/runtime/doc/builtin.txt @@ -5247,6 +5247,8 @@ maparg({name} [, {mode} [, {abbr} [, {di (|mapmode-ic|) "sid" The script local ID, used for <sid> mappings (|<SID>|). + "scriptversion" The version of the script. 999999 for + |Vim9| script. "lnum" The line number in "sid", zero if unknown. "nowait" Do not wait for other, longer mappings. (|:map-<nowait>|).
--- a/src/map.c +++ b/src/map.c @@ -222,6 +222,7 @@ map_add( #ifdef FEAT_EVAL int expr, scid_T sid, // -1 to use current_sctx + int scriptversion, linenr_T lnum, #endif int simplified) @@ -259,11 +260,11 @@ map_add( mp->m_simplified = simplified; #ifdef FEAT_EVAL mp->m_expr = expr; - if (sid >= 0) + if (sid > 0) { mp->m_script_ctx.sc_sid = sid; mp->m_script_ctx.sc_lnum = lnum; - mp->m_script_ctx.sc_version = in_vim9script() ? SCRIPT_VERSION_VIM9 : 0; + mp->m_script_ctx.sc_version = scriptversion; } else { @@ -844,7 +845,7 @@ do_map( if (map_add(map_table, abbr_table, keys, rhs, orig_rhs, noremap, nowait, silent, mode, abbrev, #ifdef FEAT_EVAL - expr, /* sid */ -1, /* lnum */ 0, + expr, /* sid */ -1, /* scriptversion */ 0, /* lnum */ 0, #endif did_simplify && keyround == 1) == FAIL) { @@ -2302,6 +2303,8 @@ get_maparg(typval_T *argvars, typval_T * dict_add_number(dict, "expr", mp->m_expr ? 1L : 0L); dict_add_number(dict, "silent", mp->m_silent ? 1L : 0L); dict_add_number(dict, "sid", (long)mp->m_script_ctx.sc_sid); + dict_add_number(dict, "scriptversion", + (long)mp->m_script_ctx.sc_version); dict_add_number(dict, "lnum", (long)mp->m_script_ctx.sc_lnum); dict_add_number(dict, "buffer", (long)buffer_local); dict_add_number(dict, "nowait", mp->m_nowait ? 1L : 0L); @@ -2371,6 +2374,7 @@ f_mapset(typval_T *argvars, typval_T *re int silent; int buffer; scid_T sid; + int scriptversion; linenr_T lnum; mapblock_T **map_table = maphash; mapblock_T **abbr_table = &first_abbr; @@ -2416,6 +2420,7 @@ f_mapset(typval_T *argvars, typval_T *re expr = dict_get_number(d, (char_u *)"expr") != 0; silent = dict_get_number(d, (char_u *)"silent") != 0; sid = dict_get_number(d, (char_u *)"sid"); + scriptversion = dict_get_number(d, (char_u *)"scriptversion"); 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; @@ -2446,10 +2451,11 @@ f_mapset(typval_T *argvars, typval_T *re vim_free(arg); (void)map_add(map_table, abbr_table, lhsraw, rhs, orig_rhs, noremap, - nowait, silent, mode, is_abbr, expr, sid, lnum, 0); + nowait, silent, mode, is_abbr, expr, sid, scriptversion, lnum, 0); if (lhsrawalt != NULL) (void)map_add(map_table, abbr_table, lhsrawalt, rhs, orig_rhs, noremap, - nowait, silent, mode, is_abbr, expr, sid, lnum, 1); + nowait, silent, mode, is_abbr, expr, sid, scriptversion, + lnum, 1); vim_free(keys_buf); vim_free(arg_buf); }
--- a/src/testdir/test_maparg.vim +++ b/src/testdir/test_maparg.vim @@ -18,26 +18,30 @@ func Test_maparg() call assert_equal("is<F4>foo", maparg('foo<C-V>')) call assert_equal({'silent': 0, 'noremap': 0, 'script': 0, 'lhs': 'foo<C-V>', \ 'lhsraw': "foo\x80\xfc\x04V", 'lhsrawalt': "foo\x16", - \ 'mode': ' ', 'nowait': 0, 'expr': 0, 'sid': sid, 'lnum': lnum + 1, + \ 'mode': ' ', 'nowait': 0, 'expr': 0, 'sid': sid, 'scriptversion': 1, + \ 'lnum': lnum + 1, \ 'rhs': 'is<F4>foo', 'buffer': 0}, \ maparg('foo<C-V>', '', 0, 1)) call assert_equal({'silent': 1, 'noremap': 1, 'script': 1, 'lhs': 'bar', \ 'lhsraw': 'bar', 'mode': 'v', - \ 'nowait': 0, 'expr': 1, 'sid': sid, 'lnum': lnum + 2, + \ 'nowait': 0, 'expr': 1, 'sid': sid, 'scriptversion': 1, + \ 'lnum': lnum + 2, \ 'rhs': 'isbar', 'buffer': 1}, \ 'bar'->maparg('', 0, 1)) let lnum = expand('<sflnum>') map <buffer> <nowait> foo bar call assert_equal({'silent': 0, 'noremap': 0, 'script': 0, 'lhs': 'foo', \ 'lhsraw': 'foo', 'mode': ' ', - \ 'nowait': 1, 'expr': 0, 'sid': sid, 'lnum': lnum + 1, 'rhs': 'bar', + \ 'nowait': 1, 'expr': 0, 'sid': sid, 'scriptversion': 1, + \ 'lnum': lnum + 1, 'rhs': 'bar', \ 'buffer': 1}, \ maparg('foo', '', 0, 1)) let lnum = expand('<sflnum>') tmap baz foo call assert_equal({'silent': 0, 'noremap': 0, 'script': 0, 'lhs': 'baz', \ 'lhsraw': 'baz', 'mode': 't', - \ 'nowait': 0, 'expr': 0, 'sid': sid, 'lnum': lnum + 1, 'rhs': 'foo', + \ 'nowait': 0, 'expr': 0, 'sid': sid, 'scriptversion': 1, + \ 'lnum': lnum + 1, 'rhs': 'foo', \ 'buffer': 0}, \ maparg('baz', 't', 0, 1))