aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2023-04-17 15:21:47 +0800
committerzeertzjq <zeertzjq@outlook.com>2023-04-17 15:46:24 +0800
commit36f1e9824aaccfe7211388737aba1bdb0e37e0be (patch)
tree2e3b0f5e4f4cdb36d3b122e07b80e1ba3262d9eb
parent9cf59acfaa2a050ce7fbc68d5435bf777618dedb (diff)
downloadrneovim-36f1e9824aaccfe7211388737aba1bdb0e37e0be.tar.gz
rneovim-36f1e9824aaccfe7211388737aba1bdb0e37e0be.tar.bz2
rneovim-36f1e9824aaccfe7211388737aba1bdb0e37e0be.zip
vim-patch:8.2.4183: cannot use an import in 'formatexpr'
Problem: Cannot use an import in 'formatexpr'. Solution: Set the script context when evaluating 'formatexpr'. https://github.com/vim/vim/commit/3ba685eeefcfbbf895d70664357ef05f252d7b21 Co-authored-by: Bram Moolenaar <Bram@vim.org>
-rw-r--r--src/nvim/textformat.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/src/nvim/textformat.c b/src/nvim/textformat.c
index c406f0c302..dd13295c48 100644
--- a/src/nvim/textformat.c
+++ b/src/nvim/textformat.c
@@ -881,6 +881,7 @@ void op_formatexpr(oparg_T *oap)
int fex_format(linenr_T lnum, long count, int c)
{
int use_sandbox = was_set_insecurely(curwin, "formatexpr", OPT_LOCAL);
+ const sctx_T save_sctx = current_sctx;
// Set v:lnum to the first line number and v:count to the number of lines.
// Set v:char to the character to be inserted (can be NUL).
@@ -890,6 +891,8 @@ int fex_format(linenr_T lnum, long count, int c)
// Make a copy, the option could be changed while calling it.
char *fex = xstrdup(curbuf->b_p_fex);
+ current_sctx = curbuf->b_p_script_ctx[BV_FEX].script_ctx;
+
// Evaluate the function.
if (use_sandbox) {
sandbox++;
@@ -901,6 +904,7 @@ int fex_format(linenr_T lnum, long count, int c)
set_vim_var_string(VV_CHAR, NULL, -1);
xfree(fex);
+ current_sctx = save_sctx;
return r;
}