forked from aniani/vim
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".
This commit is contained in:
parent
94075b2b0e
commit
a9528b39a6
@ -5247,6 +5247,8 @@ maparg({name} [, {mode} [, {abbr} [, {dict}]]]) *maparg()*
|
|||||||
(|mapmode-ic|)
|
(|mapmode-ic|)
|
||||||
"sid" The script local ID, used for <sid> mappings
|
"sid" The script local ID, used for <sid> mappings
|
||||||
(|<SID>|).
|
(|<SID>|).
|
||||||
|
"scriptversion" The version of the script. 999999 for
|
||||||
|
|Vim9| script.
|
||||||
"lnum" The line number in "sid", zero if unknown.
|
"lnum" The line number in "sid", zero if unknown.
|
||||||
"nowait" Do not wait for other, longer mappings.
|
"nowait" Do not wait for other, longer mappings.
|
||||||
(|:map-<nowait>|).
|
(|:map-<nowait>|).
|
||||||
|
16
src/map.c
16
src/map.c
@ -222,6 +222,7 @@ map_add(
|
|||||||
#ifdef FEAT_EVAL
|
#ifdef FEAT_EVAL
|
||||||
int expr,
|
int expr,
|
||||||
scid_T sid, // -1 to use current_sctx
|
scid_T sid, // -1 to use current_sctx
|
||||||
|
int scriptversion,
|
||||||
linenr_T lnum,
|
linenr_T lnum,
|
||||||
#endif
|
#endif
|
||||||
int simplified)
|
int simplified)
|
||||||
@ -259,11 +260,11 @@ map_add(
|
|||||||
mp->m_simplified = simplified;
|
mp->m_simplified = simplified;
|
||||||
#ifdef FEAT_EVAL
|
#ifdef FEAT_EVAL
|
||||||
mp->m_expr = expr;
|
mp->m_expr = expr;
|
||||||
if (sid >= 0)
|
if (sid > 0)
|
||||||
{
|
{
|
||||||
mp->m_script_ctx.sc_sid = sid;
|
mp->m_script_ctx.sc_sid = sid;
|
||||||
mp->m_script_ctx.sc_lnum = lnum;
|
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
|
else
|
||||||
{
|
{
|
||||||
@ -844,7 +845,7 @@ do_map(
|
|||||||
if (map_add(map_table, abbr_table, keys, rhs, orig_rhs,
|
if (map_add(map_table, abbr_table, keys, rhs, orig_rhs,
|
||||||
noremap, nowait, silent, mode, abbrev,
|
noremap, nowait, silent, mode, abbrev,
|
||||||
#ifdef FEAT_EVAL
|
#ifdef FEAT_EVAL
|
||||||
expr, /* sid */ -1, /* lnum */ 0,
|
expr, /* sid */ -1, /* scriptversion */ 0, /* lnum */ 0,
|
||||||
#endif
|
#endif
|
||||||
did_simplify && keyround == 1) == FAIL)
|
did_simplify && keyround == 1) == FAIL)
|
||||||
{
|
{
|
||||||
@ -2302,6 +2303,8 @@ get_maparg(typval_T *argvars, typval_T *rettv, int exact)
|
|||||||
dict_add_number(dict, "expr", mp->m_expr ? 1L : 0L);
|
dict_add_number(dict, "expr", mp->m_expr ? 1L : 0L);
|
||||||
dict_add_number(dict, "silent", mp->m_silent ? 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, "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, "lnum", (long)mp->m_script_ctx.sc_lnum);
|
||||||
dict_add_number(dict, "buffer", (long)buffer_local);
|
dict_add_number(dict, "buffer", (long)buffer_local);
|
||||||
dict_add_number(dict, "nowait", mp->m_nowait ? 1L : 0L);
|
dict_add_number(dict, "nowait", mp->m_nowait ? 1L : 0L);
|
||||||
@ -2371,6 +2374,7 @@ f_mapset(typval_T *argvars, typval_T *rettv UNUSED)
|
|||||||
int silent;
|
int silent;
|
||||||
int buffer;
|
int buffer;
|
||||||
scid_T sid;
|
scid_T sid;
|
||||||
|
int scriptversion;
|
||||||
linenr_T lnum;
|
linenr_T lnum;
|
||||||
mapblock_T **map_table = maphash;
|
mapblock_T **map_table = maphash;
|
||||||
mapblock_T **abbr_table = &first_abbr;
|
mapblock_T **abbr_table = &first_abbr;
|
||||||
@ -2416,6 +2420,7 @@ f_mapset(typval_T *argvars, typval_T *rettv UNUSED)
|
|||||||
expr = dict_get_number(d, (char_u *)"expr") != 0;
|
expr = dict_get_number(d, (char_u *)"expr") != 0;
|
||||||
silent = dict_get_number(d, (char_u *)"silent") != 0;
|
silent = dict_get_number(d, (char_u *)"silent") != 0;
|
||||||
sid = dict_get_number(d, (char_u *)"sid");
|
sid = dict_get_number(d, (char_u *)"sid");
|
||||||
|
scriptversion = dict_get_number(d, (char_u *)"scriptversion");
|
||||||
lnum = dict_get_number(d, (char_u *)"lnum");
|
lnum = dict_get_number(d, (char_u *)"lnum");
|
||||||
buffer = dict_get_number(d, (char_u *)"buffer");
|
buffer = dict_get_number(d, (char_u *)"buffer");
|
||||||
nowait = dict_get_number(d, (char_u *)"nowait") != 0;
|
nowait = dict_get_number(d, (char_u *)"nowait") != 0;
|
||||||
@ -2446,10 +2451,11 @@ f_mapset(typval_T *argvars, typval_T *rettv UNUSED)
|
|||||||
vim_free(arg);
|
vim_free(arg);
|
||||||
|
|
||||||
(void)map_add(map_table, abbr_table, lhsraw, rhs, orig_rhs, noremap,
|
(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)
|
if (lhsrawalt != NULL)
|
||||||
(void)map_add(map_table, abbr_table, lhsrawalt, rhs, orig_rhs, noremap,
|
(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(keys_buf);
|
||||||
vim_free(arg_buf);
|
vim_free(arg_buf);
|
||||||
}
|
}
|
||||||
|
@ -18,26 +18,30 @@ func Test_maparg()
|
|||||||
call assert_equal("is<F4>foo", maparg('foo<C-V>'))
|
call assert_equal("is<F4>foo", maparg('foo<C-V>'))
|
||||||
call assert_equal({'silent': 0, 'noremap': 0, 'script': 0, 'lhs': 'foo<C-V>',
|
call assert_equal({'silent': 0, 'noremap': 0, 'script': 0, 'lhs': 'foo<C-V>',
|
||||||
\ 'lhsraw': "foo\x80\xfc\x04V", 'lhsrawalt': "foo\x16",
|
\ '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},
|
\ 'rhs': 'is<F4>foo', 'buffer': 0},
|
||||||
\ maparg('foo<C-V>', '', 0, 1))
|
\ maparg('foo<C-V>', '', 0, 1))
|
||||||
call assert_equal({'silent': 1, 'noremap': 1, 'script': 1, 'lhs': 'bar',
|
call assert_equal({'silent': 1, 'noremap': 1, 'script': 1, 'lhs': 'bar',
|
||||||
\ 'lhsraw': 'bar', 'mode': 'v',
|
\ '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},
|
\ 'rhs': 'isbar', 'buffer': 1},
|
||||||
\ 'bar'->maparg('', 0, 1))
|
\ 'bar'->maparg('', 0, 1))
|
||||||
let lnum = expand('<sflnum>')
|
let lnum = expand('<sflnum>')
|
||||||
map <buffer> <nowait> foo bar
|
map <buffer> <nowait> foo bar
|
||||||
call assert_equal({'silent': 0, 'noremap': 0, 'script': 0, 'lhs': 'foo',
|
call assert_equal({'silent': 0, 'noremap': 0, 'script': 0, 'lhs': 'foo',
|
||||||
\ 'lhsraw': 'foo', 'mode': ' ',
|
\ '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},
|
\ 'buffer': 1},
|
||||||
\ maparg('foo', '', 0, 1))
|
\ maparg('foo', '', 0, 1))
|
||||||
let lnum = expand('<sflnum>')
|
let lnum = expand('<sflnum>')
|
||||||
tmap baz foo
|
tmap baz foo
|
||||||
call assert_equal({'silent': 0, 'noremap': 0, 'script': 0, 'lhs': 'baz',
|
call assert_equal({'silent': 0, 'noremap': 0, 'script': 0, 'lhs': 'baz',
|
||||||
\ 'lhsraw': 'baz', 'mode': 't',
|
\ '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},
|
\ 'buffer': 0},
|
||||||
\ maparg('baz', 't', 0, 1))
|
\ maparg('baz', 't', 0, 1))
|
||||||
|
|
||||||
|
@ -750,6 +750,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
4140,
|
||||||
/**/
|
/**/
|
||||||
4139,
|
4139,
|
||||||
/**/
|
/**/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user