forked from aniani/vim
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)
|
eval_printexpr(char_u *fname, char_u *args)
|
||||||
{
|
{
|
||||||
int err = FALSE;
|
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_FNAME_IN, fname, -1);
|
||||||
set_vim_var_string(VV_CMDARG, args, -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))
|
if (eval_to_bool(p_pexpr, &err, NULL, FALSE))
|
||||||
err = TRUE;
|
err = TRUE;
|
||||||
|
|
||||||
set_vim_var_string(VV_FNAME_IN, NULL, -1);
|
set_vim_var_string(VV_FNAME_IN, NULL, -1);
|
||||||
set_vim_var_string(VV_CMDARG, NULL, -1);
|
set_vim_var_string(VV_CMDARG, NULL, -1);
|
||||||
|
current_sctx = saved_sctx;
|
||||||
|
|
||||||
if (err)
|
if (err)
|
||||||
{
|
{
|
||||||
|
@@ -874,6 +874,37 @@ def Test_import_in_indentexpr()
|
|||||||
delete('Xindenter')
|
delete('Xindenter')
|
||||||
enddef
|
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()
|
def Test_export_fails()
|
||||||
CheckScriptFailure(['export var some = 123'], 'E1042:')
|
CheckScriptFailure(['export var some = 123'], 'E1042:')
|
||||||
CheckScriptFailure(['vim9script', 'export var g:some'], 'E1022:')
|
CheckScriptFailure(['vim9script', 'export var g:some'], 'E1022:')
|
||||||
|
@@ -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 */
|
||||||
|
/**/
|
||||||
|
4192,
|
||||||
/**/
|
/**/
|
||||||
4191,
|
4191,
|
||||||
/**/
|
/**/
|
||||||
|
Reference in New Issue
Block a user