Mercurial > vim
comparison src/usercmd.c @ 28181:2961a18f9cbf v8.2.4616
patch 8.2.4616: Vim9: Declarations in a {} block of a user command remain
Commit: https://github.com/vim/vim/commit/98b7fe725ec342d28d7c86293098b233c57c4af9
Author: Bram Moolenaar <Bram@vim.org>
Date: Wed Mar 23 21:36:27 2022 +0000
patch 8.2.4616: Vim9: Declarations in a {} block of a user command remain
Problem: Vim9: Declarations in a {} block of a user command do not use Vim9
rules if defined in a legacy script. (Yegappan Lakshmanan)
Solution: Pretend the script is Vim9 script.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Wed, 23 Mar 2022 22:45:06 +0100 |
parents | b737bfa876c5 |
children | 2b595cee4c85 |
comparison
equal
deleted
inserted
replaced
28180:d56d48f416b1 | 28181:2961a18f9cbf |
---|---|
20 char_u *uc_rep; // The command's replacement string | 20 char_u *uc_rep; // The command's replacement string |
21 long uc_def; // The default value for a range/count | 21 long uc_def; // The default value for a range/count |
22 int uc_compl; // completion type | 22 int uc_compl; // completion type |
23 cmd_addr_T uc_addr_type; // The command's address type | 23 cmd_addr_T uc_addr_type; // The command's address type |
24 sctx_T uc_script_ctx; // SCTX where the command was defined | 24 sctx_T uc_script_ctx; // SCTX where the command was defined |
25 int uc_flags; // some UC_ flags | |
25 # ifdef FEAT_EVAL | 26 # ifdef FEAT_EVAL |
26 char_u *uc_compl_arg; // completion argument if any | 27 char_u *uc_compl_arg; // completion argument if any |
27 # endif | 28 # endif |
28 } ucmd_T; | 29 } ucmd_T; |
29 | 30 |
1036 cmd->uc_def = def; | 1037 cmd->uc_def = def; |
1037 cmd->uc_compl = compl; | 1038 cmd->uc_compl = compl; |
1038 cmd->uc_script_ctx = current_sctx; | 1039 cmd->uc_script_ctx = current_sctx; |
1039 if (flags & UC_VIM9) | 1040 if (flags & UC_VIM9) |
1040 cmd->uc_script_ctx.sc_version = SCRIPT_VERSION_VIM9; | 1041 cmd->uc_script_ctx.sc_version = SCRIPT_VERSION_VIM9; |
1042 cmd->uc_flags = flags & UC_VIM9; | |
1041 #ifdef FEAT_EVAL | 1043 #ifdef FEAT_EVAL |
1042 cmd->uc_script_ctx.sc_lnum += SOURCING_LNUM; | 1044 cmd->uc_script_ctx.sc_lnum += SOURCING_LNUM; |
1043 cmd->uc_compl_arg = compl_arg; | 1045 cmd->uc_compl_arg = compl_arg; |
1044 #endif | 1046 #endif |
1045 cmd->uc_addr_type = addr_type; | 1047 cmd->uc_addr_type = addr_type; |
1723 size_t split_len = 0; | 1725 size_t split_len = 0; |
1724 char_u *split_buf = NULL; | 1726 char_u *split_buf = NULL; |
1725 ucmd_T *cmd; | 1727 ucmd_T *cmd; |
1726 sctx_T save_current_sctx; | 1728 sctx_T save_current_sctx; |
1727 int restore_current_sctx = FALSE; | 1729 int restore_current_sctx = FALSE; |
1730 #ifdef FEAT_EVAL | |
1731 int restore_script_version = 0; | |
1732 #endif | |
1728 | 1733 |
1729 if (eap->cmdidx == CMD_USER) | 1734 if (eap->cmdidx == CMD_USER) |
1730 cmd = USER_CMD(eap->useridx); | 1735 cmd = USER_CMD(eap->useridx); |
1731 else | 1736 else |
1732 cmd = USER_CMD_GA(&curbuf->b_ucmds, eap->useridx); | 1737 cmd = USER_CMD_GA(&curbuf->b_ucmds, eap->useridx); |
1828 restore_current_sctx = TRUE; | 1833 restore_current_sctx = TRUE; |
1829 save_current_sctx = current_sctx; | 1834 save_current_sctx = current_sctx; |
1830 current_sctx.sc_version = cmd->uc_script_ctx.sc_version; | 1835 current_sctx.sc_version = cmd->uc_script_ctx.sc_version; |
1831 #ifdef FEAT_EVAL | 1836 #ifdef FEAT_EVAL |
1832 current_sctx.sc_sid = cmd->uc_script_ctx.sc_sid; | 1837 current_sctx.sc_sid = cmd->uc_script_ctx.sc_sid; |
1838 if (cmd->uc_flags & UC_VIM9) | |
1839 { | |
1840 // In a {} block variables use Vim9 script rules, even in a legacy | |
1841 // script. | |
1842 restore_script_version = | |
1843 SCRIPT_ITEM(current_sctx.sc_sid)->sn_version; | |
1844 SCRIPT_ITEM(current_sctx.sc_sid)->sn_version = SCRIPT_VERSION_VIM9; | |
1845 } | |
1833 #endif | 1846 #endif |
1834 } | 1847 } |
1835 | 1848 |
1836 (void)do_cmdline(buf, eap->getline, eap->cookie, | 1849 (void)do_cmdline(buf, eap->getline, eap->cookie, |
1837 DOCMD_VERBOSE|DOCMD_NOWAIT|DOCMD_KEYTYPED); | 1850 DOCMD_VERBOSE|DOCMD_NOWAIT|DOCMD_KEYTYPED); |
1838 | 1851 |
1839 // Careful: Do not use "cmd" here, it may have become invalid if a user | 1852 // Careful: Do not use "cmd" here, it may have become invalid if a user |
1840 // command was added. | 1853 // command was added. |
1841 if (restore_current_sctx) | 1854 if (restore_current_sctx) |
1855 { | |
1856 #ifdef FEAT_EVAL | |
1857 if (restore_script_version != 0) | |
1858 SCRIPT_ITEM(current_sctx.sc_sid)->sn_version = | |
1859 restore_script_version; | |
1860 #endif | |
1842 current_sctx = save_current_sctx; | 1861 current_sctx = save_current_sctx; |
1862 } | |
1843 vim_free(buf); | 1863 vim_free(buf); |
1844 vim_free(split_buf); | 1864 vim_free(split_buf); |
1845 } | 1865 } |