changeset 103917:aa5e8ff5a9c4

* fileio.c (Fwrite_region, Fdo_auto_save): Handle save_length = -2. (Fset_buffer_auto_saved): Handle save_length = -2. Comment changes in other files.
author Richard M. Stallman <rms@gnu.org>
date Thu, 16 Jul 2009 01:45:08 +0000
parents 9653887b5cd0
children 74a905fff633
files src/ChangeLog src/buffer.c src/buffer.h src/fileio.c
diffstat 4 files changed, 27 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/src/ChangeLog	Thu Jul 16 01:24:00 2009 +0000
+++ b/src/ChangeLog	Thu Jul 16 01:45:08 2009 +0000
@@ -1,3 +1,8 @@
+2009-07-16  Richard Stallman  <rms@gnu.org>
+
+	* fileio.c (Fwrite_region, Fdo_auto_save): Handle save_length = -2.
+	(Fset_buffer_auto_saved): Handle save_length = -2.
+
 2009-07-16  Chong Yidong  <cyd@stupidchicken.com>
 
 	* xterm.c (Qx_gtk_map_stock): New var.
--- a/src/buffer.c	Thu Jul 16 01:24:00 2009 +0000
+++ b/src/buffer.c	Thu Jul 16 01:45:08 2009 +0000
@@ -5853,7 +5853,12 @@
   DEFVAR_PER_BUFFER ("buffer-saved-size", &current_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", &current_buffer->selective_display,
 		     Qnil,
--- a/src/buffer.h	Thu Jul 16 01:24:00 2009 +0000
+++ b/src/buffer.h	Thu Jul 16 01:45:08 2009 +0000
@@ -584,6 +584,9 @@
   /* 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;
--- a/src/fileio.c	Thu Jul 16 01:24:00 2009 +0000
+++ b/src/fileio.c	Thu Jul 16 01:45:08 2009 +0000
@@ -4492,7 +4492,8 @@
       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 @@
   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 @@
 	    && 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 @@
 		&& 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 @@
 	    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 @@
      ()
 {
   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;
 }