diff options
author | Bram Moolenaar <Bram@vim.org> | 2022-01-23 14:17:28 +0000 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2022-01-23 14:17:28 +0000 |
commit | f4e88f2152c5975a6f4cfa7ccd745575fe4d1c78 (patch) | |
tree | 80ce52cd0d1ce029cba5689d29b954080083ec31 | |
parent | 7ef4a2fe3736bbeb5bad182782a74576aa06b0db (diff) | |
download | vim-git-f4e88f2152c5975a6f4cfa7ccd745575fe4d1c78.tar.gz |
patch 8.2.4193: cannot use an import in 'charconvert'v8.2.4193
Problem: Cannot use an import in 'charconvert'.
Solution: Set the script context when evaluating 'charconvert'. Also expand
script-local functions in 'charconvert'.
-rw-r--r-- | src/evalvars.c | 8 | ||||
-rw-r--r-- | src/optionstr.c | 5 | ||||
-rw-r--r-- | src/testdir/test_vim9_import.vim | 31 | ||||
-rw-r--r-- | src/version.c | 2 |
4 files changed, 44 insertions, 2 deletions
diff --git a/src/evalvars.c b/src/evalvars.c index 196d4d422..305ffe548 100644 --- a/src/evalvars.c +++ b/src/evalvars.c @@ -369,17 +369,25 @@ eval_charconvert( char_u *fname_to) { int err = FALSE; + sctx_T saved_sctx = current_sctx; + sctx_T *ctx; set_vim_var_string(VV_CC_FROM, enc_from, -1); set_vim_var_string(VV_CC_TO, enc_to, -1); set_vim_var_string(VV_FNAME_IN, fname_from, -1); set_vim_var_string(VV_FNAME_OUT, fname_to, -1); + ctx = get_option_sctx("charconvert"); + if (ctx != NULL) + current_sctx = *ctx; + if (eval_to_bool(p_ccv, &err, NULL, FALSE)) err = TRUE; + set_vim_var_string(VV_CC_FROM, NULL, -1); set_vim_var_string(VV_CC_TO, NULL, -1); set_vim_var_string(VV_FNAME_IN, NULL, -1); set_vim_var_string(VV_FNAME_OUT, NULL, -1); + current_sctx = saved_sctx; if (err) return FAIL; diff --git a/src/optionstr.c b/src/optionstr.c index 94a1e2a24..4aa7cef5e 100644 --- a/src/optionstr.c +++ b/src/optionstr.c @@ -2329,8 +2329,7 @@ ambw_end: # ifdef FEAT_POSTSCRIPT varp == &p_pexpr || # endif - FALSE - ) + varp == &p_ccv) { char_u **p_opt = NULL; char_u *name; @@ -2369,6 +2368,8 @@ ambw_end: if (varp == &p_pexpr) // 'printexpr' p_opt = &p_pexpr; # endif + if (varp == &p_ccv) // 'charconvert' + p_opt = &p_ccv; if (p_opt != NULL) { diff --git a/src/testdir/test_vim9_import.vim b/src/testdir/test_vim9_import.vim index 482e759d1..3b7ec9cba 100644 --- a/src/testdir/test_vim9_import.vim +++ b/src/testdir/test_vim9_import.vim @@ -905,6 +905,37 @@ def Run_Test_import_in_printexpr() set printexpr= enddef +def Test_import_in_charconvert() + var lines =<< trim END + vim9script + export def MakeUpper(): bool + var data = readfile(v:fname_in) + map(data, 'toupper(v:val)') + writefile(data, v:fname_out) + return false # success + enddef + END + writefile(lines, 'Xconvert.vim') + + lines =<< trim END + vim9script + import './Xconvert.vim' as conv + set charconvert=conv.MakeUpper() + END + CheckScriptSuccess(lines) + + writefile(['one', 'two'], 'Xfile') + new Xfile + write ++enc=ucase Xfile1 + assert_equal(['ONE', 'TWO'], readfile('Xfile1')) + + delete('Xfile') + delete('Xfile1') + delete('Xconvert.vim') + bwipe! + set charconvert& +enddef + def Test_export_fails() CheckScriptFailure(['export var some = 123'], 'E1042:') CheckScriptFailure(['vim9script', 'export var g:some'], 'E1022:') diff --git a/src/version.c b/src/version.c index 824522f46..a5bb606e6 100644 --- a/src/version.c +++ b/src/version.c @@ -751,6 +751,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 4193, +/**/ 4192, /**/ 4191, |