diff src/optionstr.c @ 32076:32acf287a9ae v9.0.1369

patch 9.0.1369: still some "else if" constructs for setting options Commit: https://github.com/vim/vim/commit/c6ff21e876af0e3ad59664dd0f69359c4b6e9f1d Author: Yegappan Lakshmanan <yegappan@yahoo.com> Date: Thu Mar 2 14:46:48 2023 +0000 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)
author Bram Moolenaar <Bram@vim.org>
date Thu, 02 Mar 2023 16:00:05 +0100
parents ef85a4440947
children 45142117e206
line wrap: on
line diff
--- 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);