0
0
mirror of https://github.com/vim/vim.git synced 2025-09-24 03:44:06 -04:00

patch 9.0.1369: still some "else if" constructs for setting options

Problem:    Still some "else if" constructs for setting options.
Solution:   Add a few more functions for handling options. (Yegappan
            Lakshmanan, closes #12090)
This commit is contained in:
Yegappan Lakshmanan
2023-03-02 14:46:48 +00:00
committed by Bram Moolenaar
parent 4ed914b18a
commit c6ff21e876
8 changed files with 186 additions and 208 deletions

View File

@@ -890,6 +890,77 @@ did_set_casemap(optset_T *args UNUSED)
return did_set_opt_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
}
/*
* 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.
*/
@@ -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);