diff options
author | Bram Moolenaar <Bram@vim.org> | 2022-04-15 13:53:33 +0100 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2022-04-15 13:53:33 +0100 |
commit | 31e5c60a682840959cae6273ccadd9aae48c928d (patch) | |
tree | a72168baa32f1899937f3937a41b0832eac66b8f /src | |
parent | 5dc294a7b63ed0e508dd360bc4d98173f1a1aeec (diff) |
patch 8.2.4753: error from setting an option is silently ignoredv8.2.4753
Problem: Error from setting an option is silently ignored.
Solution: Handle option value errors better. Fix uses of N_().
Diffstat (limited to 'src')
-rw-r--r-- | src/channel.c | 5 | ||||
-rw-r--r-- | src/crypt.c | 4 | ||||
-rw-r--r-- | src/diff.c | 2 | ||||
-rw-r--r-- | src/edit.c | 4 | ||||
-rw-r--r-- | src/eval.c | 2 | ||||
-rw-r--r-- | src/evalfunc.c | 2 | ||||
-rw-r--r-- | src/evalvars.c | 2 | ||||
-rw-r--r-- | src/ex_cmds2.c | 14 | ||||
-rw-r--r-- | src/ex_docmd.c | 25 | ||||
-rw-r--r-- | src/ex_getln.c | 6 | ||||
-rw-r--r-- | src/getchar.c | 3 | ||||
-rw-r--r-- | src/gui.c | 7 | ||||
-rw-r--r-- | src/gui_gtk_x11.c | 3 | ||||
-rw-r--r-- | src/help.c | 3 | ||||
-rw-r--r-- | src/highlight.c | 4 | ||||
-rw-r--r-- | src/if_tcl.c | 2 | ||||
-rw-r--r-- | src/main.c | 26 | ||||
-rw-r--r-- | src/memline.c | 4 | ||||
-rw-r--r-- | src/message_test.c | 4 | ||||
-rw-r--r-- | src/option.c | 58 | ||||
-rw-r--r-- | src/optionstr.c | 24 | ||||
-rw-r--r-- | src/popupmenu.c | 18 | ||||
-rw-r--r-- | src/proto/option.pro | 3 | ||||
-rw-r--r-- | src/quickfix.c | 15 | ||||
-rw-r--r-- | src/scriptfile.c | 5 | ||||
-rw-r--r-- | src/spell.c | 6 | ||||
-rw-r--r-- | src/spellfile.c | 3 | ||||
-rw-r--r-- | src/term.c | 10 | ||||
-rw-r--r-- | src/undo.c | 2 | ||||
-rw-r--r-- | src/version.c | 2 | ||||
-rw-r--r-- | src/vim9script.c | 3 |
31 files changed, 155 insertions, 116 deletions
diff --git a/src/channel.c b/src/channel.c index e971e17c09..85089cb186 100644 --- a/src/channel.c +++ b/src/channel.c @@ -1183,8 +1183,9 @@ prepare_buffer(buf_T *buf) buf_copy_options(buf, BCO_ENTER); curbuf = buf; #ifdef FEAT_QUICKFIX - set_option_value((char_u *)"bt", 0L, (char_u *)"nofile", OPT_LOCAL); - set_option_value((char_u *)"bh", 0L, (char_u *)"hide", OPT_LOCAL); + set_option_value_give_err((char_u *)"bt", + 0L, (char_u *)"nofile", OPT_LOCAL); + set_option_value_give_err((char_u *)"bh", 0L, (char_u *)"hide", OPT_LOCAL); #endif if (curbuf->b_ml.ml_mfp == NULL) ml_open(curbuf); diff --git a/src/crypt.c b/src/crypt.c index 86f4846368..6a852fa1f9 100644 --- a/src/crypt.c +++ b/src/crypt.c @@ -752,7 +752,7 @@ crypt_check_swapfile_curbuf(void) // encryption uses padding and MAC, that does not work very well with // swap and undo files, so disable them mf_close_file(curbuf, TRUE); // remove the swap file - set_option_value((char_u *)"swf", 0, NULL, OPT_LOCAL); + set_option_value_give_err((char_u *)"swf", 0, NULL, OPT_LOCAL); msg_scroll = TRUE; msg(_("Note: Encryption of swapfile not supported, disabling swap file")); } @@ -807,7 +807,7 @@ crypt_get_key( if (store) { - set_option_value((char_u *)"key", 0L, p1, OPT_LOCAL); + set_option_value_give_err((char_u *)"key", 0L, p1, OPT_LOCAL); crypt_free_key(p1); p1 = curbuf->b_p_key; #ifdef FEAT_SODIUM diff --git a/src/diff.c b/src/diff.c index 00ccdb611f..df3dea0a17 100644 --- a/src/diff.c +++ b/src/diff.c @@ -1466,7 +1466,7 @@ set_diff_option(win_T *wp, int value) curwin = wp; curbuf = curwin->w_buffer; ++curbuf_lock; - set_option_value((char_u *)"diff", (long)value, NULL, OPT_LOCAL); + set_option_value_give_err((char_u *)"diff", (long)value, NULL, OPT_LOCAL); --curbuf_lock; curwin = old_curwin; curbuf = curwin->w_buffer; diff --git a/src/edit.c b/src/edit.c index c28c1f98a3..3790bfb5d6 100644 --- a/src/edit.c +++ b/src/edit.c @@ -4407,7 +4407,7 @@ bracketed_paste(paste_mode_T mode, int drop, garray_T *gap) if (!p_paste) // Also have the side effects of setting 'paste' to make it work much // faster. - set_option_value((char_u *)"paste", TRUE, NULL, 0); + set_option_value_give_err((char_u *)"paste", TRUE, NULL, 0); for (;;) { @@ -4482,7 +4482,7 @@ bracketed_paste(paste_mode_T mode, int drop, garray_T *gap) --no_mapping; allow_keys = save_allow_keys; if (!save_paste) - set_option_value((char_u *)"paste", FALSE, NULL, 0); + set_option_value_give_err((char_u *)"paste", FALSE, NULL, 0); return ret_char; } diff --git a/src/eval.c b/src/eval.c index 793a5263dd..90ed14b608 100644 --- a/src/eval.c +++ b/src/eval.c @@ -6801,7 +6801,7 @@ do_string_sub( // If it's still empty it was changed and restored, need to restore in // the complicated way. if (*p_cpo == NUL) - set_option_value((char_u *)"cpo", 0L, save_cpo, 0); + set_option_value_give_err((char_u *)"cpo", 0L, save_cpo, 0); free_string_option(save_cpo); } diff --git a/src/evalfunc.c b/src/evalfunc.c index e30186b034..da8f8457c5 100644 --- a/src/evalfunc.c +++ b/src/evalfunc.c @@ -9060,7 +9060,7 @@ theend: // If it's still empty it was changed and restored, need to restore in // the complicated way. if (*p_cpo == NUL) - set_option_value((char_u *)"cpo", 0L, save_cpo, 0); + set_option_value_give_err((char_u *)"cpo", 0L, save_cpo, 0); free_string_option(save_cpo); } diff --git a/src/evalvars.c b/src/evalvars.c index 0ee4b08d5c..4690d1ac47 100644 --- a/src/evalvars.c +++ b/src/evalvars.c @@ -4014,7 +4014,7 @@ set_option_from_tv(char_u *varname, typval_T *varp) strval = tv_get_string_buf_chk(varp, nbuf); } if (!error && strval != NULL) - set_option_value(varname, numval, strval, OPT_LOCAL); + set_option_value_give_err(varname, numval, strval, OPT_LOCAL); } /* diff --git a/src/ex_cmds2.c b/src/ex_cmds2.c index db82277aca..2de1798b18 100644 --- a/src/ex_cmds2.c +++ b/src/ex_cmds2.c @@ -563,9 +563,11 @@ ex_listdo(exarg_T *eap) // Clear 'shm' to avoid that the file message overwrites // any output from the command. p_shm_save = vim_strsave(p_shm); - set_option_value((char_u *)"shm", 0L, (char_u *)"", 0); + set_option_value_give_err((char_u *)"shm", + 0L, (char_u *)"", 0); do_argfile(eap, i); - set_option_value((char_u *)"shm", 0L, p_shm_save, 0); + set_option_value_give_err((char_u *)"shm", + 0L, p_shm_save, 0); vim_free(p_shm_save); } if (curwin->w_arg_idx != i) @@ -623,9 +625,9 @@ ex_listdo(exarg_T *eap) // Go to the next buffer. Clear 'shm' to avoid that the file // message overwrites any output from the command. p_shm_save = vim_strsave(p_shm); - set_option_value((char_u *)"shm", 0L, (char_u *)"", 0); + set_option_value_give_err((char_u *)"shm", 0L, (char_u *)"", 0); goto_buffer(eap, DOBUF_FIRST, FORWARD, next_fnum); - set_option_value((char_u *)"shm", 0L, p_shm_save, 0); + set_option_value_give_err((char_u *)"shm", 0L, p_shm_save, 0); vim_free(p_shm_save); // If autocommands took us elsewhere, quit here. @@ -645,9 +647,9 @@ ex_listdo(exarg_T *eap) // Clear 'shm' to avoid that the file message overwrites // any output from the command. p_shm_save = vim_strsave(p_shm); - set_option_value((char_u *)"shm", 0L, (char_u *)"", 0); + set_option_value_give_err((char_u *)"shm", 0L, (char_u *)"", 0); ex_cnext(eap); - set_option_value((char_u *)"shm", 0L, p_shm_save, 0); + set_option_value_give_err((char_u *)"shm", 0L, p_shm_save, 0); vim_free(p_shm_save); // If jumping to the next quickfix entry fails, quit here diff --git a/src/ex_docmd.c b/src/ex_docmd.c index ceb500dc13..47a12fd2cf 100644 --- a/src/ex_docmd.c +++ b/src/ex_docmd.c @@ -9423,18 +9423,23 @@ ex_behave(exarg_T *eap) { if (STRCMP(eap->arg, "mswin") == 0) { - set_option_value((char_u *)"selection", 0L, (char_u *)"exclusive", 0); - set_option_value((char_u *)"selectmode", 0L, (char_u *)"mouse,key", 0); - set_option_value((char_u *)"mousemodel", 0L, (char_u *)"popup", 0); - set_option_value((char_u *)"keymodel", 0L, - (char_u *)"startsel,stopsel", 0); + set_option_value_give_err((char_u *)"selection", + 0L, (char_u *)"exclusive", 0); + set_option_value_give_err((char_u *)"selectmode", + 0L, (char_u *)"mouse,key", 0); + set_option_value_give_err((char_u *)"mousemodel", + 0L, (char_u *)"popup", 0); + set_option_value_give_err((char_u *)"keymodel", + 0L, (char_u *)"startsel,stopsel", 0); } else if (STRCMP(eap->arg, "xterm") == 0) { - set_option_value((char_u *)"selection", 0L, (char_u *)"inclusive", 0); - set_option_value((char_u *)"selectmode", 0L, (char_u *)"", 0); - set_option_value((char_u *)"mousemodel", 0L, (char_u *)"extend", 0); - set_option_value((char_u *)"keymodel", 0L, (char_u *)"", 0); + set_option_value_give_err((char_u *)"selection", + 0L, (char_u *)"inclusive", 0); + set_option_value_give_err((char_u *)"selectmode", 0L, (char_u *)"", 0); + set_option_value_give_err((char_u *)"mousemodel", + 0L, (char_u *)"extend", 0); + set_option_value_give_err((char_u *)"keymodel", 0L, (char_u *)"", 0); } else semsg(_(e_invalid_argument_str), eap->arg); @@ -9548,7 +9553,7 @@ ex_setfiletype(exarg_T *eap) if (STRNCMP(arg, "FALLBACK ", 9) == 0) arg += 9; - set_option_value((char_u *)"filetype", 0L, arg, OPT_LOCAL); + set_option_value_give_err((char_u *)"filetype", 0L, arg, OPT_LOCAL); if (arg != eap->arg) did_filetype = FALSE; } diff --git a/src/ex_getln.c b/src/ex_getln.c index 3cacf9df76..c351cf2566 100644 --- a/src/ex_getln.c +++ b/src/ex_getln.c @@ -4367,7 +4367,8 @@ open_cmdwin(void) apply_autocmds(EVENT_BUFFILEPRE, NULL, NULL, FALSE, curbuf); (void)setfname(curbuf, (char_u *)_("[Command Line]"), NULL, TRUE); apply_autocmds(EVENT_BUFFILEPOST, NULL, NULL, FALSE, curbuf); - set_option_value((char_u *)"bt", 0L, (char_u *)"nofile", OPT_LOCAL); + set_option_value_give_err((char_u *)"bt", + 0L, (char_u *)"nofile", OPT_LOCAL); curbuf->b_p_ma = TRUE; #ifdef FEAT_FOLDING curwin->w_p_fen = FALSE; @@ -4392,7 +4393,8 @@ open_cmdwin(void) add_map((char_u *)"<buffer> <Tab> <C-X><C-V>", INSERT); add_map((char_u *)"<buffer> <Tab> a<C-X><C-V>", NORMAL); } - set_option_value((char_u *)"ft", 0L, (char_u *)"vim", OPT_LOCAL); + set_option_value_give_err((char_u *)"ft", + 0L, (char_u *)"vim", OPT_LOCAL); } --curbuf_lock; diff --git a/src/getchar.c b/src/getchar.c index fb7f00a95f..73cf4208be 100644 --- a/src/getchar.c +++ b/src/getchar.c @@ -2645,7 +2645,8 @@ handle_mapping( mlen - typebuf.tb_maplen); del_typebuf(mlen, 0); // remove the chars - set_option_value((char_u *)"paste", (long)!p_paste, NULL, 0); + set_option_value_give_err((char_u *)"paste", + (long)!p_paste, NULL, 0); if (!(State & INSERT)) { msg_col = 0; @@ -504,7 +504,7 @@ gui_init(void) * Reset 'paste'. It's useful in the terminal, but not in the GUI. It * breaks the Paste toolbar button. */ - set_option_value((char_u *)"paste", 0L, NULL, 0); + set_option_value_give_err((char_u *)"paste", 0L, NULL, 0); // Set t_Co to the number of colors: RGB. set_color_count(256 * 256 * 256); @@ -664,7 +664,8 @@ gui_init(void) * Set up the fonts. First use a font specified with "-fn" or "-font". */ if (font_argument != NULL) - set_option_value((char_u *)"gfn", 0L, (char_u *)font_argument, 0); + set_option_value_give_err((char_u *)"gfn", + 0L, (char_u *)font_argument, 0); if ( #ifdef FEAT_XFONTSET (*p_guifontset == NUL @@ -4814,7 +4815,7 @@ init_gui_options(void) // background color, unless the user has set it already. if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0) { - set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0); + set_option_value_give_err((char_u *)"bg", 0L, gui_bg_default(), 0); highlight_changed(); } } diff --git a/src/gui_gtk_x11.c b/src/gui_gtk_x11.c index acd36d3adf..d756f55294 100644 --- a/src/gui_gtk_x11.c +++ b/src/gui_gtk_x11.c @@ -3462,7 +3462,8 @@ gui_mch_init(void) * did_set_string_option() in option.c prohibits changing 'termencoding' * to something else than UTF-8 if the GUI is in use. */ - set_option_value((char_u *)"termencoding", 0L, (char_u *)"utf-8", 0); + set_option_value_give_err((char_u *)"termencoding", + 0L, (char_u *)"utf-8", 0); #ifdef FEAT_TOOLBAR gui_gtk_register_stock_icons(); diff --git a/src/help.c b/src/help.c index 48178fda3b..e58068020c 100644 --- a/src/help.c +++ b/src/help.c @@ -708,7 +708,8 @@ fix_help_buffer(void) if (STRCMP(curbuf->b_p_ft, "help") != 0) { ++curbuf_lock; - set_option_value((char_u *)"ft", 0L, (char_u *)"help", OPT_LOCAL); + set_option_value_give_err((char_u *)"ft", + 0L, (char_u *)"help", OPT_LOCAL); --curbuf_lock; } diff --git a/src/highlight.c b/src/highlight.c index 61fea9a669..6a2b0874df 100644 --- a/src/highlight.c +++ b/src/highlight.c @@ -974,8 +974,8 @@ highlight_set_ctermbg(int idx, int color, int is_normal_group) && dark != (*p_bg == 'd') && !option_was_set((char_u *)"bg")) { - set_option_value((char_u *)"bg", 0L, - (char_u *)(dark ? "dark" : "light"), 0); + set_option_value_give_err((char_u *)"bg", + 0L, (char_u *)(dark ? "dark" : "light"), 0); reset_option_was_set((char_u *)"bg"); } } diff --git a/src/if_tcl.c b/src/if_tcl.c index f66bfd3860..8a6af8db6b 100644 --- a/src/if_tcl.c +++ b/src/if_tcl.c @@ -1359,7 +1359,7 @@ tclsetoption( sval = (char_u *)Tcl_GetStringFromObj(objv[objn], NULL); if (err == TCL_OK) { - set_option_value(option, lval, sval, OPT_LOCAL); + set_option_value_give_err(option, lval, sval, OPT_LOCAL); err = vimerror(interp); } } diff --git a/src/main.c b/src/main.c index f9b1920733..931f6040bc 100644 --- a/src/main.c +++ b/src/main.c @@ -2033,7 +2033,8 @@ command_line_scan(mparm_T *parmp) use_gvimrc = (char_u *)"NONE"; #endif parmp->clean = TRUE; - set_option_value((char_u *)"vif", 0L, (char_u *)"NONE", 0); + set_option_value_give_err((char_u *)"vif", + 0L, (char_u *)"NONE", 0); } else if (STRNICMP(argv[0] + argv_idx, "literal", 7) == 0) { @@ -2115,7 +2116,7 @@ command_line_scan(mparm_T *parmp) case 'A': // "-A" start in Arabic mode #ifdef FEAT_ARABIC - set_option_value((char_u *)"arabic", 1L, NULL, 0); + set_option_value_give_err((char_u *)"arabic", 1L, NULL, 0); #else mch_errmsg(_(e_arabic_cannot_be_used_not_enabled_at_compile_time)); mch_exit(2); @@ -2171,7 +2172,7 @@ command_line_scan(mparm_T *parmp) case 'H': // "-H" start in Hebrew mode: rl + hkmap set #ifdef FEAT_RIGHTLEFT p_hkmap = TRUE; - set_option_value((char_u *)"rl", 1L, NULL, 0); + set_option_value_give_err((char_u *)"rl", 1L, NULL, 0); #else mch_errmsg(_(e_hebrew_cannot_be_used_not_enabled_at_compile_time)); mch_exit(2); @@ -2180,7 +2181,7 @@ command_line_scan(mparm_T *parmp) case 'l': // "-l" lisp mode, 'lisp' and 'showmatch' on #ifdef FEAT_LISP - set_option_value((char_u *)"lisp", 1L, NULL, 0); + set_option_value_give_err((char_u *)"lisp", 1L, NULL, 0); p_sm = TRUE; #endif break; @@ -2316,8 +2317,8 @@ command_line_scan(mparm_T *parmp) p_verbose = get_number_arg((char_u *)argv[0], &argv_idx, 10); if (argv[0][argv_idx] != NUL) { - set_option_value((char_u *)"verbosefile", 0L, - (char_u *)argv[0] + argv_idx, 0); + set_option_value_give_err((char_u *)"verbosefile", + 0L, (char_u *)argv[0] + argv_idx, 0); argv_idx = (int)STRLEN(argv[0]); } break; @@ -2334,7 +2335,7 @@ command_line_scan(mparm_T *parmp) if (vim_isdigit(((char_u *)argv[0])[argv_idx])) { n = get_number_arg((char_u *)argv[0], &argv_idx, 10); - set_option_value((char_u *)"window", n, NULL, 0); + set_option_value_give_err((char_u *)"window", n, NULL, 0); break; } want_argument = TRUE; @@ -2463,7 +2464,8 @@ command_line_scan(mparm_T *parmp) #endif case 'i': // "-i {viminfo}" use for viminfo - set_option_value((char_u *)"vif", 0L, (char_u *)argv[0], 0); + set_option_value_give_err((char_u *)"vif", + 0L, (char_u *)argv[0], 0); break; case 's': // "-s {scriptin}" read from script file @@ -2522,7 +2524,8 @@ scripterror: { argv_idx = 0; n = get_number_arg((char_u *)argv[0], &argv_idx, 10); - set_option_value((char_u *)"window", n, NULL, 0); + set_option_value_give_err((char_u *)"window", + n, NULL, 0); argv_idx = -1; break; } @@ -2967,7 +2970,8 @@ edit_buffers( p_shm_save = vim_strsave(p_shm); vim_snprintf(buf, 100, "F%s", p_shm); - set_option_value((char_u *)"shm", 0L, (char_u *)buf, 0); + set_option_value_give_err((char_u *)"shm", + 0L, (char_u *)buf, 0); } } else @@ -3016,7 +3020,7 @@ edit_buffers( if (p_shm_save != NULL) { - set_option_value((char_u *)"shm", 0L, p_shm_save, 0); + set_option_value_give_err((char_u *)"shm", 0L, p_shm_save, 0); vim_free(p_shm_save); } diff --git a/src/memline.c b/src/memline.c index f38e029bd1..e098aef552 100644 --- a/src/memline.c +++ b/src/memline.c @@ -1482,7 +1482,7 @@ ml_recover(int checkext) set_fileformat(b0_ff - 1, OPT_LOCAL); if (b0_fenc != NULL) { - set_option_value((char_u *)"fenc", 0L, b0_fenc, OPT_LOCAL); + set_option_value_give_err((char_u *)"fenc", 0L, b0_fenc, OPT_LOCAL); vim_free(b0_fenc); } unchanged(curbuf, TRUE, TRUE); @@ -1759,7 +1759,7 @@ ml_recover(int checkext) if (*buf->b_p_key != NUL && STRCMP(curbuf->b_p_key, buf->b_p_key) != 0) { msg_puts(_("Using crypt key from swap file for the text file.\n")); - set_option_value((char_u *)"key", 0L, buf->b_p_key, OPT_LOCAL); + set_option_value_give_err((char_u *)"key", 0L, buf->b_p_key, OPT_LOCAL); } #endif redraw_curbuf_later(NOT_VALID); diff --git a/src/message_test.c b/src/message_test.c index 882b591e43..940c1cc0b0 100644 --- a/src/message_test.c +++ b/src/message_test.c @@ -314,13 +314,13 @@ main(int argc, char **argv) params.argv = argv; common_init(¶ms); - set_option_value((char_u *)"encoding", 0, (char_u *)"utf-8", 0); + set_option_value_give_err((char_u *)"encoding", 0, (char_u *)"utf-8", 0); init_chartab(); test_trunc_string(); test_trunc_string_mbyte(); test_vim_snprintf(); - set_option_value((char_u *)"encoding", 0, (char_u *)"latin1", 0); + set_option_value_give_err((char_u *)"encoding", 0, (char_u *)"latin1", 0); init_chartab(); test_trunc_string(); test_vim_snprintf(); diff --git a/src/option.c b/src/option.c index cfd6817567..518e787dee 100644 --- a/src/option.c +++ b/src/option.c @@ -331,7 +331,7 @@ set_init_1(int clean_arg) #ifdef FEAT_GUI if (found_reverse_arg) - set_option_value((char_u *)"bg", 0L, (char_u *)"dark", 0); + set_option_value_give_err((char_u *)"bg", 0L, (char_u *)"dark", 0); #endif curbuf->b_p_initialized = TRUE; @@ -389,7 +389,7 @@ set_init_1(int clean_arg) // NOTE: mlterm's author is being asked to 'set' a variable // instead of an environment variable due to inheritance. if (mch_getenv((char_u *)"MLTERM") != NULL) - set_option_value((char_u *)"tbidi", 1L, NULL, 0); + set_option_value_give_err((char_u *)"tbidi", 1L, NULL, 0); #endif didset_options2(); @@ -1406,7 +1406,7 @@ do_set( && vim_strchr((char_u *)"!&<", *arg) != NULL) errmsg = e_no_white_space_allowed_between_option_and; else - errmsg = N_(e_unknown_option); + errmsg = e_unknown_option; goto skip; } @@ -1419,7 +1419,7 @@ do_set( if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL && (!(options[opt_idx].flags & P_BOOL) || nextchar == '?')) - errmsg = N_(e_option_not_supported); + errmsg = e_option_not_supported; goto skip; } @@ -1457,12 +1457,12 @@ do_set( { if (flags & (P_SECURE | P_NO_ML)) { - errmsg = N_(e_not_allowed_in_modeline); + errmsg = e_not_allowed_in_modeline; goto skip; } if ((flags & P_MLE) && !p_mle) { - errmsg = N_(e_not_allowed_in_modeline_when_modelineexpr_is_off); + errmsg = e_not_allowed_in_modeline_when_modelineexpr_is_off; goto skip; } #ifdef FEAT_DIFF @@ -1558,7 +1558,7 @@ do_set( p = find_termcode(key_name); if (p == NULL) { - errmsg = N_(e_key_code_not_set); + errmsg = e_key_code_not_set; goto skip; } else @@ -1682,13 +1682,13 @@ do_set( if (i == 0 || (arg[i] != NUL && !VIM_ISWHITE(arg[i]))) { - errmsg = N_(e_number_required_after_equal); + errmsg = e_number_required_after_equal; goto skip; } } else { - errmsg = N_(e_number_required_after_equal); + errmsg = e_number_required_after_equal; goto skip; } @@ -2140,7 +2140,7 @@ do_set( if (nextchar == '&') { if (add_termcap_entry(key_name, TRUE) == FAIL) - errmsg = N_(e_not_found_in_termcap); + errmsg = e_not_found_in_termcap; } else { @@ -2724,6 +2724,7 @@ set_bool_option( #if defined(FEAT_EVAL) int old_global_value = 0; #endif + char *errmsg = NULL; // Disallow changing some options from secure mode if ((secure @@ -2838,7 +2839,7 @@ set_bool_option( && curbuf->b_term != NULL && !term_is_finished(curbuf)))) { curbuf->b_p_ma = FALSE; - return N_(e_cannot_make_terminal_with_running_job_modifiable); + return e_cannot_make_terminal_with_running_job_modifiable; } # endif redraw_titles(); @@ -2966,7 +2967,7 @@ set_bool_option( if (win->w_p_pvw && win != curwin) { curwin->w_p_pvw = FALSE; - return N_(e_preview_window_already_exists); + return e_preview_window_already_exists; } } } @@ -3121,12 +3122,7 @@ set_bool_option( else if ((int *)varp == &curwin->w_p_spell) { if (curwin->w_p_spell) - { - char *errmsg = did_set_spelllang(curwin); - - if (errmsg != NULL) - emsg(_(errmsg)); - } + errmsg = did_set_spelllang(curwin); } #endif @@ -3173,8 +3169,8 @@ set_bool_option( # ifdef FEAT_KEYMAP // Force-set the necessary keymap for arabic - set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic", - OPT_LOCAL); + errmsg = set_option_value((char_u *)"keymap", + 0L, (char_u *)"arabic", OPT_LOCAL); # endif } else @@ -3239,7 +3235,7 @@ set_bool_option( !has_vtp_working()) { p_tgc = 0; - return N_(e_24_bit_colors_are_not_supported_on_this_environment); + return e_24_bit_colors_are_not_supported_on_this_environment; } if (is_term_win32()) swap_tcap(); @@ -3287,7 +3283,7 @@ set_bool_option( if ((opt_flags & OPT_NO_REDRAW) == 0) check_redraw(options[opt_idx].flags); - return NULL; + return errmsg; } /* @@ -4329,7 +4325,7 @@ is_crypt_key_option(int opt_idx) * Set the value of option "name". * Use "string" for string options, use "number" for other options. * - * Returns NULL on success or error message on error. + * Returns NULL on success or an untranslated error message on error. */ char * set_option_value( @@ -4419,6 +4415,22 @@ set_option_value( } /* + * Call set_option_value() and when an error is returned report it. + */ + void +set_option_value_give_err( + char_u *name, + long number, + char_u *string, + int opt_flags) // OPT_LOCAL or 0 (both) +{ + char *errmsg = set_option_value(name, number, string, opt_flags); + + if (errmsg != NULL) + emsg(_(errmsg)); +} + +/* * Get the terminal code for a terminal option. * Returns NULL when not found. */ diff --git a/src/optionstr.c b/src/optionstr.c index 7f130ddf87..698a3f3f9b 100644 --- a/src/optionstr.c +++ b/src/optionstr.c @@ -484,7 +484,7 @@ set_string_option_direct_in_buf( /* * Set a string option to a new value, and handle the effects. * - * Returns NULL on success or error message on error. + * Returns NULL on success or an untranslated error message on error. */ char * set_string_option( @@ -503,7 +503,7 @@ set_string_option( char_u *saved_oldval_g = NULL; char_u *saved_newval = NULL; #endif - char *r = NULL; + char *errmsg = NULL; int value_checked = FALSE; if (is_hidden_option(opt_idx)) // don't set hidden option @@ -542,13 +542,13 @@ set_string_option( saved_newval = vim_strsave(s); } #endif - if ((r = did_set_string_option(opt_idx, varp, TRUE, oldval, NULL, + if ((errmsg = did_set_string_option(opt_idx, varp, TRUE, oldval, NULL, opt_flags, &value_checked)) == NULL) did_set_option(opt_idx, opt_flags, TRUE, value_checked); #if defined(FEAT_EVAL) // call autocommand after handling side effects - if (r == NULL) + if (errmsg == NULL) trigger_optionsset_string(opt_idx, opt_flags, saved_oldval, saved_oldval_l, saved_oldval_g, saved_newval); @@ -558,7 +558,7 @@ set_string_option( vim_free(saved_newval); #endif } - return r; + return errmsg; } /* @@ -753,7 +753,7 @@ did_set_string_option( { if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex, *p_pm == '.' ? p_pm + 1 : p_pm) == 0) - errmsg = N_(e_backupext_and_patchmode_are_equal); + errmsg = e_backupext_and_patchmode_are_equal; } #ifdef FEAT_LINEBREAK // 'breakindentopt' @@ -878,7 +878,7 @@ did_set_string_option( if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK) errmsg = e_invalid_argument; else if (set_chars_option(curwin, &p_fcs) != NULL) - errmsg = _(e_conflicts_with_value_of_fillchars); + errmsg = e_conflicts_with_value_of_fillchars; else { tabpage_T *tp; @@ -888,7 +888,7 @@ did_set_string_option( { if (set_chars_option(wp, &wp->w_p_lcs) != NULL) { - errmsg = _(e_conflicts_with_value_of_listchars); + errmsg = e_conflicts_with_value_of_listchars; goto ambw_end; } } @@ -1492,7 +1492,7 @@ ambw_end: for (s = *varp; *s; ) { if (ptr2cells(s) != 1) - errmsg = N_(e_showbreak_contains_unprintable_or_wide_character); + errmsg = e_showbreak_contains_unprintable_or_wide_character; MB_PTR_ADV(s); } } @@ -1534,7 +1534,7 @@ ambw_end: } else # endif - errmsg = N_(e_invalid_fonts); + errmsg = e_invalid_fonts; } } redraw_gui_only = TRUE; @@ -1543,9 +1543,9 @@ ambw_end: else if (varp == &p_guifontset) { if (STRCMP(p_guifontset, "*") == 0) - errmsg = N_(e_cant_select_fontset); + errmsg = e_cant_select_fontset; else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK) - errmsg = N_(e_invalid_fontset); + errmsg = e_invalid_fontset; redraw_gui_only = TRUE; } # endif diff --git a/src/popupmenu.c b/src/popupmenu.c index f05b7bd94d..9a9bfab1a9 100644 --- a/src/popupmenu.c +++ b/src/popupmenu.c @@ -876,14 +876,16 @@ pum_set_selected(int n, int repeat UNUSED) { // Edit a new, empty buffer. Set options for a "wipeout" // buffer. - set_option_value((char_u *)"swf", 0L, NULL, OPT_LOCAL); - set_option_value((char_u *)"bl", 0L, NULL, OPT_LOCAL); - set_option_value((char_u *)"bt", 0L, - (char_u *)"nofile", OPT_LOCAL); - set_option_value((char_u *)"bh", 0L, - (char_u *)"wipe", OPT_LOCAL); - set_option_value((char_u *)"diff", 0L, - NULL, OPT_LOCAL); + set_option_value_give_err((char_u *)"swf", + 0L, NULL, OPT_LOCAL); + set_option_value_give_err((char_u *)"bl", + 0L, NULL, OPT_LOCAL); + set_option_value_give_err((char_u *)"bt", + 0L, (char_u *)"nofile", OPT_LOCAL); + set_option_value_give_err((char_u *)"bh", + 0L, (char_u *)"wipe", OPT_LOCAL); + set_option_value_give_err((char_u *)"diff", |