Patch 8.2.4183

4 views
Skip to first unread message

Bram Moolenaar

unread,
Jan 22, 2022, 2:18:09 PM1/22/22
to vim...@googlegroups.com

Patch 8.2.4183
Problem: Cannot use an import in 'formatexpr'.
Solution: Set the script context when evaluating 'formatexpr'.
Files: src/textformat.c, src/testdir/test_vim9_import.vim


*** ../vim-8.2.4182/src/textformat.c 2021-12-29 14:09:28.636663343 +0000
--- src/textformat.c 2022-01-22 19:16:46.903984656 +0000
***************
*** 903,908 ****
--- 903,909 ----
OPT_LOCAL);
int r;
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:char to the character to be inserted (can be NUL).
***************
*** 914,919 ****
--- 915,921 ----
fex = vim_strsave(curbuf->b_p_fex);
if (fex == NULL)
return 0;
+ current_sctx = curbuf->b_p_script_ctx[BV_FEX];

// Evaluate the function.
if (use_sandbox)
***************
*** 924,929 ****
--- 926,932 ----

set_vim_var_string(VV_CHAR, NULL, -1);
vim_free(fex);
+ current_sctx = save_sctx;

return r;
}
*** ../vim-8.2.4182/src/testdir/test_vim9_import.vim 2022-01-22 17:58:09.336336062 +0000
--- src/testdir/test_vim9_import.vim 2022-01-22 19:13:36.063555459 +0000
***************
*** 759,764 ****
--- 759,792 ----
bwipe!
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()
CheckScriptFailure(['export var some = 123'], 'E1042:')
CheckScriptFailure(['vim9script', 'export var g:some'], 'E1022:')
*** ../vim-8.2.4182/src/version.c 2022-01-22 18:21:32.919197886 +0000
--- src/version.c 2022-01-22 18:52:49.709023618 +0000
***************
*** 752,753 ****
--- 752,755 ----
{ /* Add new patch number below this line */
+ /**/
+ 4183,
/**/

--
John: When I'm playing tennis with friends I always get carried away
George: You hurt your foot each time?

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
Reply all
Reply to author
Forward
0 new messages