comparison src/option.c @ 28457:4dcccb2673fe v8.2.4753

patch 8.2.4753: error from setting an option is silently ignored Commit: https://github.com/vim/vim/commit/31e5c60a682840959cae6273ccadd9aae48c928d Author: Bram Moolenaar <Bram@vim.org> Date: Fri Apr 15 13:53:33 2022 +0100 patch 8.2.4753: error from setting an option is silently ignored Problem: Error from setting an option is silently ignored. Solution: Handle option value errors better. Fix uses of N_().
author Bram Moolenaar <Bram@vim.org>
date Fri, 15 Apr 2022 15:00:04 +0200
parents 473cfd79bcd8
children d770568e6c98
comparison
equal deleted inserted replaced
28456:6353f897ac82 28457:4dcccb2673fe
329 } 329 }
330 #endif 330 #endif
331 331
332 #ifdef FEAT_GUI 332 #ifdef FEAT_GUI
333 if (found_reverse_arg) 333 if (found_reverse_arg)
334 set_option_value((char_u *)"bg", 0L, (char_u *)"dark", 0); 334 set_option_value_give_err((char_u *)"bg", 0L, (char_u *)"dark", 0);
335 #endif 335 #endif
336 336
337 curbuf->b_p_initialized = TRUE; 337 curbuf->b_p_initialized = TRUE;
338 curbuf->b_p_ar = -1; // no local 'autoread' value 338 curbuf->b_p_ar = -1; // no local 'autoread' value
339 curbuf->b_p_ul = NO_LOCAL_UNDOLEVEL; 339 curbuf->b_p_ul = NO_LOCAL_UNDOLEVEL;
387 // Mlterm is a terminal emulator akin to xterm that has some special 387 // Mlterm is a terminal emulator akin to xterm that has some special
388 // abilities (bidi namely). 388 // abilities (bidi namely).
389 // NOTE: mlterm's author is being asked to 'set' a variable 389 // NOTE: mlterm's author is being asked to 'set' a variable
390 // instead of an environment variable due to inheritance. 390 // instead of an environment variable due to inheritance.
391 if (mch_getenv((char_u *)"MLTERM") != NULL) 391 if (mch_getenv((char_u *)"MLTERM") != NULL)
392 set_option_value((char_u *)"tbidi", 1L, NULL, 0); 392 set_option_value_give_err((char_u *)"tbidi", 1L, NULL, 0);
393 #endif 393 #endif
394 394
395 didset_options2(); 395 didset_options2();
396 396
397 # if defined(MSWIN) && defined(FEAT_GETTEXT) 397 # if defined(MSWIN) && defined(FEAT_GETTEXT)
1404 { 1404 {
1405 if (in_vim9script() && arg > arg_start 1405 if (in_vim9script() && arg > arg_start
1406 && vim_strchr((char_u *)"!&<", *arg) != NULL) 1406 && vim_strchr((char_u *)"!&<", *arg) != NULL)
1407 errmsg = e_no_white_space_allowed_between_option_and; 1407 errmsg = e_no_white_space_allowed_between_option_and;
1408 else 1408 else
1409 errmsg = N_(e_unknown_option); 1409 errmsg = e_unknown_option;
1410 goto skip; 1410 goto skip;
1411 } 1411 }
1412 1412
1413 if (opt_idx >= 0) 1413 if (opt_idx >= 0)
1414 { 1414 {
1417 // Only give an error message when requesting the value of 1417 // Only give an error message when requesting the value of
1418 // a hidden option, ignore setting it. 1418 // a hidden option, ignore setting it.
1419 if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL 1419 if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL
1420 && (!(options[opt_idx].flags & P_BOOL) 1420 && (!(options[opt_idx].flags & P_BOOL)
1421 || nextchar == '?')) 1421 || nextchar == '?'))
1422 errmsg = N_(e_option_not_supported); 1422 errmsg = e_option_not_supported;
1423 goto skip; 1423 goto skip;
1424 } 1424 }
1425 1425
1426 flags = options[opt_idx].flags; 1426 flags = options[opt_idx].flags;
1427 varp = get_varp_scope(&(options[opt_idx]), opt_flags); 1427 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
1455 // Disallow changing some options from modelines. 1455 // Disallow changing some options from modelines.
1456 if (opt_flags & OPT_MODELINE) 1456 if (opt_flags & OPT_MODELINE)
1457 { 1457 {
1458 if (flags & (P_SECURE | P_NO_ML)) 1458 if (flags & (P_SECURE | P_NO_ML))
1459 { 1459 {
1460 errmsg = N_(e_not_allowed_in_modeline); 1460 errmsg = e_not_allowed_in_modeline;
1461 goto skip; 1461 goto skip;
1462 } 1462 }
1463 if ((flags & P_MLE) && !p_mle) 1463 if ((flags & P_MLE) && !p_mle)
1464 { 1464 {
1465 errmsg = N_(e_not_allowed_in_modeline_when_modelineexpr_is_off); 1465 errmsg = e_not_allowed_in_modeline_when_modelineexpr_is_off;
1466 goto skip; 1466 goto skip;
1467 } 1467 }
1468 #ifdef FEAT_DIFF 1468 #ifdef FEAT_DIFF
1469 // In diff mode some options are overruled. This avoids that 1469 // In diff mode some options are overruled. This avoids that
1470 // 'foldmethod' becomes "marker" instead of "diff" and that 1470 // 'foldmethod' becomes "marker" instead of "diff" and that
1556 char_u *p; 1556 char_u *p;
1557 1557
1558 p = find_termcode(key_name); 1558 p = find_termcode(key_name);
1559 if (p == NULL) 1559 if (p == NULL)
1560 { 1560 {
1561 errmsg = N_(e_key_code_not_set); 1561 errmsg = e_key_code_not_set;
1562 goto skip; 1562 goto skip;
1563 } 1563 }
1564 else 1564 else
1565 (void)show_one_termcode(key_name, p, TRUE); 1565 (void)show_one_termcode(key_name, p, TRUE);
1566 } 1566 }
1680 vim_str2nr(arg, NULL, &i, STR2NR_ALL, 1680 vim_str2nr(arg, NULL, &i, STR2NR_ALL,
1681 &value, NULL, 0, TRUE); 1681 &value, NULL, 0, TRUE);
1682 if (i == 0 || (arg[i] != NUL 1682 if (i == 0 || (arg[i] != NUL
1683 && !VIM_ISWHITE(arg[i]))) 1683 && !VIM_ISWHITE(arg[i])))
1684 { 1684 {
1685 errmsg = N_(e_number_required_after_equal); 1685 errmsg = e_number_required_after_equal;
1686 goto skip; 1686 goto skip;
1687 } 1687 }
1688 } 1688 }
1689 else 1689 else
1690 { 1690 {
1691 errmsg = N_(e_number_required_after_equal); 1691 errmsg = e_number_required_after_equal;
1692 goto skip; 1692 goto skip;
1693 } 1693 }
1694 1694
1695 if (adding) 1695 if (adding)
1696 value = *(long *)varp + value; 1696 value = *(long *)varp + value;
2138 char_u *p; 2138 char_u *p;
2139 2139
2140 if (nextchar == '&') 2140 if (nextchar == '&')
2141 { 2141 {
2142 if (add_termcap_entry(key_name, TRUE) == FAIL) 2142 if (add_termcap_entry(key_name, TRUE) == FAIL)
2143 errmsg = N_(e_not_found_in_termcap); 2143 errmsg = e_not_found_in_termcap;
2144 } 2144 }
2145 else 2145 else
2146 { 2146 {
2147 ++arg; // jump to after the '=' or ':' 2147 ++arg; // jump to after the '=' or ':'
2148 for (p = arg; *p && !VIM_ISWHITE(*p); ++p) 2148 for (p = arg; *p && !VIM_ISWHITE(*p); ++p)
2722 { 2722 {
2723 int old_value = *(int *)varp; 2723 int old_value = *(int *)varp;
2724 #if defined(FEAT_EVAL) 2724 #if defined(FEAT_EVAL)
2725 int old_global_value = 0; 2725 int old_global_value = 0;
2726 #endif 2726 #endif
2727 char *errmsg = NULL;
2727 2728
2728 // Disallow changing some options from secure mode 2729 // Disallow changing some options from secure mode
2729 if ((secure 2730 if ((secure
2730 #ifdef HAVE_SANDBOX 2731 #ifdef HAVE_SANDBOX
2731 || sandbox != 0 2732 || sandbox != 0
2836 // Cannot set 'modifiable' when in Terminal mode. 2837 // Cannot set 'modifiable' when in Terminal mode.
2837 if (curbuf->b_p_ma && (term_in_normal_mode() || (bt_terminal(curbuf) 2838 if (curbuf->b_p_ma && (term_in_normal_mode() || (bt_terminal(curbuf)
2838 && curbuf->b_term != NULL && !term_is_finished(curbuf)))) 2839 && curbuf->b_term != NULL && !term_is_finished(curbuf))))
2839 { 2840 {
2840 curbuf->b_p_ma = FALSE; 2841 curbuf->b_p_ma = FALSE;
2841 return N_(e_cannot_make_terminal_with_running_job_modifiable); 2842 return e_cannot_make_terminal_with_running_job_modifiable;
2842 } 2843 }
2843 # endif 2844 # endif
2844 redraw_titles(); 2845 redraw_titles();
2845 } 2846 }
2846 // when 'endofline' is changed, redraw the window title 2847 // when 'endofline' is changed, redraw the window title
2964 2965
2965 FOR_ALL_WINDOWS(win) 2966 FOR_ALL_WINDOWS(win)
2966 if (win->w_p_pvw && win != curwin) 2967 if (win->w_p_pvw && win != curwin)
2967 { 2968 {
2968 curwin->w_p_pvw = FALSE; 2969 curwin->w_p_pvw = FALSE;
2969 return N_(e_preview_window_already_exists); 2970 return e_preview_window_already_exists;
2970 } 2971 }
2971 } 2972 }
2972 } 2973 }
2973 #endif 2974 #endif
2974 2975
3119 #ifdef FEAT_SPELL 3120 #ifdef FEAT_SPELL
3120 // 'spell' 3121 // 'spell'
3121 else if ((int *)varp == &curwin->w_p_spell) 3122 else if ((int *)varp == &curwin->w_p_spell)
3122 { 3123 {
3123 if (curwin->w_p_spell) 3124 if (curwin->w_p_spell)
3124 { 3125 errmsg = did_set_spelllang(curwin);
3125 char *errmsg = did_set_spelllang(curwin);
3126
3127 if (errmsg != NULL)
3128 emsg(_(errmsg));
3129 }
3130 } 3126 }
3131 #endif 3127 #endif
3132 3128
3133 #ifdef FEAT_ARABIC 3129 #ifdef FEAT_ARABIC
3134 if ((int *)varp == &curwin->w_p_arab) 3130 if ((int *)varp == &curwin->w_p_arab)
3171 // set 'delcombine' 3167 // set 'delcombine'
3172 p_deco = TRUE; 3168 p_deco = TRUE;
3173 3169
3174 # ifdef FEAT_KEYMAP 3170 # ifdef FEAT_KEYMAP
3175 // Force-set the necessary keymap for arabic 3171 // Force-set the necessary keymap for arabic
3176 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic", 3172 errmsg = set_option_value((char_u *)"keymap",
3177 OPT_LOCAL); 3173 0L, (char_u *)"arabic", OPT_LOCAL);
3178 # endif 3174 # endif
3179 } 3175 }
3180 else 3176 else
3181 { 3177 {
3182 /* 3178 /*
3237 !gui.in_use && !gui.starting && 3233 !gui.in_use && !gui.starting &&
3238 # endif 3234 # endif
3239 !has_vtp_working()) 3235 !has_vtp_working())
3240 { 3236 {
3241 p_tgc = 0; 3237 p_tgc = 0;
3242 return N_(e_24_bit_colors_are_not_supported_on_this_environment); 3238 return e_24_bit_colors_are_not_supported_on_this_environment;
3243 } 3239 }
3244 if (is_term_win32()) 3240 if (is_term_win32())
3245 swap_tcap(); 3241 swap_tcap();
3246 # endif 3242 # endif
3247 # ifdef FEAT_GUI 3243 # ifdef FEAT_GUI
3285 curwin->w_set_curswant = TRUE; 3281 curwin->w_set_curswant = TRUE;
3286 3282
3287 if ((opt_flags & OPT_NO_REDRAW) == 0) 3283 if ((opt_flags & OPT_NO_REDRAW) == 0)
3288 check_redraw(options[opt_idx].flags); 3284 check_redraw(options[opt_idx].flags);
3289 3285
3290 return NULL; 3286 return errmsg;
3291 } 3287 }
3292 3288
3293 /* 3289 /*
3294 * Set the value of a number option, and take care of side effects. 3290 * Set the value of a number option, and take care of side effects.
3295 * Returns NULL for success, or an error message for an error. 3291 * Returns NULL for success, or an error message for an error.
4327 4323
4328 /* 4324 /*
4329 * Set the value of option "name". 4325 * Set the value of option "name".
4330 * Use "string" for string options, use "number" for other options. 4326 * Use "string" for string options, use "number" for other options.
4331 * 4327 *
4332 * Returns NULL on success or error message on error. 4328 * Returns NULL on success or an untranslated error message on error.
4333 */ 4329 */
4334 char * 4330 char *
4335 set_option_value( 4331 set_option_value(
4336 char_u *name, 4332 char_u *name,
4337 long number, 4333 long number,
4414 return set_bool_option(opt_idx, varp, (int)number, opt_flags); 4410 return set_bool_option(opt_idx, varp, (int)number, opt_flags);
4415 } 4411 }
4416 4412
4417 } 4413 }
4418 return NULL; 4414 return NULL;
4415 }
4416
4417 /*
4418 * Call set_option_value() and when an error is returned report it.
4419 */
4420 void
4421 set_option_value_give_err(
4422 char_u *name,
4423 long number,
4424 char_u *string,
4425 int opt_flags) // OPT_LOCAL or 0 (both)
4426 {
4427 char *errmsg = set_option_value(name, number, string, opt_flags);
4428
4429 if (errmsg != NULL)
4430 emsg(_(errmsg));
4419 } 4431 }
4420 4432
4421 /* 4433 /*
4422 * Get the terminal code for a terminal option. 4434 * Get the terminal code for a terminal option.
4423 * Returns NULL when not found. 4435 * Returns NULL when not found.