diff options
author | Yegappan Lakshmanan <yegappan@yahoo.com> | 2023-03-02 14:46:48 +0000 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2023-03-02 14:46:48 +0000 |
commit | c6ff21e876af0e3ad59664dd0f69359c4b6e9f1d (patch) | |
tree | ef51d81e472c4addb48ec3e3ccc6a42a659e5be9 /src/optionstr.c | |
parent | 4ed914b18a47192f79f342bea5e8f59e120d5260 (diff) |
patch 9.0.1369: still some "else if" constructs for setting optionsv9.0.1369
Problem: Still some "else if" constructs for setting options.
Solution: Add a few more functions for handling options. (Yegappan
Lakshmanan, closes #12090)
Diffstat (limited to 'src/optionstr.c')
-rw-r--r-- | src/optionstr.c | 118 |
1 files changed, 71 insertions, 47 deletions
diff --git a/src/optionstr.c b/src/optionstr.c index a9b1c4c575..eca621e432 100644 --- a/src/optionstr.c +++ b/src/optionstr.c @@ -891,6 +891,77 @@ did_set_casemap(optset_T *args UNUSED) } /* + * The global 'listchars' or 'fillchars' option is changed. + */ + static char * +did_set_global_listfillchars(char_u *val, int opt_lcs, int opt_flags) +{ + char *errmsg = NULL; + char_u **local_ptr = opt_lcs ? &curwin->w_p_lcs : &curwin->w_p_fcs; + + // only apply the global value to "curwin" when it does not have a + // local value + if (opt_lcs) + errmsg = set_listchars_option(curwin, val, + **local_ptr == NUL || !(opt_flags & OPT_GLOBAL)); + else + errmsg = set_fillchars_option(curwin, val, + **local_ptr == NUL || !(opt_flags & OPT_GLOBAL)); + if (errmsg != NULL) + return errmsg; + + tabpage_T *tp; + win_T *wp; + + // If the current window is set to use the global + // 'listchars'/'fillchars' value, clear the window-local value. + if (!(opt_flags & OPT_GLOBAL)) + clear_string_option(local_ptr); + FOR_ALL_TAB_WINDOWS(tp, wp) + { + // If the current window has a local value need to apply it + // again, it was changed when setting the global value. + // If no error was returned above, we don't expect an error + // here, so ignore the return value. + if (opt_lcs) + { + if (*wp->w_p_lcs == NUL) + (void)set_listchars_option(wp, wp->w_p_lcs, TRUE); + } + else + { + if (*wp->w_p_fcs == NUL) + (void)set_fillchars_option(wp, wp->w_p_fcs, TRUE); + } + } + + redraw_all_later(UPD_NOT_VALID); + + return NULL; +} + +/* + * The 'fillchars' option or the 'listchars' option is changed. + */ + char * +did_set_chars_option(optset_T *args) +{ + char *errmsg = NULL; + + if ( args->os_varp == p_lcs // global 'listchars' + || args->os_varp == p_fcs) // global 'fillchars' + errmsg = did_set_global_listfillchars(args->os_varp, + args->os_varp == p_lcs, + args->os_flags); + else if (args->os_varp == curwin->w_p_lcs) // local 'listchars' + errmsg = set_listchars_option(curwin, args->os_varp, TRUE); + else if (args->os_varp == curwin->w_p_fcs) // local 'fillchars' + errmsg = set_fillchars_option(curwin, args->os_varp, TRUE); + + return errmsg; +} + +/* * The 'cinoptions' option is changed. */ char * @@ -1504,46 +1575,6 @@ did_set_formatoptions(optset_T *args) args->os_errbuf); } -/* - * The global 'listchars' or 'fillchars' option is changed. - */ - static char * -did_set_global_listfillchars(char_u **varp, int opt_flags) -{ - char *errmsg = NULL; - char_u **local_ptr = varp == &p_lcs - ? &curwin->w_p_lcs : &curwin->w_p_fcs; - - // only apply the global value to "curwin" when it does not have a - // local value - errmsg = set_chars_option(curwin, varp, - **local_ptr == NUL || !(opt_flags & OPT_GLOBAL)); - if (errmsg != NULL) - return errmsg; - - tabpage_T *tp; - win_T *wp; - - // If the current window is set to use the global - // 'listchars'/'fillchars' value, clear the window-local value. - if (!(opt_flags & OPT_GLOBAL)) - clear_string_option(local_ptr); - FOR_ALL_TAB_WINDOWS(tp, wp) - { - // If the current window has a local value need to apply it - // again, it was changed when setting the global value. - // If no error was returned above, we don't expect an error - // here, so ignore the return value. - local_ptr = varp == &p_lcs ? &wp->w_p_lcs : &wp->w_p_fcs; - if (**local_ptr == NUL) - (void)set_chars_option(wp, local_ptr, TRUE); - } - - redraw_all_later(UPD_NOT_VALID); - - return NULL; -} - #if defined(CURSOR_SHAPE) || defined(PROTO) /* * The 'guicursor' option is changed. @@ -3106,13 +3137,6 @@ did_set_string_option( || varp == &p_tenc // 'termencoding' || gvarp == &p_menc) // 'makeencoding' errmsg = did_set_encoding(varp, gvarp, opt_flags); - else if ( varp == &p_lcs // global 'listchars' - || varp == &p_fcs) // global 'fillchars' - errmsg = did_set_global_listfillchars(varp, opt_flags); - else if (varp == &curwin->w_p_lcs) // local 'listchars' - errmsg = set_chars_option(curwin, varp, TRUE); - else if (varp == &curwin->w_p_fcs) // local 'fillchars' - errmsg = set_chars_option(curwin, varp, TRUE); // terminal options else if (istermoption_idx(opt_idx) && full_screen) did_set_term_option(varp, &did_swaptcap); |