From 4be941e3d033e95db26ce46c14e44bdcf193e638 Mon Sep 17 00:00:00 2001 From: "Richard M. Stallman" Date: Thu, 16 Jul 2009 01:45:08 +0000 Subject: [PATCH] * fileio.c (Fwrite_region, Fdo_auto_save): Handle save_length = -2. (Fset_buffer_auto_saved): Handle save_length = -2. Comment changes in other files. --- src/ChangeLog | 5 +++++ src/buffer.c | 7 ++++++- src/buffer.h | 3 +++ src/fileio.c | 20 +++++++++++++------- 4 files changed, 27 insertions(+), 8 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 999269f60a8..698ab0d58dd 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,8 @@ +2009-07-16 Richard Stallman + + * fileio.c (Fwrite_region, Fdo_auto_save): Handle save_length = -2. + (Fset_buffer_auto_saved): Handle save_length = -2. + 2009-07-16 Chong Yidong * xterm.c (Qx_gtk_map_stock): New var. diff --git a/src/buffer.c b/src/buffer.c index f06a6c06a92..f811f162ef2 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -5853,7 +5853,12 @@ Backing up is done before the first time the file is saved. */); DEFVAR_PER_BUFFER ("buffer-saved-size", ¤t_buffer->save_length, make_number (Lisp_Int), doc: /* Length of current buffer when last read in, saved or auto-saved. -0 initially. */); +0 initially. +-1 means auto-saving turned off until next real save. + +If you set this to -2, that means don't turn off auto-saving in this buffer +if its text size shrinks. If you use `buffer-swap-text' on a buffer, +you probably should set this to -2 in that buffer. */); DEFVAR_PER_BUFFER ("selective-display", ¤t_buffer->selective_display, Qnil, diff --git a/src/buffer.h b/src/buffer.h index 1fb322e3ed9..397b97579e6 100644 --- a/src/buffer.h +++ b/src/buffer.h @@ -584,6 +584,9 @@ struct buffer /* This isn't really used by the C code, so could be deleted. */ Lisp_Object backed_up; /* Length of file when last read or saved. + -1 means auto saving turned off because buffer shrank a lot. + -2 means don't turn off auto saving if buffer shrinks. + (That value is used with buffer-swap-text.) This is not in the struct buffer_text because it's not used in indirect buffers at all. */ Lisp_Object save_length; diff --git a/src/fileio.c b/src/fileio.c index bf96b3aa2b1..43872d59472 100644 --- a/src/fileio.c +++ b/src/fileio.c @@ -4492,7 +4492,8 @@ This calls `write-region-annotate-functions' at the start, and if (visiting) { SAVE_MODIFF = MODIFF; - XSETFASTINT (current_buffer->save_length, Z - BEG); + if (XINT (current_buffer->save_length) != -2) + XSETFASTINT (current_buffer->save_length, Z - BEG); current_buffer->filename = visit_file; } UNGCPRO; @@ -4703,7 +4704,8 @@ This calls `write-region-annotate-functions' at the start, and if (visiting) { SAVE_MODIFF = MODIFF; - XSETFASTINT (current_buffer->save_length, Z - BEG); + if (XINT (current_buffer->save_length) != -2) + XSETFASTINT (current_buffer->save_length, Z - BEG); current_buffer->filename = visit_file; update_mode_lines++; } @@ -5307,7 +5309,7 @@ A non-nil CURRENT-ONLY argument means save only current buffer. */) && BUF_SAVE_MODIFF (b) < BUF_MODIFF (b) && b->auto_save_modified < BUF_MODIFF (b) /* -1 means we've turned off autosaving for a while--see below. */ - && XINT (b->save_length) >= 0 + && XINT (b->save_length) != -1 && (do_handled_files || NILP (Ffind_file_name_handler (b->auto_save_file_name, Qwrite_region)))) @@ -5321,8 +5323,10 @@ A non-nil CURRENT-ONLY argument means save only current buffer. */) && EMACS_SECS (before_time) - b->auto_save_failure_time < 1200) continue; - if ((XFASTINT (b->save_length) * 10 - > (BUF_Z (b) - BUF_BEG (b)) * 13) + if (XINT (b->save_length) != -2 + /* -2 is a magic flag turning off this feature in a buffer. */ + && (XFASTINT (b->save_length) * 10 + > (BUF_Z (b) - BUF_BEG (b)) * 13) /* A short file is likely to change a large fraction; spare the user annoying messages. */ && XFASTINT (b->save_length) > 5000 @@ -5347,7 +5351,8 @@ A non-nil CURRENT-ONLY argument means save only current buffer. */) internal_condition_case (auto_save_1, Qt, auto_save_error); auto_saved++; b->auto_save_modified = BUF_MODIFF (b); - XSETFASTINT (current_buffer->save_length, Z - BEG); + if (XINT (current_buffer->save_length) != -2) + XSETFASTINT (current_buffer->save_length, Z - BEG); set_buffer_internal (old); EMACS_GET_TIME (after_time); @@ -5392,7 +5397,8 @@ No auto-save file will be written until the buffer changes again. */) () { current_buffer->auto_save_modified = MODIFF; - XSETFASTINT (current_buffer->save_length, Z - BEG); + if (XINT (current_buffer->save_length) != -2) + XSETFASTINT (current_buffer->save_length, Z - BEG); current_buffer->auto_save_failure_time = -1; return Qnil; } -- 2.39.2