File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -4741,6 +4741,7 @@ fex_format(
47414741 int use_sandbox = was_set_insecurely ((char_u * )"formatexpr" ,
47424742 OPT_LOCAL );
47434743 int r ;
4744+ char_u * fex ;
47444745
47454746 /*
47464747 * Set v:lnum to the first line number and v:count to the number of lines.
@@ -4750,16 +4751,22 @@ fex_format(
47504751 set_vim_var_nr (VV_COUNT , count );
47514752 set_vim_var_char (c );
47524753
4754+ /* Make a copy, the option could be changed while calling it. */
4755+ fex = vim_strsave (curbuf -> b_p_fex );
4756+ if (fex == NULL )
4757+ return 0 ;
4758+
47534759 /*
47544760 * Evaluate the function.
47554761 */
47564762 if (use_sandbox )
47574763 ++ sandbox ;
4758- r = (int )eval_to_number (curbuf -> b_p_fex );
4764+ r = (int )eval_to_number (fex );
47594765 if (use_sandbox )
47604766 -- sandbox ;
47614767
47624768 set_vim_var_string (VV_CHAR , NULL , -1 );
4769+ vim_free (fex );
47634770
47644771 return r ;
47654772}
Original file line number Diff line number Diff line change @@ -192,6 +192,30 @@ func! Test_normal05_formatexpr()
192192 bw !
193193endfu
194194
195+ func Test_normal05_formatexpr_newbuf ()
196+ " Edit another buffer in the 'formatexpr' function
197+ new
198+ func ! Format ()
199+ edit another
200+ endfunc
201+ set formatexpr = Format ()
202+ norm gqG
203+ bw !
204+ set formatexpr =
205+ endfunc
206+
207+ func Test_normal05_formatexpr_setopt ()
208+ " Change the 'formatexpr' value in the function
209+ new
210+ func ! Format ()
211+ set formatexpr =
212+ endfunc
213+ set formatexpr = Format ()
214+ norm gqG
215+ bw !
216+ set formatexpr =
217+ endfunc
218+
195219func ! Test_normal06_formatprg ()
196220 " basic test for formatprg
197221 " only test on non windows platform
Original file line number Diff line number Diff line change @@ -763,6 +763,8 @@ static char *(features[]) =
763763
764764static int included_patches [] =
765765{ /* Add new patch number below this line */
766+ /**/
767+ 2323 ,
766768/**/
767769 2322 ,
768770/**/
You can’t perform that action at this time.
0 commit comments