forked from aniani/vim
		
	patch 8.2.4185: cannot use an import in 'indentexpr'
Problem: Cannot use an import in 'indentexpr'. Solution: Set the script context when evaluating 'indentexpr'
This commit is contained in:
		| @@ -1829,6 +1829,7 @@ get_expr_indent(void) | |||||||
|     int		save_State; |     int		save_State; | ||||||
|     int		use_sandbox = was_set_insecurely((char_u *)"indentexpr", |     int		use_sandbox = was_set_insecurely((char_u *)"indentexpr", | ||||||
| 								   OPT_LOCAL); | 								   OPT_LOCAL); | ||||||
|  |     sctx_T	save_sctx = current_sctx; | ||||||
|  |  | ||||||
|     // Save and restore cursor position and curswant, in case it was changed |     // Save and restore cursor position and curswant, in case it was changed | ||||||
|     // via :normal commands |     // via :normal commands | ||||||
| @@ -1839,6 +1840,7 @@ get_expr_indent(void) | |||||||
|     if (use_sandbox) |     if (use_sandbox) | ||||||
| 	++sandbox; | 	++sandbox; | ||||||
|     ++textwinlock; |     ++textwinlock; | ||||||
|  |     current_sctx = curbuf->b_p_script_ctx[BV_INDE]; | ||||||
|  |  | ||||||
|     // Need to make a copy, the 'indentexpr' option could be changed while |     // Need to make a copy, the 'indentexpr' option could be changed while | ||||||
|     // evaluating it. |     // evaluating it. | ||||||
| @@ -1852,6 +1854,7 @@ get_expr_indent(void) | |||||||
|     if (use_sandbox) |     if (use_sandbox) | ||||||
| 	--sandbox; | 	--sandbox; | ||||||
|     --textwinlock; |     --textwinlock; | ||||||
|  |     current_sctx = save_sctx; | ||||||
|  |  | ||||||
|     // Restore the cursor position so that 'indentexpr' doesn't need to. |     // Restore the cursor position so that 'indentexpr' doesn't need to. | ||||||
|     // Pretend to be in Insert mode, allow cursor past end of line for "o" |     // Pretend to be in Insert mode, allow cursor past end of line for "o" | ||||||
|   | |||||||
| @@ -817,6 +817,33 @@ def Test_import_in_includeexpr() | |||||||
|   delete('Xthisfile') |   delete('Xthisfile') | ||||||
| enddef | enddef | ||||||
|  |  | ||||||
|  | def Test_import_in_indentexpr() | ||||||
|  |   var lines =<< trim END | ||||||
|  |       vim9script | ||||||
|  |       export def GetIndent(): number | ||||||
|  |         return 5 | ||||||
|  |       enddef | ||||||
|  |   END | ||||||
|  |   writefile(lines, 'Xindenter') | ||||||
|  |  | ||||||
|  |   lines =<< trim END | ||||||
|  |       vim9script | ||||||
|  |       import './Xindenter' as indent | ||||||
|  |       set indentexpr=indent.GetIndent() | ||||||
|  |       set debug=throw | ||||||
|  |   END | ||||||
|  |   CheckScriptSuccess(lines) | ||||||
|  |  | ||||||
|  |   new | ||||||
|  |   setline(1, 'hello') | ||||||
|  |   normal == | ||||||
|  |   assert_equal('     hello', getline(1)) | ||||||
|  |  | ||||||
|  |   bwipe! | ||||||
|  |   set indentexpr= debug= | ||||||
|  |   delete('Xindenter') | ||||||
|  | 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 */ | ||||||
|  | /**/ | ||||||
|  |     4185, | ||||||
| /**/ | /**/ | ||||||
|     4184, |     4184, | ||||||
| /**/ | /**/ | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user