comparison src/map.c @ 27061:1a56c0252772 v8.2.4059

patch 8.2.4059: Vim9: an expression of a map cannot access script-local items Commit: https://github.com/vim/vim/commit/19db9e6ba710ca32f0f5e0c2ca2ba69f8228b833 Author: Bram Moolenaar <Bram@vim.org> Date: Tue Jan 11 11:58:19 2022 +0000 patch 8.2.4059: Vim9: an expression of a map cannot access script-local items Problem: Vim9: an expression of a map cannot access script-local items. (Maxim Kim) Solution: Use the script ID of where the map was defined.
author Bram Moolenaar <Bram@vim.org>
date Tue, 11 Jan 2022 13:00:06 +0100
parents 3631d2deb36c
children 0bb71ef751bb
comparison
equal deleted inserted replaced
27060:6f3ec6d0ef33 27061:1a56c0252772
258 mp->m_expr = expr; 258 mp->m_expr = expr;
259 if (sid >= 0) 259 if (sid >= 0)
260 { 260 {
261 mp->m_script_ctx.sc_sid = sid; 261 mp->m_script_ctx.sc_sid = sid;
262 mp->m_script_ctx.sc_lnum = lnum; 262 mp->m_script_ctx.sc_lnum = lnum;
263 mp->m_script_ctx.sc_version = in_vim9script() ? SCRIPT_VERSION_VIM9 : 0;
263 } 264 }
264 else 265 else
265 { 266 {
266 mp->m_script_ctx = current_sctx; 267 mp->m_script_ctx = current_sctx;
267 mp->m_script_ctx.sc_lnum += SOURCING_LNUM; 268 mp->m_script_ctx.sc_lnum += SOURCING_LNUM;
1563 // insert the last typed char 1564 // insert the last typed char
1564 (void)ins_typebuf(tb, 1, 0, TRUE, mp->m_silent); 1565 (void)ins_typebuf(tb, 1, 0, TRUE, mp->m_silent);
1565 } 1566 }
1566 #ifdef FEAT_EVAL 1567 #ifdef FEAT_EVAL
1567 if (mp->m_expr) 1568 if (mp->m_expr)
1568 s = eval_map_expr(mp->m_str, c); 1569 s = eval_map_expr(mp, c);
1569 else 1570 else
1570 #endif 1571 #endif
1571 s = mp->m_str; 1572 s = mp->m_str;
1572 if (s != NULL) 1573 if (s != NULL)
1573 { 1574 {
1598 * Evaluate the RHS of a mapping or abbreviations and take care of escaping 1599 * Evaluate the RHS of a mapping or abbreviations and take care of escaping
1599 * special characters. 1600 * special characters.
1600 */ 1601 */
1601 char_u * 1602 char_u *
1602 eval_map_expr( 1603 eval_map_expr(
1603 char_u *str, 1604 mapblock_T *mp,
1604 int c) // NUL or typed character for abbreviation 1605 int c) // NUL or typed character for abbreviation
1605 { 1606 {
1606 char_u *res; 1607 char_u *res;
1607 char_u *p; 1608 char_u *p;
1608 char_u *expr; 1609 char_u *expr;
1609 pos_T save_cursor; 1610 pos_T save_cursor;
1610 int save_msg_col; 1611 int save_msg_col;
1611 int save_msg_row; 1612 int save_msg_row;
1613 scid_T save_sctx_sid = current_sctx.sc_sid;
1614 int save_sctx_version = current_sctx.sc_version;
1612 1615
1613 // Remove escaping of CSI, because "str" is in a format to be used as 1616 // Remove escaping of CSI, because "str" is in a format to be used as
1614 // typeahead. 1617 // typeahead.
1615 expr = vim_strsave(str); 1618 expr = vim_strsave(mp->m_str);
1616 if (expr == NULL) 1619 if (expr == NULL)
1617 return NULL; 1620 return NULL;
1618 vim_unescape_csi(expr); 1621 vim_unescape_csi(expr);
1619 1622
1620 // Forbid changing text or using ":normal" to avoid most of the bad side 1623 // Forbid changing text or using ":normal" to avoid most of the bad side
1623 ++ex_normal_lock; 1626 ++ex_normal_lock;
1624 set_vim_var_char(c); // set v:char to the typed character 1627 set_vim_var_char(c); // set v:char to the typed character
1625 save_cursor = curwin->w_cursor; 1628 save_cursor = curwin->w_cursor;
1626 save_msg_col = msg_col; 1629 save_msg_col = msg_col;
1627 save_msg_row = msg_row; 1630 save_msg_row = msg_row;
1631 if (mp->m_script_ctx.sc_version == SCRIPT_VERSION_VIM9)
1632 {
1633 current_sctx.sc_sid = mp->m_script_ctx.sc_sid;
1634 current_sctx.sc_version = SCRIPT_VERSION_VIM9;
1635 }
1636
1637 // Note: the evaluation may make "mp" invalid.
1628 p = eval_to_string(expr, FALSE); 1638 p = eval_to_string(expr, FALSE);
1639
1629 --textwinlock; 1640 --textwinlock;
1630 --ex_normal_lock; 1641 --ex_normal_lock;
1631 curwin->w_cursor = save_cursor; 1642 curwin->w_cursor = save_cursor;
1632 msg_col = save_msg_col; 1643 msg_col = save_msg_col;
1633 msg_row = save_msg_row; 1644 msg_row = save_msg_row;
1645 current_sctx.sc_sid = save_sctx_sid;
1646 current_sctx.sc_version = save_sctx_version;
1634 1647
1635 vim_free(expr); 1648 vim_free(expr);
1636 1649
1637 if (p == NULL) 1650 if (p == NULL)
1638 return NULL; 1651 return NULL;