mirror of
https://github.com/vim/vim.git
synced 2025-09-23 03:43:49 -04:00
patch 8.2.4192: cannot use an import in 'printexpr'
Problem: Cannot use an import in 'printexpr'. Solution: Set the script context when evaluating 'printexpr'.
This commit is contained in:
@@ -391,13 +391,21 @@ eval_charconvert(
|
||||
eval_printexpr(char_u *fname, char_u *args)
|
||||
{
|
||||
int err = FALSE;
|
||||
sctx_T saved_sctx = current_sctx;
|
||||
sctx_T *ctx;
|
||||
|
||||
set_vim_var_string(VV_FNAME_IN, fname, -1);
|
||||
set_vim_var_string(VV_CMDARG, args, -1);
|
||||
ctx = get_option_sctx("printexpr");
|
||||
if (ctx != NULL)
|
||||
current_sctx = *ctx;
|
||||
|
||||
if (eval_to_bool(p_pexpr, &err, NULL, FALSE))
|
||||
err = TRUE;
|
||||
|
||||
set_vim_var_string(VV_FNAME_IN, NULL, -1);
|
||||
set_vim_var_string(VV_CMDARG, NULL, -1);
|
||||
current_sctx = saved_sctx;
|
||||
|
||||
if (err)
|
||||
{
|
||||
|
@@ -874,6 +874,37 @@ def Test_import_in_indentexpr()
|
||||
delete('Xindenter')
|
||||
enddef
|
||||
|
||||
func Test_import_in_printexpr()
|
||||
CheckFeature postscript
|
||||
call Run_Test_import_in_printexpr()
|
||||
endfunc
|
||||
|
||||
def Run_Test_import_in_printexpr()
|
||||
var lines =<< trim END
|
||||
vim9script
|
||||
export def PrintFile(): bool
|
||||
g:printed = 'yes'
|
||||
delete('v:fname_in')
|
||||
return false
|
||||
enddef
|
||||
END
|
||||
writefile(lines, 'Xprint.vim')
|
||||
|
||||
lines =<< trim END
|
||||
vim9script
|
||||
import './Xprint.vim'
|
||||
set printexpr=Xprint.PrintFile()
|
||||
END
|
||||
CheckScriptSuccess(lines)
|
||||
|
||||
help
|
||||
hardcopy dummy args
|
||||
assert_equal('yes', g:printed)
|
||||
|
||||
delete('Xprint.vim')
|
||||
set printexpr=
|
||||
enddef
|
||||
|
||||
def Test_export_fails()
|
||||
CheckScriptFailure(['export var some = 123'], 'E1042:')
|
||||
CheckScriptFailure(['vim9script', 'export var g:some'], 'E1022:')
|
||||
|
@@ -750,6 +750,8 @@ static char *(features[]) =
|
||||
|
||||
static int included_patches[] =
|
||||
{ /* Add new patch number below this line */
|
||||
/**/
|
||||
4192,
|
||||
/**/
|
||||
4191,
|
||||
/**/
|
||||
|
Reference in New Issue
Block a user