mirror of
https://github.com/vim/vim.git
synced 2025-09-23 03:43:49 -04:00
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'.
This commit is contained in:
@@ -759,6 +759,34 @@ def Run_Test_import_in_diffexpr()
|
|||||||
bwipe!
|
bwipe!
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
|
def Test_import_in_formatexpr()
|
||||||
|
var lines =<< trim END
|
||||||
|
vim9script
|
||||||
|
export def MyFormatExpr(): number
|
||||||
|
g:did_format = 'yes'
|
||||||
|
return 0
|
||||||
|
enddef
|
||||||
|
END
|
||||||
|
writefile(lines, 'Xformatter')
|
||||||
|
|
||||||
|
lines =<< trim END
|
||||||
|
vim9script
|
||||||
|
import './Xformatter' as format
|
||||||
|
set formatexpr=format.MyFormatExpr()
|
||||||
|
END
|
||||||
|
CheckScriptSuccess(lines)
|
||||||
|
|
||||||
|
new
|
||||||
|
setline(1, ['a', 'b', 'c'])
|
||||||
|
normal gqG
|
||||||
|
assert_equal('yes', g:did_format)
|
||||||
|
|
||||||
|
bwipe!
|
||||||
|
delete('Xformatter')
|
||||||
|
unlet g:did_format
|
||||||
|
set formatexpr=
|
||||||
|
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:')
|
||||||
|
@@ -903,6 +903,7 @@ fex_format(
|
|||||||
OPT_LOCAL);
|
OPT_LOCAL);
|
||||||
int r;
|
int r;
|
||||||
char_u *fex;
|
char_u *fex;
|
||||||
|
sctx_T save_sctx = current_sctx;
|
||||||
|
|
||||||
// Set v:lnum to the first line number and v:count to the number of lines.
|
// 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).
|
// Set v:char to the character to be inserted (can be NUL).
|
||||||
@@ -914,6 +915,7 @@ fex_format(
|
|||||||
fex = vim_strsave(curbuf->b_p_fex);
|
fex = vim_strsave(curbuf->b_p_fex);
|
||||||
if (fex == NULL)
|
if (fex == NULL)
|
||||||
return 0;
|
return 0;
|
||||||
|
current_sctx = curbuf->b_p_script_ctx[BV_FEX];
|
||||||
|
|
||||||
// Evaluate the function.
|
// Evaluate the function.
|
||||||
if (use_sandbox)
|
if (use_sandbox)
|
||||||
@@ -924,6 +926,7 @@ fex_format(
|
|||||||
|
|
||||||
set_vim_var_string(VV_CHAR, NULL, -1);
|
set_vim_var_string(VV_CHAR, NULL, -1);
|
||||||
vim_free(fex);
|
vim_free(fex);
|
||||||
|
current_sctx = save_sctx;
|
||||||
|
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
@@ -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 */
|
||||||
|
/**/
|
||||||
|
4183,
|
||||||
/**/
|
/**/
|
||||||
4182,
|
4182,
|
||||||
/**/
|
/**/
|
||||||
|
Reference in New Issue
Block a user