* fileio.c (Fwrite_region, Fdo_auto_save): Handle save_length = -2.
authorRichard M. Stallman <rms@gnu.org>
Thu, 16 Jul 2009 01:45:08 +0000 (01:45 +0000)
committerRichard M. Stallman <rms@gnu.org>
Thu, 16 Jul 2009 01:45:08 +0000 (01:45 +0000)
(Fset_buffer_auto_saved): Handle save_length = -2.

Comment changes in other files.

src/ChangeLog
src/buffer.c
src/buffer.h
src/fileio.c

index 999269f..698ab0d 100644 (file)
@@ -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.
index f06a6c0..f811f16 100644 (file)
@@ -5853,7 +5853,12 @@ Backing up is done before the first time the file is saved.  */);
   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,
index 1fb322e..397b975 100644 (file)
@@ -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;
index bf96b3a..43872d5 100644 (file)
@@ -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;
 }