Mercurial > vim
comparison src/buffer.c @ 31018:9716c7d24c12 v9.0.0844
patch 9.0.0844: handling 'statusline' errors is spread out
Commit: https://github.com/vim/vim/commit/7b224fdf4a29f115567d4fc8629c1cef92d8444a
Author: Luuk van Baal <luukvbaal@gmail.com>
Date: Mon Nov 7 12:16:51 2022 +0000
patch 9.0.0844: handling 'statusline' errors is spread out
Problem: Handling 'statusline' errors is spread out.
Solution: Pass the option name to the lower levels so the option can be
reset there when an error is encountered. (Luuk van Baal,
closes #11467)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Mon, 07 Nov 2022 13:30:04 +0100 |
parents | 35265d9d24df |
children | 684e6dfa2fba |
comparison
equal
deleted
inserted
replaced
31017:99a1b64051b5 | 31018:9716c7d24c12 |
---|---|
3957 title_str = buf; | 3957 title_str = buf; |
3958 if (*p_titlestring != NUL) | 3958 if (*p_titlestring != NUL) |
3959 { | 3959 { |
3960 #ifdef FEAT_STL_OPT | 3960 #ifdef FEAT_STL_OPT |
3961 if (stl_syntax & STL_IN_TITLE) | 3961 if (stl_syntax & STL_IN_TITLE) |
3962 { | 3962 build_stl_str_hl(curwin, title_str, sizeof(buf), p_titlestring, |
3963 int use_sandbox = FALSE; | 3963 (char_u *)"titlestring", 0, |
3964 int called_emsg_before = called_emsg; | 3964 0, maxlen, NULL, NULL); |
3965 | |
3966 # ifdef FEAT_EVAL | |
3967 use_sandbox = was_set_insecurely((char_u *)"titlestring", 0); | |
3968 # endif | |
3969 build_stl_str_hl(curwin, title_str, sizeof(buf), | |
3970 p_titlestring, use_sandbox, | |
3971 0, maxlen, NULL, NULL); | |
3972 if (called_emsg > called_emsg_before) | |
3973 set_string_option_direct((char_u *)"titlestring", -1, | |
3974 (char_u *)"", OPT_FREE, SID_ERROR); | |
3975 } | |
3976 else | 3965 else |
3977 #endif | 3966 #endif |
3978 title_str = p_titlestring; | 3967 title_str = p_titlestring; |
3979 } | 3968 } |
3980 else | 3969 else |
4088 icon_str = buf; | 4077 icon_str = buf; |
4089 if (*p_iconstring != NUL) | 4078 if (*p_iconstring != NUL) |
4090 { | 4079 { |
4091 #ifdef FEAT_STL_OPT | 4080 #ifdef FEAT_STL_OPT |
4092 if (stl_syntax & STL_IN_ICON) | 4081 if (stl_syntax & STL_IN_ICON) |
4093 { | 4082 build_stl_str_hl(curwin, icon_str, sizeof(buf), p_iconstring, |
4094 int use_sandbox = FALSE; | 4083 (char_u *)"iconstring", 0, 0, 0, NULL, NULL); |
4095 int called_emsg_before = called_emsg; | |
4096 | |
4097 # ifdef FEAT_EVAL | |
4098 use_sandbox = was_set_insecurely((char_u *)"iconstring", 0); | |
4099 # endif | |
4100 build_stl_str_hl(curwin, icon_str, sizeof(buf), | |
4101 p_iconstring, use_sandbox, | |
4102 0, 0, NULL, NULL); | |
4103 if (called_emsg > called_emsg_before) | |
4104 set_string_option_direct((char_u *)"iconstring", -1, | |
4105 (char_u *)"", OPT_FREE, SID_ERROR); | |
4106 } | |
4107 else | 4084 else |
4108 #endif | 4085 #endif |
4109 icon_str = p_iconstring; | 4086 icon_str = p_iconstring; |
4110 } | 4087 } |
4111 else | 4088 else |
4226 build_stl_str_hl( | 4203 build_stl_str_hl( |
4227 win_T *wp, | 4204 win_T *wp, |
4228 char_u *out, // buffer to write into != NameBuff | 4205 char_u *out, // buffer to write into != NameBuff |
4229 size_t outlen, // length of out[] | 4206 size_t outlen, // length of out[] |
4230 char_u *fmt, | 4207 char_u *fmt, |
4231 int use_sandbox UNUSED, // "fmt" was set insecurely, use sandbox | 4208 char_u *opt_name, // option name corresponding to "fmt" |
4209 int opt_scope, // scope for "opt_name" | |
4232 int fillchar, | 4210 int fillchar, |
4233 int maxwidth, | 4211 int maxwidth, |
4234 stl_hlrec_T **hltab, // return: HL attributes (can be NULL) | 4212 stl_hlrec_T **hltab, // return: HL attributes (can be NULL) |
4235 stl_hlrec_T **tabtab) // return: tab page nrs (can be NULL) | 4213 stl_hlrec_T **tabtab) // return: tab page nrs (can be NULL) |
4236 { | 4214 { |
4239 char_u *p; | 4217 char_u *p; |
4240 char_u *s; | 4218 char_u *s; |
4241 char_u *t; | 4219 char_u *t; |
4242 int byteval; | 4220 int byteval; |
4243 #ifdef FEAT_EVAL | 4221 #ifdef FEAT_EVAL |
4222 int use_sandbox; | |
4244 win_T *save_curwin; | 4223 win_T *save_curwin; |
4245 buf_T *save_curbuf; | 4224 buf_T *save_curbuf; |
4246 int save_VIsual_active; | 4225 int save_VIsual_active; |
4247 #endif | 4226 #endif |
4248 int empty_line; | 4227 int empty_line; |
4274 char_u win_tmp[TMPLEN]; | 4253 char_u win_tmp[TMPLEN]; |
4275 char_u *usefmt = fmt; | 4254 char_u *usefmt = fmt; |
4276 stl_hlrec_T *sp; | 4255 stl_hlrec_T *sp; |
4277 int save_redraw_not_allowed = redraw_not_allowed; | 4256 int save_redraw_not_allowed = redraw_not_allowed; |
4278 int save_KeyTyped = KeyTyped; | 4257 int save_KeyTyped = KeyTyped; |
4258 // TODO: find out why using called_emsg_before makes tests fail, does it | |
4259 // matter? | |
4260 // int called_emsg_before = called_emsg; | |
4261 int did_emsg_before = did_emsg; | |
4279 | 4262 |
4280 // When inside update_screen() we do not want redrawing a statusline, | 4263 // When inside update_screen() we do not want redrawing a statusline, |
4281 // ruler, title, etc. to trigger another redraw, it may cause an endless | 4264 // ruler, title, etc. to trigger another redraw, it may cause an endless |
4282 // loop. | 4265 // loop. |
4283 if (updating_screen) | 4266 if (updating_screen) |
4293 stl_hltab = ALLOC_MULT(stl_hlrec_T, stl_items_len + 1); | 4276 stl_hltab = ALLOC_MULT(stl_hlrec_T, stl_items_len + 1); |
4294 stl_tabtab = ALLOC_MULT(stl_hlrec_T, stl_items_len + 1); | 4277 stl_tabtab = ALLOC_MULT(stl_hlrec_T, stl_items_len + 1); |
4295 } | 4278 } |
4296 | 4279 |
4297 #ifdef FEAT_EVAL | 4280 #ifdef FEAT_EVAL |
4298 /* | 4281 // if "fmt" was set insecurely it needs to be evaluated in the sandbox |
4299 * When the format starts with "%!" then evaluate it as an expression and | 4282 use_sandbox = was_set_insecurely(opt_name, opt_scope); |
4300 * use the result as the actual format string. | 4283 |
4301 */ | 4284 // When the format starts with "%!" then evaluate it as an expression and |
4285 // use the result as the actual format string. | |
4302 if (fmt[0] == '%' && fmt[1] == '!') | 4286 if (fmt[0] == '%' && fmt[1] == '!') |
4303 { | 4287 { |
4304 typval_T tv; | 4288 typval_T tv; |
4305 | 4289 |
4306 tv.v_type = VAR_NUMBER; | 4290 tv.v_type = VAR_NUMBER; |
5179 redraw_not_allowed = save_redraw_not_allowed; | 5163 redraw_not_allowed = save_redraw_not_allowed; |
5180 | 5164 |
5181 // A user function may reset KeyTyped, restore it. | 5165 // A user function may reset KeyTyped, restore it. |
5182 KeyTyped = save_KeyTyped; | 5166 KeyTyped = save_KeyTyped; |
5183 | 5167 |
5168 // Check for an error. If there is one the display will be messed up and | |
5169 // might loop redrawing. Avoid that by making the corresponding option | |
5170 // empty. | |
5171 // TODO: find out why using called_emsg_before makes tests fail, does it | |
5172 // matter? | |
5173 // if (called_emsg > called_emsg_before) | |
5174 if (did_emsg > did_emsg_before) | |
5175 set_string_option_direct(opt_name, -1, (char_u *)"", | |
5176 OPT_FREE | opt_scope, SID_ERROR); | |
5177 | |
5184 return width; | 5178 return width; |
5185 } | 5179 } |
5186 #endif // FEAT_STL_OPT | 5180 #endif // FEAT_STL_OPT |
5187 | 5181 |
5188 /* | 5182 /* |