@@ -97,6 +97,7 @@ static char *(p_scl_values[]) = {"yes", "no", "auto", "number", NULL};
9797static char * (p_twt_values []) = {"winpty" , "conpty" , "" , NULL };
9898#endif
9999static char * (p_sloc_values []) = {"last" , "statusline" , "tabline" , NULL };
100+ static char * (p_sws_values []) = {"fsync" , "sync" , NULL };
100101
101102static int check_opt_strings (char_u * val , char * * values , int list );
102103static int opt_strings_flags (char_u * val , char * * values , unsigned * flagp , int list );
@@ -761,15 +762,15 @@ did_set_breakindentopt(optset_T *args UNUSED)
761762 * The 'isident' or the 'iskeyword' or the 'isprint' or the 'isfname' option is
762763 * changed.
763764 */
764- static char *
765- did_set_isopt (int * did_chartab )
765+ char *
766+ did_set_isopt (optset_T * args )
766767{
767768 // 'isident', 'iskeyword', 'isprint or 'isfname' option: refill g_chartab[]
768769 // If the new option is invalid, use old value.
769770 // 'lisp' option: refill g_chartab[] for '-' char.
770771 if (init_chartab () == FAIL )
771772 {
772- * did_chartab = TRUE; // need to restore it below
773+ args -> os_restore_chartab = TRUE;// need to restore the chartab.
773774 return e_invalid_argument ; // error in value
774775 }
775776
@@ -928,6 +929,15 @@ did_set_splitkeep(optset_T *args UNUSED)
928929 return did_set_opt_strings (p_spk , p_spk_values , FALSE);
929930}
930931
932+ /*
933+ * The 'swapsync' option is changed.
934+ */
935+ char *
936+ did_set_swapsync (optset_T * args UNUSED )
937+ {
938+ return did_set_opt_strings (p_sws , p_sws_values , FALSE);
939+ }
940+
931941/*
932942 * The 'switchbuf' option is changed.
933943 */
@@ -1224,16 +1234,16 @@ did_set_imactivatekey(optset_T *args UNUSED)
12241234}
12251235#endif
12261236
1227- #ifdef FEAT_KEYMAP
1237+ #if defined( FEAT_KEYMAP ) || defined( PROTO )
12281238/*
12291239 * The 'keymap' option is changed.
12301240 */
1231- static char *
1232- did_set_keymap (char_u * * varp , int opt_flags , int * value_checked )
1241+ char *
1242+ did_set_keymap (optset_T * args )
12331243{
12341244 char * errmsg = NULL ;
12351245
1236- if (!valid_filetype (* varp ))
1246+ if (!valid_filetype (args -> os_varp ))
12371247 errmsg = e_invalid_argument ;
12381248 else
12391249 {
@@ -1250,7 +1260,7 @@ did_set_keymap(char_u **varp, int opt_flags, int *value_checked)
12501260
12511261 // Since we check the value, there is no need to set P_INSECURE,
12521262 // even when the value comes from a modeline.
1253- * value_checked = TRUE;
1263+ args -> os_value_checked = TRUE;
12541264 }
12551265
12561266 if (errmsg == NULL )
@@ -1270,7 +1280,7 @@ did_set_keymap(char_u **varp, int opt_flags, int *value_checked)
12701280 if (curbuf -> b_p_imsearch == B_IMODE_LMAP )
12711281 curbuf -> b_p_imsearch = B_IMODE_USE_INSERT ;
12721282 }
1273- if ((opt_flags & OPT_LOCAL ) == 0 )
1283+ if ((args -> os_flags & OPT_LOCAL ) == 0 )
12741284 {
12751285 set_iminsert_global ();
12761286 set_imsearch_global ();
@@ -2573,7 +2583,8 @@ did_set_cinoptions(optset_T *args UNUSED)
25732583 char *
25742584did_set_lispoptions (optset_T * args )
25752585{
2576- if (* args -> os_varp != NUL && STRCMP (args -> os_varp , "expr:0" ) != 0
2586+ if (* args -> os_varp != NUL
2587+ && STRCMP (args -> os_varp , "expr:0" ) != 0
25772588 && STRCMP (args -> os_varp , "expr:1" ) != 0 )
25782589 return e_invalid_argument ;
25792590
@@ -2594,24 +2605,36 @@ did_set_renderoptions(optset_T *args UNUSED)
25942605}
25952606#endif
25962607
2608+ #if defined(FEAT_RIGHTLEFT ) || defined(PROTO )
2609+ /*
2610+ * The 'rightleftcmd' option is changed.
2611+ */
2612+ char *
2613+ did_set_rightleftcmd (optset_T * args )
2614+ {
2615+ // Currently only "search" is a supported value.
2616+ if (* args -> os_varp != NUL && STRCMP (args -> os_varp , "search" ) != 0 )
2617+ return e_invalid_argument ;
2618+
2619+ return NULL ;
2620+ }
2621+ #endif
2622+
25972623/*
25982624 * The 'filetype' or the 'syntax' option is changed.
25992625 */
2600- static char *
2601- did_set_filetype_or_syntax (
2602- char_u * * varp ,
2603- char_u * oldval ,
2604- int * value_checked ,
2605- int * value_changed )
2626+ char *
2627+ did_set_filetype_or_syntax (optset_T * args )
26062628{
2607- if (!valid_filetype (* varp ))
2629+ if (!valid_filetype (args -> os_varp ))
26082630 return e_invalid_argument ;
26092631
2610- * value_changed = STRCMP (oldval , * varp ) != 0 ;
2632+ args -> os_value_changed =
2633+ STRCMP (args -> os_oldval .string , args -> os_varp ) != 0 ;
26112634
26122635 // Since we check the value, there is no need to set P_INSECURE,
26132636 // even when the value comes from a modeline.
2614- * value_checked = TRUE;
2637+ args -> os_value_checked = TRUE;
26152638
26162639 return NULL ;
26172640}
@@ -3008,7 +3031,7 @@ did_set_string_option(
30083031 // need to set P_INSECURE
30093032{
30103033 char * errmsg = NULL ;
3011- int did_chartab = FALSE;
3034+ int restore_chartab = FALSE;
30123035 char_u * * gvarp ;
30133036 long_u free_oldval = (get_option_flags (opt_idx ) & P_ALLOCED );
30143037 int value_changed = FALSE;
@@ -3037,31 +3060,37 @@ did_set_string_option(
30373060 args .os_flags = opt_flags ;
30383061 args .os_oldval .string = oldval ;
30393062 args .os_newval .string = value ;
3063+ args .os_value_checked = FALSE;
3064+ args .os_value_changed = FALSE;
3065+ args .os_restore_chartab = FALSE;
30403066 args .os_errbuf = errbuf ;
3067+ // Invoke the option specific callback function to validate and apply
3068+ // the new option value.
30413069 errmsg = did_set_cb (& args );
3070+
30423071#ifdef FEAT_EVAL
3043- // When processing the '*expr' options (e.g. diffexpr, foldexpr, etc.),
3044- // the did_set_cb() function may modify '*varp'.
3072+ // The '*expr' option (e.g. diffexpr, foldexpr, etc.), callback
3073+ // functions may modify '*varp'.
30453074 if (errmsg == NULL && is_expr_option (varp , gvarp ))
30463075 * varp = args .os_varp ;
30473076#endif
3077+ // The 'filetype' and 'syntax' option callback functions may change
3078+ // the os_value_changed field.
3079+ value_changed = args .os_value_changed ;
3080+ // The 'keymap', 'filetype' and 'syntax' option callback functions
3081+ // may change the os_value_checked field.
3082+ * value_checked = args .os_value_checked ;
3083+ // The 'isident', 'iskeyword', 'isprint' and 'isfname' options may
3084+ // change the character table. On failure, this needs to be restored.
3085+ restore_chartab = args .os_restore_chartab ;
30483086 }
30493087 else if (varp == & T_NAME ) // 'term'
30503088 errmsg = did_set_term (& opt_idx , & free_oldval );
3051- else if ( varp == & p_isi // 'isident'
3052- || varp == & (curbuf -> b_p_isk ) // 'iskeyword'
3053- || varp == & p_isp // 'isprint'
3054- || varp == & p_isf ) // 'isfname'
3055- errmsg = did_set_isopt (& did_chartab );
30563089 else if ( varp == & p_enc // 'encoding'
30573090 || gvarp == & p_fenc // 'fileencoding'
30583091 || varp == & p_tenc // 'termencoding'
30593092 || gvarp == & p_menc ) // 'makeencoding'
30603093 errmsg = did_set_encoding (varp , gvarp , opt_flags );
3061- #ifdef FEAT_KEYMAP
3062- else if (varp == & curbuf -> b_p_keymap ) // 'keymap'
3063- errmsg = did_set_keymap (varp , opt_flags , value_checked );
3064- #endif
30653094 else if ( varp == & p_lcs // global 'listchars'
30663095 || varp == & p_fcs ) // global 'fillchars'
30673096 errmsg = did_set_global_listfillchars (varp , opt_flags );
@@ -3072,22 +3101,14 @@ did_set_string_option(
30723101 // terminal options
30733102 else if (istermoption_idx (opt_idx ) && full_screen )
30743103 did_set_term_option (varp , & did_swaptcap );
3075- else if (gvarp == & p_ft ) // 'filetype'
3076- errmsg = did_set_filetype_or_syntax (varp , oldval , value_checked ,
3077- & value_changed );
3078- #ifdef FEAT_SYN_HL
3079- else if (gvarp == & p_syn ) // 'syntax'
3080- errmsg = did_set_filetype_or_syntax (varp , oldval , value_checked ,
3081- & value_changed );
3082- #endif
30833104
30843105 // If an error is detected, restore the previous value.
30853106 if (errmsg != NULL )
30863107 {
30873108 free_string_option (* varp );
30883109 * varp = oldval ;
30893110 // When resetting some values, need to act on it.
3090- if (did_chartab )
3111+ if (restore_chartab )
30913112 (void )init_chartab ();
30923113 if (varp == & p_hl )
30933114 (void )highlight_changed ();
0 commit comments