changeset 32027:ef124f222fc2 v9.0.1345

patch 9.0.1345: too many "else if" statements for handling options Commit: https://github.com/vim/vim/commit/8ad862a1f9d6f4128de856ccfabbeb7546d33b98 Author: Yegappan Lakshmanan <yegappan@yahoo.com> Date: Thu Feb 23 15:05:22 2023 +0000 patch 9.0.1345: too many "else if" statements for handling options Problem: Too many "else if" statements for handling options. Solution: Add more functions to handle options. (Yegappan Lakshmanan, closes #12051)
author Bram Moolenaar <Bram@vim.org>
date Thu, 23 Feb 2023 16:15:04 +0100
parents f7f4dd3b2d13
children 36205c3cc1e6
files src/optiondefs.h src/optionstr.c src/proto/optionstr.pro src/testdir/test_options.vim src/version.c
diffstat 5 files changed, 291 insertions(+), 74 deletions(-) [+]
line wrap: on
line diff
--- a/src/optiondefs.h
+++ b/src/optiondefs.h
@@ -479,7 +479,7 @@ static struct vimoption options[] =
 			    (char_u *)NULL, PV_NONE, NULL,
 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
     {"belloff",      "bo",  P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
-			    (char_u *)&p_bo, PV_NONE, NULL,
+			    (char_u *)&p_bo, PV_NONE, did_set_belloff,
 			    {(char_u *)"", (char_u *)0L} SCTX_INIT},
     {"binary",	    "bin",  P_BOOL|P_VI_DEF|P_RSTAT,
 			    (char_u *)&p_bin, PV_BIN, did_set_binary,
@@ -530,7 +530,7 @@ static struct vimoption options[] =
 #endif
 			    SCTX_INIT},
     {"bufhidden",   "bh",   P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
-			    (char_u *)&p_bh, PV_BH, NULL,
+			    (char_u *)&p_bh, PV_BH, did_set_bufhidden,
 			    {(char_u *)"", (char_u *)0L}
 			    SCTX_INIT},
     {"buflisted",   "bl",   P_BOOL|P_VI_DEF|P_NOGLOB,
@@ -542,7 +542,7 @@ static struct vimoption options[] =
 			    {(char_u *)"", (char_u *)0L}
 			    SCTX_INIT},
     {"casemap",	    "cmp",   P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
-			    (char_u *)&p_cmp, PV_NONE, NULL,
+			    (char_u *)&p_cmp, PV_NONE, did_set_casemap,
 			    {(char_u *)"internal,keepascii", (char_u *)0L}
 			    SCTX_INIT},
     {"cdhome",	    "cdh",  P_BOOL|P_VI_DEF|P_VIM|P_SECURE,
@@ -606,7 +606,7 @@ static struct vimoption options[] =
 			    {(char_u *)7L, (char_u *)0L} SCTX_INIT},
     {"colorcolumn", "cc",   P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_RWIN,
 #ifdef FEAT_SYN_HL
-			    (char_u *)VAR_WIN, PV_CC, NULL,
+			    (char_u *)VAR_WIN, PV_CC, did_set_colorcolumn,
 #else
 			    (char_u *)NULL, PV_NONE, NULL,
 #endif
@@ -785,13 +785,14 @@ static struct vimoption options[] =
 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
     {"cursorlineopt", "culopt", P_STRING|P_VI_DEF|P_RWIN|P_ONECOMMA|P_NODUP,
 #ifdef FEAT_SYN_HL
-			    (char_u *)VAR_WIN, PV_CULOPT, NULL,
+			    (char_u *)VAR_WIN, PV_CULOPT,
+			    did_set_cursorlineopt,
 #else
 			    (char_u *)NULL, PV_NONE, NULL,
 #endif
 			    {(char_u *)"both", (char_u *)0L} SCTX_INIT},
     {"debug",	    NULL,   P_STRING|P_VI_DEF,
-			    (char_u *)&p_debug, PV_NONE, NULL,
+			    (char_u *)&p_debug, PV_NONE, did_set_debug,
 			    {(char_u *)"", (char_u *)0L} SCTX_INIT},
     {"define",	    "def",  P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
 #ifdef FEAT_FIND_ID
@@ -850,7 +851,7 @@ static struct vimoption options[] =
 			    (char_u *)&p_dy, PV_NONE, did_set_display,
 			    {(char_u *)"", (char_u *)0L} SCTX_INIT},
     {"eadirection", "ead",  P_STRING|P_VI_DEF,
-			    (char_u *)&p_ead, PV_NONE, NULL,
+			    (char_u *)&p_ead, PV_NONE, did_set_eadirection,
 			    {(char_u *)"both", (char_u *)0L}
 			    SCTX_INIT},
     {"edcompatible","ed",   P_BOOL|P_VI_DEF,
@@ -958,7 +959,7 @@ static struct vimoption options[] =
 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
     {"foldclose",   "fcl",  P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_RWIN,
 #ifdef FEAT_FOLDING
-			    (char_u *)&p_fcl, PV_NONE, NULL,
+			    (char_u *)&p_fcl, PV_NONE, did_set_foldclose,
 			    {(char_u *)"", (char_u *)0L}
 #else
 			    (char_u *)NULL, PV_NONE, NULL,
@@ -1058,7 +1059,7 @@ static struct vimoption options[] =
 			    SCTX_INIT},
     {"foldopen",    "fdo",  P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_CURSWANT,
 #ifdef FEAT_FOLDING
-			    (char_u *)&p_fdo, PV_NONE, NULL,
+			    (char_u *)&p_fdo, PV_NONE, did_set_foldopen,
 		 {(char_u *)"block,hor,mark,percent,quickfix,search,tag,undo",
 						 (char_u *)0L}
 #else
@@ -1772,7 +1773,7 @@ static struct vimoption options[] =
 			    (char_u *)NULL, PV_NONE, NULL,
 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
     {"nrformats",   "nf",   P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
-			    (char_u *)&p_nf, PV_NF, NULL,
+			    (char_u *)&p_nf, PV_NF, did_set_nrformats,
 			    {(char_u *)"bin,octal,hex", (char_u *)0L}
 			    SCTX_INIT},
     {"number",	    "nu",   P_BOOL|P_VI_DEF|P_RWIN,
@@ -2144,7 +2145,7 @@ static struct vimoption options[] =
 			    (char_u *)&p_so, PV_SO, NULL,
 			    {(char_u *)0L, (char_u *)0L} SCTX_INIT},
     {"scrollopt",   "sbo",  P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
-			    (char_u *)&p_sbo, PV_NONE, NULL,
+			    (char_u *)&p_sbo, PV_NONE, did_set_scrollopt,
 			    {(char_u *)"ver,jump", (char_u *)0L}
 			    SCTX_INIT},
     {"sections",    "sect", P_STRING|P_VI_DEF,
@@ -2159,7 +2160,7 @@ static struct vimoption options[] =
 			    {(char_u *)"inclusive", (char_u *)0L}
 			    SCTX_INIT},
     {"selectmode",  "slm",  P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
-			    (char_u *)&p_slm, PV_NONE, NULL,
+			    (char_u *)&p_slm, PV_NONE, did_set_selectmode,
 			    {(char_u *)"", (char_u *)0L} SCTX_INIT},
     {"sessionoptions", "ssop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
 #ifdef FEAT_SESSION
@@ -2281,7 +2282,7 @@ static struct vimoption options[] =
 #endif
 				} SCTX_INIT},
     {"showcmdloc",  "sloc", P_STRING|P_RSTAT,
-			    (char_u *)&p_sloc, PV_NONE, NULL,
+			    (char_u *)&p_sloc, PV_NONE, did_set_showcmdloc,
 			    {(char_u *)"last", (char_u *)"last"} SCTX_INIT},
     {"showfulltag", "sft",  P_BOOL|P_VI_DEF,
 			    (char_u *)&p_sft, PV_NONE, NULL,
@@ -2390,7 +2391,7 @@ static struct vimoption options[] =
 			    (char_u *)&p_sb, PV_NONE, NULL,
 			    {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
     {"splitkeep",   "spk",  P_STRING,
-			    (char_u *)&p_spk, PV_NONE, NULL,
+			    (char_u *)&p_spk, PV_NONE, did_set_splitkeep,
 			    {(char_u *)"cursor", (char_u *)"cursor"} SCTX_INIT},
     {"splitright",  "spr",  P_BOOL|P_VI_DEF,
 			    (char_u *)&p_spr, PV_NONE, NULL,
@@ -2420,7 +2421,7 @@ static struct vimoption options[] =
 			    (char_u *)&p_sws, PV_NONE, NULL,
 			    {(char_u *)"fsync", (char_u *)0L} SCTX_INIT},
     {"switchbuf",   "swb",  P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
-			    (char_u *)&p_swb, PV_NONE, NULL,
+			    (char_u *)&p_swb, PV_NONE, did_set_switchbuf,
 			    {(char_u *)"", (char_u *)0L} SCTX_INIT},
     {"synmaxcol",   "smc",  P_NUM|P_VI_DEF|P_RBUF,
 #ifdef FEAT_SYN_HL
@@ -2553,7 +2554,7 @@ static struct vimoption options[] =
 			    SCTX_INIT},
     {"termwintype", "twt",  P_STRING|P_ALLOCED|P_VI_DEF,
 #if defined(MSWIN) && defined(FEAT_TERMINAL)
-			    (char_u *)&p_twt, PV_NONE, NULL,
+			    (char_u *)&p_twt, PV_NONE, did_set_termwintype,
 			    {(char_u *)"", (char_u *)NULL}
 #else
 			    (char_u *)NULL, PV_NONE, NULL,
@@ -2731,7 +2732,7 @@ static struct vimoption options[] =
 			    SCTX_INIT},
     {"viewoptions", "vop",  P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
 #ifdef FEAT_SESSION
-			    (char_u *)&p_vop, PV_NONE, NULL,
+			    (char_u *)&p_vop, PV_NONE, did_set_viewoptions,
 			    {(char_u *)"folds,options,cursor,curdir",
 								  (char_u *)0L}
 #else
@@ -2811,7 +2812,7 @@ static struct vimoption options[] =
 			    (char_u *)&p_wim, PV_NONE, did_set_wildmode,
 			    {(char_u *)"full", (char_u *)0L} SCTX_INIT},
     {"wildoptions", "wop",  P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
-			    (char_u *)&p_wop, PV_NONE, NULL,
+			    (char_u *)&p_wop, PV_NONE, did_set_wildoptions,
 			    {(char_u *)"", (char_u *)0L}
 			    SCTX_INIT},
     {"winaltkeys",  "wak",  P_STRING|P_VI_DEF,
@@ -2824,7 +2825,7 @@ static struct vimoption options[] =
 #endif
 			    SCTX_INIT},
     {"wincolor", "wcr",	    P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
-			    (char_u *)VAR_WIN, PV_WCR, NULL,
+			    (char_u *)VAR_WIN, PV_WCR, did_set_wincolor,
 			    {(char_u *)"", (char_u *)NULL}
 			    SCTX_INIT},
     {"window",	    "wi",   P_NUM|P_VI_DEF,
--- a/src/optionstr.c
+++ b/src/optionstr.c
@@ -792,12 +792,22 @@ did_set_helpfile(optset_T *args UNUSED)
 
 #ifdef FEAT_SYN_HL
 /*
+ * The 'colorcolumn' option is changed.
+ */
+    char *
+did_set_colorcolumn(optset_T *args UNUSED)
+{
+    return check_colorcolumn(curwin);
+}
+
+/*
  * The 'cursorlineopt' option is changed.
  */
-    static char *
-did_set_cursorlineopt(char_u **varp)
+    char *
+did_set_cursorlineopt(optset_T *args)
 {
-    if (**varp == NUL || fill_culopt_flags(*varp, curwin) != OK)
+    if (*args->os_varp == NUL
+	    || fill_culopt_flags(args->os_varp, curwin) != OK)
 	return e_invalid_argument;
 
     return NULL;
@@ -864,7 +874,70 @@ did_set_opt_strings(char_u *val, char **
     return did_set_opt_flags(val, values, NULL, list);
 }
 
-#ifdef FEAT_SESSION
+/*
+ * The 'belloff' option is changed.
+ */
+    char *
+did_set_belloff(optset_T *args UNUSED)
+{
+    return did_set_opt_flags(p_bo, p_bo_values, &bo_flags, TRUE);
+}
+
+/*
+ * The 'casemap' option is changed.
+ */
+    char *
+did_set_casemap(optset_T *args UNUSED)
+{
+    return did_set_opt_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
+}
+
+/*
+ * The 'scrollopt' option is changed.
+ */
+    char *
+did_set_scrollopt(optset_T *args UNUSED)
+{
+    return did_set_opt_strings(p_sbo, p_scbopt_values, TRUE);
+}
+
+/*
+ * The 'selectmode' option is changed.
+ */
+    char *
+did_set_selectmode(optset_T *args UNUSED)
+{
+    return did_set_opt_strings(p_slm, p_slm_values, TRUE);
+}
+
+/*
+ * The 'showcmdloc' option is changed.
+ */
+    char *
+did_set_showcmdloc(optset_T *args UNUSED)
+{
+    return did_set_opt_strings(p_sloc, p_sloc_values, FALSE);
+}
+
+/*
+ * The 'splitkeep' option is changed.
+ */
+    char *
+did_set_splitkeep(optset_T *args UNUSED)
+{
+    return did_set_opt_strings(p_spk, p_spk_values, FALSE);
+}
+
+/*
+ * The 'switchbuf' option is changed.
+ */
+    char *
+did_set_switchbuf(optset_T *args UNUSED)
+{
+    return did_set_opt_flags(p_swb, p_swb_values, &swb_flags, TRUE);
+}
+
+#if defined(FEAT_SESSION) || defined(PROTO)
 /*
  * The 'sessionoptions' option is changed.
  */
@@ -883,6 +956,15 @@ did_set_sessionoptions(optset_T *args)
 
     return NULL;
 }
+
+/*
+ * The 'viewoptions' option is changed.
+ */
+    char *
+did_set_viewoptions(optset_T *args UNUSED)
+{
+    return did_set_opt_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
+}
 #endif
 
 /*
@@ -944,6 +1026,15 @@ did_set_wildmode(optset_T *args UNUSED)
     return NULL;
 }
 
+/*
+ * The 'wildoptions' option is changed.
+ */
+    char *
+did_set_wildoptions(optset_T *args UNUSED)
+{
+    return did_set_opt_strings(p_wop, p_wop_values, TRUE);
+}
+
 #if defined(FEAT_WAK) || defined(PROTO)
 /*
  * The 'winaltkeys' option is changed.
@@ -970,6 +1061,27 @@ did_set_winaltkeys(optset_T *args UNUSED
 #endif
 
 /*
+ * The 'wincolor' option is changed.
+ */
+    char *
+did_set_wincolor(optset_T *args UNUSED)
+{
+#ifdef FEAT_TERMINAL
+    term_update_wincolor(curwin);
+#endif
+    return NULL;
+}
+
+/*
+ * The 'eadirection' option is changed.
+ */
+    char *
+did_set_eadirection(optset_T *args UNUSED)
+{
+    return did_set_opt_strings(p_ead, p_ead_values, FALSE);
+}
+
+/*
  * The 'eventignore' option is changed.
  */
     char *
@@ -1857,6 +1969,15 @@ did_set_mousemodel(optset_T *args UNUSED
 }
 
 /*
+ * The 'debug' option is changed.
+ */
+    char *
+did_set_debug(optset_T *args UNUSED)
+{
+    return did_set_opt_strings(p_debug, p_debug_values, TRUE);
+}
+
+/*
  * The 'display' option is changed.
  */
     char *
@@ -1946,6 +2067,15 @@ did_set_mkspellmem(optset_T *args UNUSED
 #endif
 
 /*
+ * The 'nrformats' option is changed.
+ */
+    char *
+did_set_nrformats(optset_T *args)
+{
+    return did_set_opt_strings(args->os_varp, p_nf_values, TRUE);
+}
+
+/*
  * The 'buftype' option is changed.
  */
     char *
@@ -2198,6 +2328,15 @@ did_set_backspace(optset_T *args UNUSED)
 }
 
 /*
+ * The 'bufhidden' option is changed.
+ */
+    char *
+did_set_bufhidden(optset_T *args UNUSED)
+{
+    return did_set_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE);
+}
+
+/*
  * The 'tagcase' option is changed.
  */
     char *
@@ -2299,6 +2438,24 @@ did_set_foldignore(optset_T *args UNUSED
 	foldUpdateAll(curwin);
     return NULL;
 }
+
+/*
+ * The 'foldclose' option is changed.
+ */
+    char *
+did_set_foldclose(optset_T *args UNUSED)
+{
+    return did_set_opt_strings(p_fcl, p_fcl_values, TRUE);
+}
+
+/*
+ * The 'foldopen' option is changed.
+ */
+    char *
+did_set_foldopen(optset_T *args UNUSED)
+{
+    return did_set_opt_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
+}
 #endif
 
 /*
@@ -2459,6 +2616,17 @@ did_set_termwinsize(optset_T *args UNUSE
 
     return NULL;
 }
+
+# if defined(MSWIN) || defined(PROTO)
+/*
+ * The 'termwintype' option is changed.
+ */
+    char *
+did_set_termwintype(optset_T *args UNUSED)
+{
+    return did_set_opt_strings(p_twt, p_twt_values, FALSE);
+}
+# endif
 #endif
 
 #if defined(FEAT_VARTABS) || defined(PROTO)
@@ -2753,23 +2921,6 @@ did_set_string_option(
 	    || varp == &p_isp			// 'isprint'
 	    || varp == &p_isf)			// 'isfname'
 	errmsg = did_set_isopt(&did_chartab);
-#ifdef FEAT_SYN_HL
-    else if (  varp == &curwin->w_p_culopt	// 'cursorlineopt'
-	    || gvarp == &curwin->w_allbuf_opt.wo_culopt)
-	errmsg = did_set_cursorlineopt(varp);
-    else if (varp == &curwin->w_p_cc)		// 'colorcolumn'
-	errmsg = check_colorcolumn(curwin);
-#endif
-    else if (gvarp == &p_nf)			// 'nrformats'
-	errmsg = did_set_opt_strings(*varp, p_nf_values, TRUE);
-#ifdef FEAT_SESSION
-    else if (varp == &p_vop)			// 'viewoptions'
-	errmsg = did_set_opt_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
-#endif
-    else if (varp == &p_sbo)			// 'scrollopt'
-	errmsg = did_set_opt_strings(p_sbo, p_scbopt_values, TRUE);
-    else if (varp == &p_wop)			// 'wildoptions'
-	errmsg = did_set_opt_strings(p_wop, p_wop_values, TRUE);
     else if (  varp == &p_enc			// 'encoding'
 	    || gvarp == &p_fenc			// 'fileencoding'
 	    || varp == &p_tenc			// 'termencoding'
@@ -2799,33 +2950,8 @@ did_set_string_option(
     else if (varp == &p_guicursor)		// 'guicursor'
 	errmsg = parse_shape_opt(SHAPE_CURSOR);
 #endif
-    else if (varp == &p_slm)			// 'selectmode'
-	errmsg = did_set_opt_strings(p_slm, p_slm_values, TRUE);
-    else if (varp == &p_swb)			// 'switchbuf'
-	errmsg = did_set_opt_flags(p_swb, p_swb_values, &swb_flags, TRUE);
-    else if (varp == &p_spk)			// 'splitkeep'
-	errmsg = did_set_opt_strings(p_spk, p_spk_values, FALSE);
-    else if (varp == &p_debug)			// 'debug'
-	errmsg = did_set_opt_strings(p_debug, p_debug_values, TRUE);
-    else if (varp == &p_ead)			// 'eadirection'
-	errmsg = did_set_opt_strings(p_ead, p_ead_values, FALSE);
-    else if (gvarp == &p_bh)			// 'bufhidden'
-	errmsg = did_set_opt_strings(curbuf->b_p_bh, p_bufhidden_values,
-								FALSE);
     else if (gvarp == &p_cpt)			// 'complete'
 	errmsg = did_set_complete(varp, errbuf);
-    else if (varp == &p_sloc)			// 'showcmdloc'
-	errmsg = did_set_opt_strings(p_sloc, p_sloc_values, FALSE);
-    else if (varp == &p_bo)			// 'belloff'
-	errmsg = did_set_opt_flags(p_bo, p_bo_values, &bo_flags, TRUE);
-    else if (varp == &p_cmp)			// 'casemap'
-	errmsg = did_set_opt_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
-#ifdef FEAT_FOLDING
-    else if (varp == &p_fdo)			// 'foldopen'
-	errmsg = did_set_opt_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
-    else if (varp == &p_fcl)			// 'foldclose'
-	errmsg = did_set_opt_strings(p_fcl, p_fcl_values, TRUE);
-#endif
     else if (gvarp == &p_ft)			// 'filetype'
 	errmsg = did_set_filetype_or_syntax(varp, oldval, value_checked,
 							&value_changed);
@@ -2834,14 +2960,6 @@ did_set_string_option(
 	errmsg = did_set_filetype_or_syntax(varp, oldval, value_checked,
 							&value_changed);
 #endif
-#ifdef FEAT_TERMINAL
-    else if (varp == &curwin->w_p_wcr)		// 'wincolor'
-	term_update_wincolor(curwin);
-# if defined(MSWIN)
-    else if (varp == &p_twt)			// 'termwintype'
-	errmsg = did_set_opt_strings(p_twt, p_twt_values, FALSE);
-# endif
-#endif
 #ifdef FEAT_EVAL
     else if (
 # ifdef FEAT_BEVAL
--- a/src/proto/optionstr.pro
+++ b/src/proto/optionstr.pro
@@ -13,13 +13,26 @@ char *did_set_backupcopy(optset_T *args)
 char *did_set_backupext_or_patchmode(optset_T *args);
 char *did_set_breakindentopt(optset_T *args);
 char *did_set_helpfile(optset_T *args);
+char *did_set_colorcolumn(optset_T *args);
+char *did_set_cursorlineopt(optset_T *args);
 char *did_set_helplang(optset_T *args);
 char *did_set_highlight(optset_T *args);
+char *did_set_belloff(optset_T *args);
+char *did_set_casemap(optset_T *args);
+char *did_set_scrollopt(optset_T *args);
+char *did_set_selectmode(optset_T *args);
+char *did_set_showcmdloc(optset_T *args);
+char *did_set_splitkeep(optset_T *args);
+char *did_set_switchbuf(optset_T *args);
 char *did_set_sessionoptions(optset_T *args);
+char *did_set_viewoptions(optset_T *args);
 char *did_set_ambiwidth(optset_T *args);
 char *did_set_background(optset_T *args);
 char *did_set_wildmode(optset_T *args);
+char *did_set_wildoptions(optset_T *args);
 char *did_set_winaltkeys(optset_T *args);
+char *did_set_wincolor(optset_T *args);
+char *did_set_eadirection(optset_T *args);
 char *did_set_eventignore(optset_T *args);
 char *did_set_printencoding(optset_T *args);
 char *did_set_imactivatekey(optset_T *args);
@@ -45,6 +58,7 @@ char *did_set_browsedir(optset_T *args);
 char *did_set_keymodel(optset_T *args);
 char *did_set_keyprotocol(optset_T *args);
 char *did_set_mousemodel(optset_T *args);
+char *did_set_debug(optset_T *args);
 char *did_set_display(optset_T *args);
 char *did_set_spellfile(optset_T *args);
 char *did_set_spelllang(optset_T *args);
@@ -52,6 +66,7 @@ char *did_set_spellcapcheck(optset_T *ar
 char *did_set_spelloptions(optset_T *args);
 char *did_set_spellsuggest(optset_T *args);
 char *did_set_mkspellmem(optset_T *args);
+char *did_set_nrformats(optset_T *args);
 char *did_set_buftype(optset_T *args);
 char *did_set_statusline(optset_T *args);
 char *did_set_tabline(optset_T *args);
@@ -63,12 +78,15 @@ char *did_set_toolbar(optset_T *args);
 char *did_set_toolbariconsize(optset_T *args);
 char *did_set_pastetoggle(optset_T *args);
 char *did_set_backspace(optset_T *args);
+char *did_set_bufhidden(optset_T *args);
 char *did_set_tagcase(optset_T *args);
 char *did_set_diffopt(optset_T *args);
 char *did_set_foldmethod(optset_T *args);
 char *did_set_foldmarker(optset_T *args);
 char *did_set_commentstring(optset_T *args);
 char *did_set_foldignore(optset_T *args);
+char *did_set_foldclose(optset_T *args);
+char *did_set_foldopen(optset_T *args);
 char *did_set_virtualedit(optset_T *args);
 char *did_set_cscopequickfix(optset_T *args);
 char *did_set_cinoptions(optset_T *args);
@@ -76,6 +94,7 @@ char *did_set_lispoptions(optset_T *args
 char *did_set_renderoptions(optset_T *args);
 char *did_set_termwinkey(optset_T *args);
 char *did_set_termwinsize(optset_T *args);
+char *did_set_termwintype(optset_T *args);
 char *did_set_varsofttabstop(optset_T *args);
 char *did_set_vartabstop(optset_T *args);
 char *did_set_previewpopup(optset_T *args);
--- a/src/testdir/test_options.vim
+++ b/src/testdir/test_options.vim
@@ -437,7 +437,16 @@ func Test_set_errors()
   if has('mouseshape')
     call assert_fails('se mouseshape=i-r:x', 'E547:')
   endif
-  call assert_fails('set backupext=~ patchmode=~', 'E589:')
+
+  " Test for 'backupext' and 'patchmode' set to the same value
+  set backupext=.bak
+  set patchmode=.patch
+  call assert_fails('set patchmode=.bak', 'E589:')
+  call assert_equal('.patch', &patchmode)
+  call assert_fails('set backupext=.patch', 'E589:')
+  call assert_equal('.bak', &backupext)
+  set backupext& patchmode&
+
   call assert_fails('set winminheight=10 winheight=9', 'E591:')
   set winminheight& winheight&
   set winheight=10 winminheight=10
@@ -1506,4 +1515,72 @@ func Test_set_min_lines_columns()
   let &columns = save_columns
 endfunc
 
+" Test for reverting a string option value if the new value is invalid.
+func Test_string_option_revert_on_failure()
+  new
+  let optlist = [
+        \ ['ambiwidth', 'double', 'a123'],
+        \ ['background', 'dark', 'a123'],
+        \ ['backspace', 'eol', 'a123'],
+        \ ['backupcopy', 'no', 'a123'],
+        \ ['belloff', 'showmatch', 'a123'],
+        \ ['breakindentopt', 'min:10', 'list'],
+        \ ['bufhidden', 'wipe', 'a123'],
+        \ ['buftype', 'nowrite', 'a123'],
+        \ ['casemap', 'keepascii', 'a123'],
+        \ ['cedit', "\<C-Y>", 'z'],
+        \ ['colorcolumn', '10', 'z'],
+        \ ['commentstring', '#%s', 'a123'],
+        \ ['complete', '.,t', 'a'],
+        \ ['completefunc', 'MyCmplFunc', '1a-'],
+        \ ['completeopt', 'popup', 'a123'],
+        \ ['completepopup', 'width:20', 'border'],
+        \ ['concealcursor', 'v', 'xyz'],
+        \ ['cpoptions', 'HJ', '~'],
+        \ ['cryptmethod', 'zip', 'a123'],
+        \ ['cursorlineopt', 'screenline', 'a123'],
+        \ ['debug', 'throw', 'a123'],
+        \ ['diffopt', 'iwhite', 'a123'],
+        \ ['display', 'uhex', 'a123'],
+        \ ['eadirection', 'hor', 'a123'],
+        \ ['encoding', 'utf-8', 'a123'],
+        \ ['eventignore', 'TextYankPost', 'a123'],
+        \ ['fileencoding', 'utf-8', 'a123,'],
+        \ ['fileformat', 'mac', 'a123'],
+        \ ['fileformats', 'mac', 'a123'],
+        \ ['fillchars', 'diff:~', 'a123'],
+        \ ['foldclose', 'all', 'a123'],
+        \ ['foldmarker', '[[[,]]]', '[[['],
+        \ ['foldmethod', 'marker', 'a123'],
+        \ ['foldopen', 'percent', 'a123'],
+        \ ['formatoptions', 'an', '*'],
+        \ ['guicursor', 'n-v-c:block-Cursor/lCursor', 'n-v-c'],
+        \ ['helplang', 'en', 'a'],
+        \ ['highlight', '!:CursorColumn', '8:']
+        \ ]
+  if has('gui')
+    call add(optlist, ['browsedir', 'buffer', 'a123'])
+  endif
+  if has('clipboard_working')
+    call add(optlist, ['clipboard', 'unnamed', 'a123'])
+  endif
+  if has('win32')
+    call add(optlist, ['completeslash', 'slash', 'a123'])
+  endif
+  if has('cscope')
+    call add(optlist, ['cscopequickfix', 't-', 'z-'])
+  endif
+  if !has('win32')
+    call add(optlist, ['imactivatefunc', 'MyCmplFunc', '1a-'])
+  endif
+  for opt in optlist
+    exe $"let save_opt = &{opt[0]}"
+    exe $"let &{opt[0]} = '{opt[1]}'"
+    call assert_fails($"let &{opt[0]} = '{opt[2]}'", '', opt[0])
+    call assert_equal(opt[1], eval($"&{opt[0]}"), opt[0])
+    exe $"let &{opt[0]} = save_opt"
+  endfor
+  bw!
+endfunc
+
 " vim: shiftwidth=2 sts=2 expandtab
--- a/src/version.c
+++ b/src/version.c
@@ -696,6 +696,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    1345,
+/**/
     1344,
 /**/
     1343,