• R/O
  • SSH

vim: Commit

Mirror of the Vim source from https://github.com/vim/vim


Commit MetaInfo

Revisionebe56a24acb6e9b04c74bd390f7e5ba305a7d713 (tree)
Zeit2022-01-22 22:45:02
AutorBram Moolenaar <Bram@vim....>
CommiterBram Moolenaar

Log Message

patch 8.2.4179: 'foldtext' is evaluated in the current script context

Commit: https://github.com/vim/vim/commit/9530b580a7b71960dbbdb2b12a3aafeb540bd135
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Jan 22 13:39:08 2022 +0000

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.

Ändern Zusammenfassung

Diff

diff -r 160b87e56c45 -r ebe56a24acb6 src/buffer.c
--- a/src/buffer.c Sat Jan 22 13:30:06 2022 +0100
+++ b/src/buffer.c Sat Jan 22 14:45:02 2022 +0100
@@ -4162,7 +4162,7 @@
41624162 tv.vval.v_number = wp->w_id;
41634163 set_var((char_u *)"g:statusline_winid", &tv, FALSE);
41644164
4165- usefmt = eval_to_string_safe(fmt + 2, use_sandbox);
4165+ usefmt = eval_to_string_safe(fmt + 2, use_sandbox, FALSE);
41664166 if (usefmt == NULL)
41674167 usefmt = fmt;
41684168
@@ -4546,7 +4546,7 @@
45464546 if (curwin != save_curwin)
45474547 VIsual_active = FALSE;
45484548
4549- str = eval_to_string_safe(p, use_sandbox);
4549+ str = eval_to_string_safe(p, use_sandbox, FALSE);
45504550
45514551 curwin = save_curwin;
45524552 curbuf = save_curbuf;
diff -r 160b87e56c45 -r ebe56a24acb6 src/eval.c
--- a/src/eval.c Sat Jan 22 13:30:06 2022 +0100
+++ b/src/eval.c Sat Jan 22 14:45:02 2022 +0100
@@ -555,14 +555,16 @@
555555 char_u *
556556 eval_to_string_safe(
557557 char_u *arg,
558- int use_sandbox)
558+ int use_sandbox,
559+ int keep_script_version)
559560 {
560561 char_u *retval;
561562 funccal_entry_T funccal_entry;
562563 int save_sc_version = current_sctx.sc_version;
563564 int save_garbage = may_garbage_collect;
564565
565- current_sctx.sc_version = 1;
566+ if (!keep_script_version)
567+ current_sctx.sc_version = 1;
566568 save_funccal(&funccal_entry);
567569 if (use_sandbox)
568570 ++sandbox;
diff -r 160b87e56c45 -r ebe56a24acb6 src/findfile.c
--- a/src/findfile.c Sat Jan 22 13:30:06 2022 +0100
+++ b/src/findfile.c Sat Jan 22 14:45:02 2022 +0100
@@ -2097,7 +2097,7 @@
20972097
20982098 set_vim_var_string(VV_FNAME, ptr, len);
20992099 res = eval_to_string_safe(curbuf->b_p_inex,
2100- was_set_insecurely((char_u *)"includeexpr", OPT_LOCAL));
2100+ was_set_insecurely((char_u *)"includeexpr", OPT_LOCAL), FALSE);
21012101 set_vim_var_string(VV_FNAME, NULL, 0);
21022102 return res;
21032103 }
diff -r 160b87e56c45 -r ebe56a24acb6 src/fold.c
--- a/src/fold.c Sat Jan 22 13:30:06 2022 +0100
+++ b/src/fold.c Sat Jan 22 14:45:02 2022 +0100
@@ -1923,7 +1923,6 @@
19231923 if (*wp->w_p_fdt != NUL)
19241924 {
19251925 char_u dashes[MAX_LEVEL + 2];
1926- win_T *save_curwin;
19271926 int level;
19281927 char_u *p;
19291928
@@ -1941,23 +1940,27 @@
19411940 set_vim_var_string(VV_FOLDDASHES, dashes, -1);
19421941 set_vim_var_nr(VV_FOLDLEVEL, (long)level);
19431942
1944- // skip evaluating foldtext on errors
1943+ // skip evaluating 'foldtext' on errors
19451944 if (!got_fdt_error)
19461945 {
1947- save_curwin = curwin;
1946+ win_T *save_curwin = curwin;
1947+ sctx_T saved_sctx = current_sctx;
1948+
19481949 curwin = wp;
19491950 curbuf = wp->w_buffer;
1950-
1951- ++emsg_silent; // handle exceptions, but don't display errors
1951+ current_sctx = wp->w_p_script_ctx[WV_FDT];
1952+
1953+ ++emsg_off; // handle exceptions, but don't display errors
19521954 text = eval_to_string_safe(wp->w_p_fdt,
1953- was_set_insecurely((char_u *)"foldtext", OPT_LOCAL));
1954- --emsg_silent;
1955+ was_set_insecurely((char_u *)"foldtext", OPT_LOCAL), TRUE);
1956+ --emsg_off;
19551957
19561958 if (text == NULL || did_emsg)
19571959 got_fdt_error = TRUE;
19581960
19591961 curwin = save_curwin;
19601962 curbuf = curwin->w_buffer;
1963+ current_sctx = saved_sctx;
19611964 }
19621965 last_lnum = lnum;
19631966 last_wp = wp;
diff -r 160b87e56c45 -r ebe56a24acb6 src/proto/eval.pro
--- a/src/proto/eval.pro Sat Jan 22 13:30:06 2022 +0100
+++ b/src/proto/eval.pro Sat Jan 22 14:45:02 2022 +0100
@@ -14,7 +14,7 @@
1414 char_u *typval2string(typval_T *tv, int convert);
1515 char_u *eval_to_string_eap(char_u *arg, int convert, exarg_T *eap);
1616 char_u *eval_to_string(char_u *arg, int convert);
17-char_u *eval_to_string_safe(char_u *arg, int use_sandbox);
17+char_u *eval_to_string_safe(char_u *arg, int use_sandbox, int keep_script_version);
1818 varnumber_T eval_to_number(char_u *expr);
1919 typval_T *eval_expr(char_u *arg, exarg_T *eap);
2020 int call_vim_function(char_u *func, int argc, typval_T *argv, typval_T *rettv);
diff -r 160b87e56c45 -r ebe56a24acb6 src/testdir/test_vim9_import.vim
--- a/src/testdir/test_vim9_import.vim Sat Jan 22 13:30:06 2022 +0100
+++ b/src/testdir/test_vim9_import.vim Sat Jan 22 14:45:02 2022 +0100
@@ -683,6 +683,9 @@
683683 export def Expr(): string
684684 return getline(v:lnum) =~ '^#' ? '>1' : '1'
685685 enddef
686+ export def Text(): string
687+ return 'fold text'
688+ enddef
686689 g:fold_loaded = 'yes'
687690 END
688691 writefile(lines, 'Xdir/autoload/fold.vim')
@@ -691,6 +694,7 @@
691694 vim9script
692695 import autoload 'fold.vim'
693696 &foldexpr = 'fold.Expr()'
697+ &foldtext = 'fold.Text()'
694698 &foldmethod = 'expr'
695699 &debug = 'throw'
696700 END
@@ -706,7 +710,7 @@
706710 edit! otherfile
707711 redraw
708712
709- set foldexpr= foldmethod& debug=
713+ set foldexpr= foldtext& foldmethod& debug=
710714 bwipe!
711715 delete('Xdir', 'rf')
712716 &rtp = save_rtp
diff -r 160b87e56c45 -r ebe56a24acb6 src/version.c
--- a/src/version.c Sat Jan 22 13:30:06 2022 +0100
+++ b/src/version.c Sat Jan 22 14:45:02 2022 +0100
@@ -751,6 +751,8 @@
751751 static int included_patches[] =
752752 { /* Add new patch number below this line */
753753 /**/
754+ 4179,
755+/**/
754756 4178,
755757 /**/
756758 4177,
Show on old repository browser