mirror of
https://github.com/vim/vim.git
synced 2025-10-06 05:44:14 -04:00
patch 8.2.4179: 'foldtext' is evaluated in the current script context
Problem: 'foldtext' is evaluated in the current script context. Solution: Use the script context where the option was set.
This commit is contained in:
@@ -4162,7 +4162,7 @@ build_stl_str_hl(
|
|||||||
tv.vval.v_number = wp->w_id;
|
tv.vval.v_number = wp->w_id;
|
||||||
set_var((char_u *)"g:statusline_winid", &tv, FALSE);
|
set_var((char_u *)"g:statusline_winid", &tv, FALSE);
|
||||||
|
|
||||||
usefmt = eval_to_string_safe(fmt + 2, use_sandbox);
|
usefmt = eval_to_string_safe(fmt + 2, use_sandbox, FALSE);
|
||||||
if (usefmt == NULL)
|
if (usefmt == NULL)
|
||||||
usefmt = fmt;
|
usefmt = fmt;
|
||||||
|
|
||||||
@@ -4546,7 +4546,7 @@ build_stl_str_hl(
|
|||||||
if (curwin != save_curwin)
|
if (curwin != save_curwin)
|
||||||
VIsual_active = FALSE;
|
VIsual_active = FALSE;
|
||||||
|
|
||||||
str = eval_to_string_safe(p, use_sandbox);
|
str = eval_to_string_safe(p, use_sandbox, FALSE);
|
||||||
|
|
||||||
curwin = save_curwin;
|
curwin = save_curwin;
|
||||||
curbuf = save_curbuf;
|
curbuf = save_curbuf;
|
||||||
|
@@ -555,14 +555,16 @@ eval_to_string(
|
|||||||
char_u *
|
char_u *
|
||||||
eval_to_string_safe(
|
eval_to_string_safe(
|
||||||
char_u *arg,
|
char_u *arg,
|
||||||
int use_sandbox)
|
int use_sandbox,
|
||||||
|
int keep_script_version)
|
||||||
{
|
{
|
||||||
char_u *retval;
|
char_u *retval;
|
||||||
funccal_entry_T funccal_entry;
|
funccal_entry_T funccal_entry;
|
||||||
int save_sc_version = current_sctx.sc_version;
|
int save_sc_version = current_sctx.sc_version;
|
||||||
int save_garbage = may_garbage_collect;
|
int save_garbage = may_garbage_collect;
|
||||||
|
|
||||||
current_sctx.sc_version = 1;
|
if (!keep_script_version)
|
||||||
|
current_sctx.sc_version = 1;
|
||||||
save_funccal(&funccal_entry);
|
save_funccal(&funccal_entry);
|
||||||
if (use_sandbox)
|
if (use_sandbox)
|
||||||
++sandbox;
|
++sandbox;
|
||||||
|
@@ -2097,7 +2097,7 @@ eval_includeexpr(char_u *ptr, int len)
|
|||||||
|
|
||||||
set_vim_var_string(VV_FNAME, ptr, len);
|
set_vim_var_string(VV_FNAME, ptr, len);
|
||||||
res = eval_to_string_safe(curbuf->b_p_inex,
|
res = eval_to_string_safe(curbuf->b_p_inex,
|
||||||
was_set_insecurely((char_u *)"includeexpr", OPT_LOCAL));
|
was_set_insecurely((char_u *)"includeexpr", OPT_LOCAL), FALSE);
|
||||||
set_vim_var_string(VV_FNAME, NULL, 0);
|
set_vim_var_string(VV_FNAME, NULL, 0);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
15
src/fold.c
15
src/fold.c
@@ -1923,7 +1923,6 @@ get_foldtext(
|
|||||||
if (*wp->w_p_fdt != NUL)
|
if (*wp->w_p_fdt != NUL)
|
||||||
{
|
{
|
||||||
char_u dashes[MAX_LEVEL + 2];
|
char_u dashes[MAX_LEVEL + 2];
|
||||||
win_T *save_curwin;
|
|
||||||
int level;
|
int level;
|
||||||
char_u *p;
|
char_u *p;
|
||||||
|
|
||||||
@@ -1941,23 +1940,27 @@ get_foldtext(
|
|||||||
set_vim_var_string(VV_FOLDDASHES, dashes, -1);
|
set_vim_var_string(VV_FOLDDASHES, dashes, -1);
|
||||||
set_vim_var_nr(VV_FOLDLEVEL, (long)level);
|
set_vim_var_nr(VV_FOLDLEVEL, (long)level);
|
||||||
|
|
||||||
// skip evaluating foldtext on errors
|
// skip evaluating 'foldtext' on errors
|
||||||
if (!got_fdt_error)
|
if (!got_fdt_error)
|
||||||
{
|
{
|
||||||
save_curwin = curwin;
|
win_T *save_curwin = curwin;
|
||||||
|
sctx_T saved_sctx = current_sctx;
|
||||||
|
|
||||||
curwin = wp;
|
curwin = wp;
|
||||||
curbuf = wp->w_buffer;
|
curbuf = wp->w_buffer;
|
||||||
|
current_sctx = wp->w_p_script_ctx[WV_FDT];
|
||||||
|
|
||||||
++emsg_silent; // handle exceptions, but don't display errors
|
++emsg_off; // handle exceptions, but don't display errors
|
||||||
text = eval_to_string_safe(wp->w_p_fdt,
|
text = eval_to_string_safe(wp->w_p_fdt,
|
||||||
was_set_insecurely((char_u *)"foldtext", OPT_LOCAL));
|
was_set_insecurely((char_u *)"foldtext", OPT_LOCAL), TRUE);
|
||||||
--emsg_silent;
|
--emsg_off;
|
||||||
|
|
||||||
if (text == NULL || did_emsg)
|
if (text == NULL || did_emsg)
|
||||||
got_fdt_error = TRUE;
|
got_fdt_error = TRUE;
|
||||||
|
|
||||||
curwin = save_curwin;
|
curwin = save_curwin;
|
||||||
curbuf = curwin->w_buffer;
|
curbuf = curwin->w_buffer;
|
||||||
|
current_sctx = saved_sctx;
|
||||||
}
|
}
|
||||||
last_lnum = lnum;
|
last_lnum = lnum;
|
||||||
last_wp = wp;
|
last_wp = wp;
|
||||||
|
@@ -14,7 +14,7 @@ int skip_expr_concatenate(char_u **arg, char_u **start, char_u **end, evalarg_T
|
|||||||
char_u *typval2string(typval_T *tv, int convert);
|
char_u *typval2string(typval_T *tv, int convert);
|
||||||
char_u *eval_to_string_eap(char_u *arg, int convert, exarg_T *eap);
|
char_u *eval_to_string_eap(char_u *arg, int convert, exarg_T *eap);
|
||||||
char_u *eval_to_string(char_u *arg, int convert);
|
char_u *eval_to_string(char_u *arg, int convert);
|
||||||
char_u *eval_to_string_safe(char_u *arg, int use_sandbox);
|
char_u *eval_to_string_safe(char_u *arg, int use_sandbox, int keep_script_version);
|
||||||
varnumber_T eval_to_number(char_u *expr);
|
varnumber_T eval_to_number(char_u *expr);
|
||||||
typval_T *eval_expr(char_u *arg, exarg_T *eap);
|
typval_T *eval_expr(char_u *arg, exarg_T *eap);
|
||||||
int call_vim_function(char_u *func, int argc, typval_T *argv, typval_T *rettv);
|
int call_vim_function(char_u *func, int argc, typval_T *argv, typval_T *rettv);
|
||||||
|
@@ -683,6 +683,9 @@ def Test_use_autoload_import_in_fold_expression()
|
|||||||
export def Expr(): string
|
export def Expr(): string
|
||||||
return getline(v:lnum) =~ '^#' ? '>1' : '1'
|
return getline(v:lnum) =~ '^#' ? '>1' : '1'
|
||||||
enddef
|
enddef
|
||||||
|
export def Text(): string
|
||||||
|
return 'fold text'
|
||||||
|
enddef
|
||||||
g:fold_loaded = 'yes'
|
g:fold_loaded = 'yes'
|
||||||
END
|
END
|
||||||
writefile(lines, 'Xdir/autoload/fold.vim')
|
writefile(lines, 'Xdir/autoload/fold.vim')
|
||||||
@@ -691,6 +694,7 @@ def Test_use_autoload_import_in_fold_expression()
|
|||||||
vim9script
|
vim9script
|
||||||
import autoload 'fold.vim'
|
import autoload 'fold.vim'
|
||||||
&foldexpr = 'fold.Expr()'
|
&foldexpr = 'fold.Expr()'
|
||||||
|
&foldtext = 'fold.Text()'
|
||||||
&foldmethod = 'expr'
|
&foldmethod = 'expr'
|
||||||
&debug = 'throw'
|
&debug = 'throw'
|
||||||
END
|
END
|
||||||
@@ -706,7 +710,7 @@ def Test_use_autoload_import_in_fold_expression()
|
|||||||
edit! otherfile
|
edit! otherfile
|
||||||
redraw
|
redraw
|
||||||
|
|
||||||
set foldexpr= foldmethod& debug=
|
set foldexpr= foldtext& foldmethod& debug=
|
||||||
bwipe!
|
bwipe!
|
||||||
delete('Xdir', 'rf')
|
delete('Xdir', 'rf')
|
||||||
&rtp = save_rtp
|
&rtp = save_rtp
|
||||||
|
@@ -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 */
|
||||||
|
/**/
|
||||||
|
4179,
|
||||||
/**/
|
/**/
|
||||||
4178,
|
4178,
|
||||||
/**/
|
/**/
|
||||||
|
Reference in New Issue
Block a user