@@ -7573,24 +7573,30 @@ set_bool_option(opt_idx, varp, value, opt_flags)
75737573 /* 'undofile' */
75747574 else if ((int * )varp == & curbuf -> b_p_udf || (int * )varp == & p_udf )
75757575 {
7576- char_u hash [ UNDO_HASH_SIZE ];
7577- buf_T * save_curbuf = curbuf ;
7578-
7579- for (curbuf = firstbuf ; curbuf != NULL ; curbuf = curbuf -> b_next )
7576+ /* Only take action when the option was set. When reset we do not
7577+ * delete the undo file, the option may be set again without making
7578+ * any changes in between. */
7579+ if (curbuf -> b_p_udf || p_udf )
75807580 {
7581- /* When 'undofile' is set globally: for every buffer, otherwise
7582- * only for the current buffer: Try to read in the undofile, if
7583- * one exists and the buffer wasn't changed and the buffer was
7584- * loaded. */
7585- if ((curbuf == save_curbuf
7586- || (opt_flags & OPT_GLOBAL ) || opt_flags == 0 )
7587- && !curbufIsChanged () && curbuf -> b_ml .ml_mfp != NULL )
7581+ char_u hash [UNDO_HASH_SIZE ];
7582+ buf_T * save_curbuf = curbuf ;
7583+
7584+ for (curbuf = firstbuf ; curbuf != NULL ; curbuf = curbuf -> b_next )
75887585 {
7589- u_compute_hash (hash );
7590- u_read_undo (NULL , hash , curbuf -> b_fname );
7586+ /* When 'undofile' is set globally: for every buffer, otherwise
7587+ * only for the current buffer: Try to read in the undofile,
7588+ * if one exists, the buffer wasn't changed and the buffer was
7589+ * loaded */
7590+ if ((curbuf == save_curbuf
7591+ || (opt_flags & OPT_GLOBAL ) || opt_flags == 0 )
7592+ && !curbufIsChanged () && curbuf -> b_ml .ml_mfp != NULL )
7593+ {
7594+ u_compute_hash (hash );
7595+ u_read_undo (NULL , hash , curbuf -> b_fname );
7596+ }
75917597 }
7598+ curbuf = save_curbuf ;
75927599 }
7593- curbuf = save_curbuf ;
75947600 }
75957601#endif
75967602
0 commit comments