@@ -7567,24 +7567,32 @@ did_set_string_option(
75677567 /* When 'syntax' is set, load the syntax of that name */
75687568 if (varp == & (curbuf -> b_p_syn ))
75697569 {
7570- // Only pass TRUE for "force" when the value changed, to avoid
7571- // endless recurrence. */
7572- apply_autocmds (EVENT_SYNTAX , curbuf -> b_p_syn ,
7573- curbuf -> b_fname , value_changed , curbuf );
7570+ static int syn_recursive = 0 ;
7571+
7572+ ++ syn_recursive ;
7573+ // Only pass TRUE for "force" when the value changed or not used
7574+ // recursively, to avoid endless recurrence.
7575+ apply_autocmds (EVENT_SYNTAX , curbuf -> b_p_syn , curbuf -> b_fname ,
7576+ value_changed || syn_recursive == 1 , curbuf );
7577+ -- syn_recursive ;
75747578 }
75757579#endif
75767580 else if (varp == & (curbuf -> b_p_ft ))
75777581 {
75787582 /* 'filetype' is set, trigger the FileType autocommand.
75797583 * Skip this when called from a modeline and the filetype was
7580- * already set to this value.
7581- * Only pass TRUE for "force" when the value changed, to avoid
7582- * endless recurrence. */
7584+ * already set to this value. */
75837585 if (!(opt_flags & OPT_MODELINE ) || value_changed )
75847586 {
7587+ static int ft_recursive = 0 ;
7588+
7589+ ++ ft_recursive ;
75857590 did_filetype = TRUE;
7586- apply_autocmds (EVENT_FILETYPE , curbuf -> b_p_ft ,
7587- curbuf -> b_fname , value_changed , curbuf );
7591+ // Only pass TRUE for "force" when the value changed or not
7592+ // used recursively, to avoid endless recurrence.
7593+ apply_autocmds (EVENT_FILETYPE , curbuf -> b_p_ft , curbuf -> b_fname ,
7594+ value_changed || ft_recursive == 1 , curbuf );
7595+ -- ft_recursive ;
75887596 /* Just in case the old "curbuf" is now invalid. */
75897597 if (varp != & (curbuf -> b_p_ft ))
75907598 varp = NULL ;
0 commit comments