diff options
-rw-r--r-- | src/gui_xim.c | 14 | ||||
-rw-r--r-- | src/insexpand.c | 27 | ||||
-rw-r--r-- | src/ops.c | 7 | ||||
-rw-r--r-- | src/optionstr.c | 3258 | ||||
-rw-r--r-- | src/proto/gui_xim.pro | 4 | ||||
-rw-r--r-- | src/proto/insexpand.pro | 6 | ||||
-rw-r--r-- | src/proto/ops.pro | 2 | ||||
-rw-r--r-- | src/proto/quickfix.pro | 2 | ||||
-rw-r--r-- | src/proto/tag.pro | 2 | ||||
-rw-r--r-- | src/quickfix.c | 7 | ||||
-rw-r--r-- | src/spell.c | 2 | ||||
-rw-r--r-- | src/tag.c | 8 | ||||
-rw-r--r-- | src/version.c | 2 |
13 files changed, 2035 insertions, 1306 deletions
diff --git a/src/gui_xim.c b/src/gui_xim.c index 163cbdaa0f..86273b5c3d 100644 --- a/src/gui_xim.c +++ b/src/gui_xim.c @@ -73,16 +73,22 @@ xim_log(char *s, ...) static callback_T imaf_cb; // 'imactivatefunc' callback function static callback_T imsf_cb; // 'imstatusfunc' callback function - int + char * set_imactivatefunc_option(void) { - return option_set_callback_func(p_imaf, &imaf_cb); + if (option_set_callback_func(p_imaf, &imaf_cb) == FAIL) + return e_invalid_argument; + + return NULL; } - int + char * set_imstatusfunc_option(void) { - return option_set_callback_func(p_imsf, &imsf_cb); + if (option_set_callback_func(p_imsf, &imsf_cb) == FAIL) + return e_invalid_argument; + + return NULL; } static void diff --git a/src/insexpand.c b/src/insexpand.c index 2351ac65c9..a8d986a2cd 100644 --- a/src/insexpand.c +++ b/src/insexpand.c @@ -2545,16 +2545,15 @@ copy_global_to_buflocal_cb(callback_T *globcb, callback_T *bufcb) * name of a function (string), or function(<name>) or funcref(<name>) or a * lambda expression. */ - int + char * set_completefunc_option(void) { - int retval; + if (option_set_callback_func(curbuf->b_p_cfu, &cfu_cb) == FAIL) + return e_invalid_argument; - retval = option_set_callback_func(curbuf->b_p_cfu, &cfu_cb); - if (retval == OK) - set_buflocal_cfu_callback(curbuf); + set_buflocal_cfu_callback(curbuf); - return retval; + return NULL; } /* @@ -2575,16 +2574,14 @@ set_buflocal_cfu_callback(buf_T *buf UNUSED) * name of a function (string), or function(<name>) or funcref(<name>) or a * lambda expression. */ - int + char * set_omnifunc_option(void) { - int retval; + if (option_set_callback_func(curbuf->b_p_ofu, &ofu_cb) == FAIL) + return e_invalid_argument; - retval = option_set_callback_func(curbuf->b_p_ofu, &ofu_cb); - if (retval == OK) - set_buflocal_ofu_callback(curbuf); - - return retval; + set_buflocal_ofu_callback(curbuf); + return NULL; } /* @@ -2605,7 +2602,7 @@ set_buflocal_ofu_callback(buf_T *buf UNUSED) * name of a function (string), or function(<name>) or funcref(<name>) or a * lambda expression. */ - int + char * set_thesaurusfunc_option(void) { int retval; @@ -2622,7 +2619,7 @@ set_thesaurusfunc_option(void) retval = option_set_callback_func(p_tsrfu, &tsrfu_cb); } - return retval; + return retval == FAIL ? e_invalid_argument : NULL; } /* @@ -3405,10 +3405,13 @@ static callback_T opfunc_cb; * Process the 'operatorfunc' option value. * Returns OK or FAIL. */ - int + char * set_operatorfunc_option(void) { - return option_set_callback_func(p_opfunc, &opfunc_cb); + if (option_set_callback_func(p_opfunc, &opfunc_cb) == FAIL) + return e_invalid_argument; + + return NULL; } #if defined(EXITFREE) || defined(PROTO) diff --git a/src/optionstr.c b/src/optionstr.c index 0eb9f5b742..1329be31a0 100644 --- a/src/optionstr.c +++ b/src/optionstr.c @@ -640,905 +640,2103 @@ check_stl_option(char_u *s) #endif /* - * Handle string options that need some action to perform when changed. - * The new value must be allocated. - * Returns NULL for success, or an unstranslated error message for an error. + * The 'term' option is changed. */ - char * -did_set_string_option( - int opt_idx, // index in options[] table - char_u **varp, // pointer to the option variable - char_u *oldval, // previous value of the option - char *errbuf, // buffer for errors, or NULL - int opt_flags, // OPT_LOCAL and/or OPT_GLOBAL - int *value_checked) // value was checked to be save, no - // need to set P_INSECURE + static char * +did_set_term(int *opt_idx, long_u *free_oldval) { - char *errmsg = NULL; - char_u *s, *p; - int did_chartab = FALSE; - char_u **gvarp; - long_u free_oldval = (get_option_flags(opt_idx) & P_ALLOCED); + char *errmsg = NULL; + + if (T_NAME[0] == NUL) + errmsg = e_cannot_set_term_to_empty_string; #ifdef FEAT_GUI - // set when changing an option that only requires a redraw in the GUI - int redraw_gui_only = FALSE; -#endif - int value_changed = FALSE; -#if defined(FEAT_VTP) && defined(FEAT_TERMGUICOLORS) - int did_swaptcap = FALSE; + else if (gui.in_use) + errmsg = e_cannot_change_term_in_GUI; + else if (term_is_gui(T_NAME)) + errmsg = e_use_gui_to_start_GUI; #endif + else if (set_termname(T_NAME) == FAIL) + errmsg = e_not_found_in_termcap; + else + { + // Screen colors may have changed. + redraw_later_clear(); - // Get the global option to compare with, otherwise we would have to check - // two values for all local options. - gvarp = (char_u **)get_option_varp_scope(opt_idx, OPT_GLOBAL); + // Both 'term' and 'ttytype' point to T_NAME, only set the + // P_ALLOCED flag on 'term'. + *opt_idx = findoption((char_u *)"term"); + *free_oldval = (get_option_flags(*opt_idx) & P_ALLOCED); + } - // Disallow changing some options from secure mode - if ((secure -#ifdef HAVE_SANDBOX - || sandbox != 0 -#endif - ) && (get_option_flags(opt_idx) & P_SECURE)) - errmsg = e_not_allowed_here; + return errmsg; +} - // Check for a "normal" directory or file name in some options. Disallow a - // path separator (slash and/or backslash), wildcards and characters that - // are often illegal in a file name. Be more permissive if "secure" is off. - else if (((get_option_flags(opt_idx) & P_NFNAME) - && vim_strpbrk(*varp, (char_u *)(secure - ? "/\\*?[|;&<>\r\n" : "/\\*?[<>\r\n")) != NULL) - || ((get_option_flags(opt_idx) & P_NDNAME) - && vim_strpbrk(*varp, (char_u *)"*?[|;&<>\r\n") != NULL)) - errmsg = e_invalid_argument; +/* + * The 'backupcopy' option is changed. + */ + static char * +did_set_backupcopy( + char_u *oldval, + int opt_flags) +{ + char_u *bkc = p_bkc; + unsigned int *flags = &bkc_flags; + char *errmsg = NULL; - // 'term' - else if (varp == &T_NAME) + if (opt_flags & OPT_LOCAL) { - if (T_NAME[0] == NUL) - errmsg = e_cannot_set_term_to_empty_string; -#ifdef FEAT_GUI - else if (gui.in_use) - errmsg = e_cannot_change_term_in_GUI; - else if (term_is_gui(T_NAME)) - errmsg = e_use_gui_to_start_GUI; -#endif - else if (set_termname(T_NAME) == FAIL) - errmsg = e_not_found_in_termcap; - else - { - // Screen colors may have changed. - redraw_later_clear(); - - // Both 'term' and 'ttytype' point to T_NAME, only set the - // P_ALLOCED flag on 'term'. - opt_idx = findoption((char_u *)"term"); - free_oldval = (get_option_flags(opt_idx) & P_ALLOCED); - } + bkc = curbuf->b_p_bkc; + flags = &curbuf->b_bkc_flags; } - // 'backupcopy' - else if (gvarp == &p_bkc) + if ((opt_flags & OPT_LOCAL) && *bkc == NUL) + // make the local value empty: use the global value + *flags = 0; + else { - char_u *bkc = p_bkc; - unsigned int *flags = &bkc_flags; - - if (opt_flags & OPT_LOCAL) - { - bkc = curbuf->b_p_bkc; - flags = &curbuf->b_bkc_flags; - } - - if ((opt_flags & OPT_LOCAL) && *bkc == NUL) - // make the local value empty: use the global value - *flags = 0; - else + if (opt_strings_flags(bkc, p_bkc_values, flags, TRUE) != OK) + errmsg = e_invalid_argument; + if ((((int)*flags & BKC_AUTO) != 0) + + (((int)*flags & BKC_YES) != 0) + + (((int)*flags & BKC_NO) != 0) != 1) { - if (opt_strings_flags(bkc, p_bkc_values, flags, TRUE) != OK) - errmsg = e_invalid_argument; - if ((((int)*flags & BKC_AUTO) != 0) - + (((int)*flags & BKC_YES) != 0) - + (((int)*flags & BKC_NO) != 0) != 1) - { - // Must have exactly one of "auto", "yes" and "no". - (void)opt_strings_flags(oldval, p_bkc_values, flags, TRUE); - errmsg = e_invalid_argument; - } + // Must have exactly one of "auto", "yes" and "no". + (void)opt_strings_flags(oldval, p_bkc_values, flags, TRUE); + errmsg = e_invalid_argument; } } - // 'backupext' and 'patchmode' - else if (varp == &p_bex || varp == &p_pm) - { - if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex, - *p_pm == '.' ? p_pm + 1 : p_pm) == 0) - errmsg = e_backupext_and_patchmode_are_equal; - } + return errmsg; +} + +/* + * The 'backupext' or the 'patchmode' option is changed. + */ + static char * +did_set_backupext_or_patchmode(void) +{ + if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex, + *p_pm == '.' ? p_pm + 1 : p_pm) == 0) + return e_backupext_and_patchmode_are_equal; + + return NULL; +} + #ifdef FEAT_LINEBREAK - // 'breakindentopt' - else if (varp == &curwin->w_p_briopt) - { - if (briopt_check(curwin) == FAIL) - errmsg = e_invalid_argument; - // list setting requires a redraw - if (curwin->w_briopt_list) - redraw_all_later(UPD_NOT_VALID); - } +/* + * The 'breakindentopt' option is changed. + */ + static char * +did_set_breakindentopt(void) +{ + char *errmsg = NULL; + + if (briopt_check(curwin) == FAIL) + errmsg = e_invalid_argument; + // list setting requires a redraw + if (curwin->w_briopt_list) + redraw_all_later(UPD_NOT_VALID); + + return errmsg; +} #endif - // 'isident', 'iskeyword', 'isprint or 'isfname' option: refill g_chartab[] - // If the new option is invalid, use old value. 'lisp' option: refill - // g_chartab[] for '-' char - else if ( varp == &p_isi - || varp == &(curbuf->b_p_isk) - || varp == &p_isp - || varp == &p_isf) +/* + * The 'isident' or the 'iskeyword' or the 'isprint' or the 'isfname' option is + * changed. + */ + static char * +did_set_isopt(int *did_chartab) +{ + if (init_chartab() == FAIL) { - if (init_chartab() == FAIL) - { - did_chartab = TRUE; // need to restore it below - errmsg = e_invalid_argument; // error in value - } + *did_chartab = TRUE; // need to restore it below + return e_invalid_argument; // error in value } - // 'helpfile' - else if (varp == &p_hf) - { - // May compute new values for $VIM and $VIMRUNTIME - if (didset_vim) - vim_unsetenv_ext((char_u *)"VIM"); - if (didset_vimruntime) - vim_unsetenv_ext((char_u *)"VIMRUNTIME"); - } + return NULL; +} + +/* + * The 'helpfile' option is changed. + */ + static void +did_set_helpfile(void) +{ + // May compute new values for $VIM and $VIMRUNTIME + if (didset_vim) + vim_unsetenv_ext((char_u *)"VIM"); + if (didset_vimruntime) + vim_unsetenv_ext((char_u *)"VIMRUNTIME"); +} #ifdef FEAT_SYN_HL - // 'cursorlineopt' - else if (varp == &curwin->w_p_culopt - || gvarp == &curwin->w_allbuf_opt.wo_culopt) - { - if (**varp == NUL || fill_culopt_flags(*varp, curwin) != OK) - errmsg = e_invalid_argument; - } +/* + * The 'cursorlineopt' option is changed. + */ + static char * +did_set_cursorlineopt(char_u **varp) +{ + if (**varp == NUL || fill_culopt_flags(*varp, curwin) != OK) + return e_invalid_argument; - // 'colorcolumn' - else if (varp == &curwin->w_p_cc) - errmsg = check_colorcolumn(curwin); + return NULL; +} #endif #ifdef FEAT_MULTI_LANG - // 'helplang' - else if (varp == &p_hlg) +/* + * The 'helplang' option is changed. + */ + static char * +did_set_helplang(void) +{ + char *errmsg = NULL; + + // Check for "", "ab", "ab,cd", etc. + for (char_u *s = p_hlg; *s != NUL; s += 3) { - // Check for "", "ab", "ab,cd", etc. - for (s = p_hlg; *s != NUL; s += 3) + if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL)) { - if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL)) - { - errmsg = e_invalid_argument; - break; - } - if (s[2] == NUL) - break; + errmsg = e_invalid_argument; + break; } + if (s[2] == NUL) + break; } + + return errmsg; +} #endif - // 'highlight' - else if (varp == &p_hl) - { - if (highlight_changed() == FAIL) - errmsg = e_invalid_argument; // invalid flags - } +/* + * The 'highlight' option is changed. + */ + static char * +did_set_highlight(void) +{ + if (highlight_changed() == FAIL) + return e_invalid_argument; // invalid flags - // 'nrformats' - else if (gvarp == &p_nf) - { - if (check_opt_strings(*varp, p_nf_values, TRUE) != OK) - errmsg = e_invalid_argument; - } + return NULL; +} + +/* + * An option that accepts a list of flags is changed. + * e.g. 'viewoptions', 'switchbuf', 'casemap', etc. + */ + static char * +did_set_opt_flags(char_u *val, char **values, unsigned *flagp, int list) +{ + if (opt_strings_flags(val, values, flagp, list) == FAIL) + return e_invalid_argument; + + return NULL; +} + +/* + * An option that accepts a list of string values is changed. + * e.g. 'nrformats', 'scrollopt', 'wildoptions', etc. + */ + static char * +did_set_opt_strings(char_u *val, char **values, int list) +{ + return did_set_opt_flags(val, values, NULL, list); +} #ifdef FEAT_SESSION - // 'sessionoptions' - else if (varp == &p_ssop) - { - if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK) - errmsg = e_invalid_argument; - if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR)) - { - // Don't allow both "sesdir" and "curdir". - (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE); - errmsg = e_invalid_argument; - } - } - // 'viewoptions' - else if (varp == &p_vop) +/* + * The 'sessionoptions' option is changed. + */ + static char * +did_set_sessionoptions(char_u *oldval) +{ + if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK) + return e_invalid_argument; + if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR)) { - if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK) - errmsg = e_invalid_argument; + // Don't allow both "sesdir" and "curdir". + (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE); + return e_invalid_argument; } + + return NULL; +} #endif - // 'scrollopt' - else if (varp == &p_sbo) - { - if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK) - errmsg = e_invalid_argument; - } +/* + * The 'ambiwidth' option is changed. + */ + static char * +did_set_ambiwidth(void) +{ + if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK) + return e_invalid_argument; - // 'ambiwidth' - else if (varp == &p_ambw || varp == &p_emoji) - { - if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK) - errmsg = e_invalid_argument; - else - errmsg = check_chars_options(); - } + return check_chars_options(); +} + +/* + * The 'background' option is changed. + */ + static char * +did_set_background(void) +{ + if (check_opt_strings(p_bg, p_bg_values, FALSE) == FAIL) + return e_invalid_argument; - // 'background' - else if (varp == &p_bg) - { - if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK) - { #ifdef FEAT_EVAL - int dark = (*p_bg == 'd'); + int dark = (*p_bg == 'd'); #endif - init_highlight(FALSE, FALSE); + init_highlight(FALSE, FALSE); #ifdef FEAT_EVAL - if (dark != (*p_bg == 'd') - && get_var_value((char_u *)"g:colors_name") != NULL) - { - // The color scheme must have set 'background' back to another - // value, that's not what we want here. Disable the color - // scheme and set the colors again. - do_unlet((char_u *)"g:colors_name", TRUE); - free_string_option(p_bg); - p_bg = vim_strsave((char_u *)(dark ? "dark" : "light")); - check_string_option(&p_bg); - init_highlight(FALSE, FALSE); - } + if (dark != (*p_bg == 'd') + && get_var_value((char_u *)"g:colors_name") != NULL) + { + // The color scheme must have set 'background' back to another + // value, that's not what we want here. Disable the color + // scheme and set the colors again. + do_unlet((char_u *)"g:colors_name", TRUE); + free_string_option(p_bg); + p_bg = vim_strsave((char_u *)(dark ? "dark" : "light")); + check_string_option(&p_bg); + init_highlight(FALSE, FALSE); + } #endif #ifdef FEAT_TERMINAL - term_update_colors_all(); + term_update_colors_all(); #endif - } - else - errmsg = e_invalid_argument; - } - // 'wildmode' - else if (varp == &p_wim) - { - if (check_opt_wim() == FAIL) - errmsg = e_invalid_argument; - } + return NULL; +} - // 'wildoptions' - else if (varp == &p_wop) - { - if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK) - errmsg = e_invalid_argument; - } +/* + * The 'wildmode' option is changed. + */ + static char * +did_set_wildmode(void) +{ + if (check_opt_wim() == FAIL) + return e_invalid_argument; + return NULL; +} #ifdef FEAT_WAK - // 'winaltkeys' - else if (varp == &p_wak) - { - if (*p_wak == NUL - || check_opt_strings(p_wak, p_wak_values, FALSE) != OK) - errmsg = e_invalid_argument; +/* + * The 'winaltkeys' option is changed. + */ + static char * +did_set_winaltkeys(void) +{ + char *errmsg = NULL; + + if (*p_wak == NUL + || check_opt_strings(p_wak, p_wak_values, FALSE) != OK) + errmsg = e_invalid_argument; # ifdef FEAT_MENU # if defined(FEAT_GUI_MOTIF) - else if (gui.in_use) - gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm'); + else if (gui.in_use) + gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm'); # elif defined(FEAT_GUI_GTK) - else if (gui.in_use) - gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm'); + else if (gui.in_use) + gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm'); # endif # endif - } + return errmsg; +} #endif - // 'eventignore' - else if (varp == &p_ei) +/* + * The 'eventignore' option is changed. + */ + static char * +did_set_eventignore(void) +{ + if (check_ei() == FAIL) + return e_invalid_argument; + return NULL; +} + +/* + * One of the 'encoding', 'fileencoding', 'termencoding' or 'makeencoding' + * options is changed. + */ + static char * +did_set_encoding(char_u **varp, char_u **gvarp, int opt_flags) +{ + char *errmsg = NULL; + char_u *p; + + if (gvarp == &p_fenc) { - if (check_ei() == FAIL) + if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL) + errmsg = e_cannot_make_changes_modifiable_is_off; + else if (vim_strchr(*varp, ',') != NULL) + // No comma allowed in 'fileencoding'; catches confusing it + // with 'fileencodings'. errmsg = e_invalid_argument; + else + { + // May show a "+" in the title now. + redraw_titles(); + // Add 'fileencoding' to the swap file. + ml_setflags(curbuf); + } } - - // 'encoding', 'fileencoding', 'termencoding' and 'makeencoding' - else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc - || gvarp == &p_menc) + if (errmsg == NULL) { - if (gvarp == &p_fenc) + // canonize the value, so that STRCMP() can be used on it + p = enc_canonize(*varp); + if (p != NULL) { - if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL) - errmsg = e_cannot_make_changes_modifiable_is_off; - else if (vim_strchr(*varp, ',') != NULL) - // No comma allowed in 'fileencoding'; catches confusing it - // with 'fileencodings'. - errmsg = e_invalid_argument; - else - { - // May show a "+" in the title now. - redraw_titles(); - // Add 'fileencoding' to the swap file. - ml_setflags(curbuf); - } + vim_free(*varp); + *varp = p; } - if (errmsg == NULL) + if (varp == &p_enc) { - // canonize the value, so that STRCMP() can be used on it - p = enc_canonize(*varp); - if (p != NULL) - { - vim_free(*varp); - *varp = p; - } - if (varp == &p_enc) - { - errmsg = mb_init(); - redraw_titles(); - } + errmsg = mb_init(); + redraw_titles(); } + } #if defined(FEAT_GUI_GTK) - if (errmsg == NULL && varp == &p_tenc && gui.in_use) - { - // GTK uses only a single encoding, and that is UTF-8. - if (STRCMP(p_tenc, "utf-8") != 0) - errmsg = e_cannot_be_changed_in_gtk_GUI; - } + if (errmsg == NULL && varp == &p_tenc && gui.in_use) + { + // GTK uses only a single encoding, and that is UTF-8. + if (STRCMP(p_tenc, "utf-8") != 0) + errmsg = e_cannot_be_changed_in_gtk_GUI; + } #endif - if (errmsg == NULL) - { + if (errmsg == NULL) + { #ifdef FEAT_KEYMAP - // When 'keymap' is used and 'encoding' changes, reload the keymap - // (with another encoding). - if (varp == &p_enc && *curbuf->b_p_keymap != NUL) - (void)keymap_init(); + // When 'keymap' is used and 'encoding' changes, reload the keymap + // (with another encoding). + if (varp == &p_enc && *curbuf->b_p_keymap != NUL) + (void)keymap_init(); #endif - // When 'termencoding' is not empty and 'encoding' changes or when - // 'termencoding' changes, need to setup for keyboard input and - // display output conversion. - if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc)) + // When 'termencoding' is not empty and 'encoding' changes or when + // 'termencoding' changes, need to setup for keyboard input and + // display output conversion. + if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc)) + { + if (convert_setup(&input_conv, p_tenc, p_enc) == FAIL + || convert_setup(&output_conv, p_enc, p_tenc) == FAIL) { - if (convert_setup(&input_conv, p_tenc, p_enc) == FAIL - || convert_setup(&output_conv, p_enc, p_tenc) == FAIL) - { - semsg(_(e_cannot_convert_between_str_and_str), - p_tenc, p_enc); - errmsg = e_invalid_argument; - } + semsg(_(e_cannot_convert_between_str_and_str), + p_tenc, p_enc); + errmsg = e_invalid_argument; } + } #if defined(MSWIN) - // $HOME may have characters in active code page. - if (varp == &p_enc) - init_homedir(); + // $HOME may have characters in active code page. + if (varp == &p_enc) + init_homedir(); #endif - } } + return errmsg; +} + #if defined(FEAT_POSTSCRIPT) - else if (varp == &p_penc) +/* + * The 'printencoding' option is changed. + */ + static void +did_set_printencoding(void) +{ + char_u *s, *p; + + // Canonize printencoding if VIM standard one + p = enc_canonize(p_penc); + if (p != NULL) { - // Canonize printencoding if VIM standard one - p = enc_canonize(p_penc); - if (p != NULL) - { - vim_free(p_penc); - p_penc = p; - } - else + vim_free(p_penc); + p_penc = p; + } + else + { + // Ensure lower case and '-' for '_' + for (s = p_penc; *s != NUL; s++) { - // Ensure lower case and '-' for '_' - for (s = p_penc; *s != NUL; s++) - { - if (*s == '_') - *s = '-'; - else - *s = TOLOWER_ASC(*s); - } + if (*s == '_') + *s = '-'; + else + *s = TOLOWER_ASC(*s); } } +} #endif #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK) - else if (varp == &p_imak) - { - if (!im_xim_isvalid_imactivate()) - errmsg = e_invalid_argument; - } +/* + * The 'imactivatekey' option is changed. + */ + static char * +did_set_imactivatekey(void) +{ + if (!im_xim_isvalid_imactivate()) + return e_invalid_argument; + return NULL; +} #endif #ifdef FEAT_KEYMAP - else if (varp == &curbuf->b_p_keymap) +/* + * The 'keymap' option is changed. + */ + static char * +did_set_keymap(char_u **varp, int opt_flags, int *value_checked) +{ + char *errmsg = NULL; + + if (!valid_filetype(*varp)) + errmsg = e_invalid_argument; + else { - if (!valid_filetype(*varp)) - errmsg = e_invalid_argument; - else - { - int secure_save = secure; + int secure_save = secure; - // Reset the secure flag, since the value of 'keymap' has - // been checked to be safe. - secure = 0; + // Reset the secure flag, since the value of 'keymap' has + // been checked to be safe. + secure = 0; - // load or unload key mapping tables - errmsg = keymap_init(); + // load or unload key mapping tables + errmsg = keymap_init(); - secure = secure_save; + secure = secure_save; - // Since we check the value, there is no need to set P_INSECURE, - // even when the value comes from a modeline. - *value_checked = TRUE; - } + // Since we check the value, there is no need to set P_INSECURE, + // even when the value comes from a modeline. + *value_checked = TRUE; + } - if (errmsg == NULL) + if (errmsg == NULL) + { + if (*curbuf->b_p_keymap != NUL) { - if (*curbuf->b_p_keymap != NUL) - { - // Installed a new keymap, switch on using it. - curbuf->b_p_iminsert = B_IMODE_LMAP; - if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT) - curbuf->b_p_imsearch = B_IMODE_LMAP; - } - else - { - // Cleared the keymap, may reset 'iminsert' and 'imsearch'. - if (curbuf->b_p_iminsert == B_IMODE_LMAP) - curbuf->b_p_iminsert = B_IMODE_NONE; - if (curbuf->b_p_imsearch == B_IMODE_LMAP) - curbuf->b_p_imsearch = B_IMODE_USE_INSERT; - } - if ((opt_flags & OPT_LOCAL) == 0) - { - set_iminsert_global(); - set_imsearch_global(); - } - status_redraw_curbuf(); + // Installed a new keymap, switch on using it. + curbuf->b_p_iminsert = B_IMODE_LMAP; + if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT) + curbuf->b_p_imsearch = B_IMODE_LMAP; + } + else + { + // Cleared the keymap, may reset 'iminsert' and 'imsearch'. + if (curbuf->b_p_iminsert == B_IMODE_LMAP) + curbuf->b_p_iminsert = B_IMODE_NONE; + if (curbuf->b_p_imsearch == B_IMODE_LMAP) + curbuf->b_p_imsearch = B_IMODE_USE_INSERT; } + if ((opt_flags & OPT_LOCAL) == 0) + { + set_iminsert_global(); + set_imsearch_global(); + } + status_redraw_curbuf(); } + + return errmsg; +} #endif - // 'fileformat' - else if (gvarp == &p_ff) +/* + * The 'fileformat' option is changed. + */ + static char * +did_set_fileformat(char_u **varp, char_u *oldval, int opt_flags) +{ + if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL)) + return e_cannot_make_changes_modifiable_is_off; + else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK) + return e_invalid_argument; + + // may also change 'textmode' + if (get_fileformat(curbuf) == EOL_DOS) + curbuf->b_p_tx = TRUE; + else + curbuf->b_p_tx = FALSE; + redraw_titles(); + // update flag in swap file + ml_setflags(curbuf); + // Redraw needed when switching to/from "mac": a CR in the text + // will be displayed differently. + if (get_fileformat(curbuf) == EOL_MAC || *oldval == 'm') + redraw_curbuf_later(UPD_NOT_VALID); + + return NULL; +} + +/* + * The 'fileformats' option is changed. + */ + static char * +did_set_fileformats(void) +{ + if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK) + return e_invalid_argument; + + // also change 'textauto' + if (*p_ffs == NUL) + p_ta = FALSE; + else + p_ta = TRUE; + + return NULL; +} + +#if defined(FEAT_CRYPT) +/* + * The 'cryptkey' option is changed. + */ + static void +did_set_cryptkey(char_u *oldval) +{ + // Make sure the ":set" command doesn't show the new value in the + // history. + remove_key_from_history(); + + if (STRCMP(curbuf->b_p_key, oldval) != 0) + // Need to update the swapfile. { - if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL)) - errmsg = e_cannot_make_changes_modifiable_is_off; - else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK) - errmsg = e_invalid_argument; - else - { - // may also change 'textmode' - if (get_fileformat(curbuf) == EOL_DOS) - curbuf->b_p_tx = TRUE; - else - curbuf->b_p_tx = FALSE; - redraw_titles(); - // update flag in swap file - ml_setflags(curbuf); - // Redraw needed when switching to/from "mac": a CR in the text - // will be displayed differently. - if (get_fileformat(curbuf) == EOL_MAC || *oldval == 'm') - redraw_curbuf_later(UPD_NOT_VALID); - } + ml_set_crypt_key(curbuf, oldval, + *curbuf->b_p_cm == NUL ? p_cm : curbuf->b_p_cm); + changed_internal(); } +} - // 'fileformats' - else if (varp == &p_ffs) +/* + * The 'cryptmethod' option is changed. + */ + static char * +did_set_cryptmethod(char_u *oldval, int opt_flags) +{ + char_u *p; + char_u *s; + + if (opt_flags & OPT_LOCAL) + p = curbuf->b_p_cm; + else + p = p_cm; + if (check_opt_strings(p, p_cm_values, TRUE) != OK) + return e_invalid_argument; + else if (crypt_self_test() == FAIL) + return e_invalid_argument; + + // When setting the global value to empty, make it "zip". + if (*p_cm == NUL) { - if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK) - errmsg = e_invalid_argument; - else - { - // also change 'textauto' - if (*p_ffs == NUL) - p_ta = FALSE; - else - p_ta = TRUE; - } + free_string_option(p_cm); + p_cm = vim_strsave((char_u *)"zip"); + } + // When using ":set cm=name" the local value is going to be empty. + // Do that here, otherwise the crypt functions will still use the + // local value. + if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0) + { + free_string_option(curbuf->b_p_cm); + curbuf->b_p_cm = empty_option; } -#if defined(FEAT_CRYPT) - // 'cryptkey' - else if (gvarp == &p_key) + // Need to update the swapfile when the effective method changed. + // Set "s" to the effective old value, "p" to the effective new + // method and compare. + if ((opt_flags & OPT_LOCAL) && *oldval == NUL) + s = p_cm; // was previously using the global value + else + s = oldval; + if (*curbuf->b_p_cm == NUL) + p = p_cm; // is now using the global value + else + p = curbuf->b_p_cm; + if (STRCMP(s, p) ! |