Hi James!
On Di, 16 Okt 2012, James McCoy wrote:
> On Oct 16, 2012 1:14 PM, "Christian Brabandt" <[email protected]> wrote:
> >
> > Hi vim_dev!
> >
> > On Di, 16 Okt 2012, Christian Brabandt wrote:
> >
> > […]
> > BTW: Any comments on whether unsetting the 'undofile' option should
> > delete the undofile?
>
> I've seen requests for that, or at least some easy way to discard the undo
> history. Seems reasonable to me.
Here is an updated patch.
regards,
Christian
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
diff --git a/runtime/doc/options.txt b/runtime/doc/options.txt
--- a/runtime/doc/options.txt
+++ b/runtime/doc/options.txt
@@ -7494,6 +7494,8 @@
For more information about this feature see |undo-persistence|.
The undo file is not read when 'undoreload' causes the buffer from
before a reload to be saved for undo.
+ When 'undofile' is turned off, the undofile for the current buffer is
+ immediately deleted.
WARNING: this is a very new feature. Use at your own risk!
*'undolevels'* *'ul'*
diff --git a/src/option.c b/src/option.c
--- a/src/option.c
+++ b/src/option.c
@@ -7570,27 +7570,39 @@
}
#ifdef FEAT_PERSISTENT_UNDO
- /* 'undofile' */
- else if ((int *)varp == &curbuf->b_p_udf || (int *)varp == &p_udf)
- {
- char_u hash[UNDO_HASH_SIZE];
- buf_T *save_curbuf = curbuf;
-
- for (curbuf = firstbuf; curbuf != NULL; curbuf = curbuf->b_next)
- {
- /* When 'undofile' is set globally: for every buffer, otherwise
- * only for the current buffer: Try to read in the undofile, if
- * one exists and the buffer wasn't changed and the buffer was
- * loaded. */
- if ((curbuf == save_curbuf
- || (opt_flags & OPT_GLOBAL) || opt_flags == 0)
- && !curbufIsChanged() && curbuf->b_ml.ml_mfp != NULL)
- {
- u_compute_hash(hash);
- u_read_undo(NULL, hash, curbuf->b_fname);
- }
- }
- curbuf = save_curbuf;
+ /* 'undofile' was set */
+ else if (((int *)varp == &curbuf->b_p_udf || (int *)varp == &p_udf))
+ {
+ if (curbuf->b_p_udf || p_udf)
+ {
+ char_u hash[UNDO_HASH_SIZE];
+ buf_T *save_curbuf = curbuf;
+
+ for (curbuf = firstbuf; curbuf != NULL; curbuf = curbuf->b_next)
+ {
+ /* When 'undofile' is set globally: for every buffer, otherwise
+ * only for the current buffer: Try to read in the undofile, if
+ * one exists, the buffer wasn't changed and the buffer was
+ * loaded */
+ if ((curbuf == save_curbuf
+ || (opt_flags & OPT_GLOBAL) || opt_flags == 0)
+ && !curbufIsChanged() && curbuf->b_ml.ml_mfp != NULL)
+ {
+ u_compute_hash(hash);
+ u_read_undo(NULL, hash, curbuf->b_fname);
+ }
+ }
+ curbuf = save_curbuf;
+ }
+ /* unsetting 'udf' means delete undofile, if one exists */
+ else if (curbuf->b_ffname != NULL)
+ {
+ /* u_get_undo_file_name already checks for existence of the file */
+ char_u *undo_file = u_get_undo_file_name(curbuf->b_ffname, TRUE);
+
+ mch_remove(undo_file);
+ vim_free(undo_file);
+ }
}
#endif