# HG changeset patch # User Stefan Monnier # Date 1263357222 18000 # Node ID 4040ecb0c904ba10620a40adba63b28250f7ef0b # Parent b727bf8894829c75c2af324cd4642d99a4e237ce Try to fix bug#5314. This is probably not the final word, tho. * buffer.c (Fset_buffer_modified_p): Try and be careful not to modify recent-auto-save-p as a side-effect. * buffer.h (BUF_AUTOSAVE_MODIFF): New macro. * buffer.c (Fkill_buffer, reset_buffer): * editfns.c (Fsubst_char_in_region): * fileio.c (Finsert_file_contents, Fdo_auto_save) (Fset_buffer_auto_saved, Frecent_auto_save_p): Use it. diff -r b727bf889482 -r 4040ecb0c904 src/ChangeLog --- a/src/ChangeLog Wed Jan 13 10:40:39 2010 +0900 +++ b/src/ChangeLog Tue Jan 12 23:33:42 2010 -0500 @@ -1,17 +1,28 @@ +2010-01-13 Stefan Monnier + + Try to fix bug#5314. This is probably not the final word, tho. + * buffer.c (Fset_buffer_modified_p): Try and be careful not to modify + recent-auto-save-p as a side-effect. + * buffer.h (BUF_AUTOSAVE_MODIFF): New macro. + * buffer.c (Fkill_buffer, reset_buffer): + * editfns.c (Fsubst_char_in_region): + * fileio.c (Finsert_file_contents, Fdo_auto_save) + (Fset_buffer_auto_saved, Frecent_auto_save_p): Use it. + 2010-01-13 Kenichi Handa Display buffer name, etc. in mode line by composing correctly. * xdisp.c (reseat_to_string): Call composition_compute_stop_pos if STRING is not nil. - (display_mode_element): Adjusted for the change of + (display_mode_element): Adjust for the change of decode_mode_spec and display_line. (decode_mode_spec): Change arg MULTIBYTE to STRING. (display_string): Handle the case that STRING is non-null and LISP_STRING is not nil. - * xterm.c (x_draw_composite_glyph_string_foreground): Pay - attention to s->face->overstrike. + * xterm.c (x_draw_composite_glyph_string_foreground): + Pay attention to s->face->overstrike. * composite.c (composition_reseat_it): Don't check PT if STRING is non nil. @@ -125,8 +136,8 @@ (x_set_window_size): ... to here. bug #2568. * gtkutil.c (xg_clear_under_internal_border): New function. - (xg_frame_resized, xg_frame_set_char_size): Call - xg_clear_under_internal_border. + (xg_frame_resized, xg_frame_set_char_size): + Call xg_clear_under_internal_border. (xg_update_scrollbar_pos): Clear under old scroll bar position. 2010-01-05 Chong Yidong @@ -250,8 +261,8 @@ and atimer.h. (minibuf.o): Depend on systime.h and coding.h. Don't depend on dispextern.h explicitly. - (print.o): Depend on termhooks.h, coding.h, and ccl.h. Don't - depend explicitly on dispextern.h and composite.h. + (print.o): Depend on termhooks.h, coding.h, and ccl.h. + Don't depend explicitly on dispextern.h and composite.h. (process.o): Depend on character.h, xgselect.h, and sysselect.h. (regex.o): Don't depend on charset.h. (scroll.o): Depend on systime.h, coding.h, composite.h, and window.h. @@ -430,8 +441,8 @@ 2009-12-04 Eli Zaretskii - * dispextern.h (enum prop_idx) : Delete - unused enumeration value. + * dispextern.h (enum prop_idx) : + Delete unused enumeration value. 2009-12-03 Eli Zaretskii @@ -562,8 +573,8 @@ 2009-11-21 Andreas Schwab - * character.h (STRING_CHAR, STRING_CHAR_AND_LENGTH): Remove - ignored second argument. All callers changed. + * character.h (STRING_CHAR, STRING_CHAR_AND_LENGTH): + Remove ignored second argument. All callers changed. * regex.c (STRING_CHAR, STRING_CHAR_AND_LENGTH, RE_STRING_CHAR) (RE_STRING_CHAR_AND_LENGTH): Likewise. * xdisp.c (string_char_and_length): Likewise. diff -r b727bf889482 -r 4040ecb0c904 src/buffer.c --- a/src/buffer.c Wed Jan 13 10:40:39 2010 +0900 +++ b/src/buffer.c Tue Jan 12 23:33:42 2010 -0500 @@ -1,7 +1,7 @@ /* Buffer manipulation primitives for GNU Emacs. Copyright (C) 1985, 1986, 1987, 1988, 1989, 1993, 1994, 1995, 1997, 1998, 1999, 2000, 2001, 2002, - 2003, 2004, 2005, 2006, 2007, 2008, 2009 + 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc. This file is part of GNU Emacs. @@ -704,7 +704,7 @@ b->clip_changed = 0; b->prevent_redisplay_optimizations_p = 1; b->backed_up = Qnil; - b->auto_save_modified = 0; + BUF_AUTOSAVE_MODIFF (b) = 0; b->auto_save_failure_time = -1; b->auto_save_file_name = Qnil; b->read_only = Qnil; @@ -1132,7 +1132,25 @@ } #endif /* CLASH_DETECTION */ - SAVE_MODIFF = NILP (flag) ? MODIFF : 0; + /* Here we have a problem. SAVE_MODIFF is used here to encode + buffer-modified-p (as SAVE_MODIFF=auto_save_modified + we risk changing recent-auto-save-p from nil to t. */ + SAVE_MODIFF = (NILP (flag) + /* FIXME: This unavoidably sets recent-auto-save-p to nil. */ + ? MODIFF + /* Let's try to preserve recent-auto-save-p. */ + : SAVE_MODIFF < MODIFF ? SAVE_MODIFF + /* If SAVE_MODIFF == auto_save_modified == MODIFF, + we can either decrease SAVE_MODIFF and auto_save_modified + or increase MODIFF. */ + : MODIFF++); /* Set update_mode_lines only if buffer is displayed in some window. Packages like jit-lock or lazy-lock preserve a buffer's modified @@ -1541,8 +1559,8 @@ /* Delete any auto-save file, if we saved it in this session. But not if the buffer is modified. */ if (STRINGP (b->auto_save_file_name) - && b->auto_save_modified != 0 - && BUF_SAVE_MODIFF (b) < b->auto_save_modified + && BUF_AUTOSAVE_MODIFF (b) != 0 + && BUF_SAVE_MODIFF (b) < BUF_AUTOSAVE_MODIFF (b) && BUF_SAVE_MODIFF (b) < BUF_MODIFF (b) && NILP (Fsymbol_value (intern ("auto-save-visited-file-name")))) { diff -r b727bf889482 -r 4040ecb0c904 src/buffer.h --- a/src/buffer.h Wed Jan 13 10:40:39 2010 +0900 +++ b/src/buffer.h Tue Jan 12 23:33:42 2010 -0500 @@ -1,6 +1,6 @@ /* Header file for the buffer manipulation primitives. Copyright (C) 1985, 1986, 1993, 1994, 1995, 1997, 1998, 1999, 2000, 2001, - 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 + 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc. This file is part of GNU Emacs. @@ -158,6 +158,10 @@ /* Overlay modification count. */ #define BUF_OVERLAY_MODIFF(buf) ((buf)->text->overlay_modiff) +/* Modification count as of last auto-save. */ +/* FIXME: should we move this into ->text->auto_save_modiff? */ +#define BUF_AUTOSAVE_MODIFF(buf) ((buf)->auto_save_modified) + /* Interval tree of buffer. */ #define BUF_INTERVALS(buf) ((buf)->text->intervals) diff -r b727bf889482 -r 4040ecb0c904 src/editfns.c --- a/src/editfns.c Wed Jan 13 10:40:39 2010 +0900 +++ b/src/editfns.c Tue Jan 12 23:33:42 2010 -0500 @@ -1,7 +1,7 @@ /* Lisp functions pertaining to editing. Copyright (C) 1985, 1986, 1987, 1989, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, - 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc. + 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc. This file is part of GNU Emacs. @@ -2870,8 +2870,8 @@ { if (MODIFF - 1 == SAVE_MODIFF) SAVE_MODIFF++; - if (MODIFF - 1 == current_buffer->auto_save_modified) - current_buffer->auto_save_modified++; + if (MODIFF - 1 == BUF_AUTOSAVE_MODIFF (current_buffer)) + BUF_AUTOSAVE_MODIFF (current_buffer)++; } /* The before-change-function may have moved the gap diff -r b727bf889482 -r 4040ecb0c904 src/fileio.c --- a/src/fileio.c Wed Jan 13 10:40:39 2010 +0900 +++ b/src/fileio.c Tue Jan 12 23:33:42 2010 -0500 @@ -1,7 +1,7 @@ /* File IO for GNU Emacs. Copyright (C) 1985, 1986, 1987, 1988, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, - 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc. + 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc. This file is part of GNU Emacs. @@ -4097,7 +4097,7 @@ } SAVE_MODIFF = MODIFF; - current_buffer->auto_save_modified = MODIFF; + BUF_AUTOSAVE_MODIFF (current_buffer) = MODIFF; XSETFASTINT (current_buffer->save_length, Z - BEG); #ifdef CLASH_DETECTION if (NILP (handler)) @@ -5307,7 +5307,7 @@ and file changed since last real save. */ if (STRINGP (b->auto_save_file_name) && BUF_SAVE_MODIFF (b) < BUF_MODIFF (b) - && b->auto_save_modified < BUF_MODIFF (b) + && BUF_AUTOSAVE_MODIFF (b) < BUF_MODIFF (b) /* -1 means we've turned off autosaving for a while--see below. */ && XINT (b->save_length) >= 0 && (do_handled_files @@ -5349,7 +5349,7 @@ message1 ("Auto-saving..."); internal_condition_case (auto_save_1, Qt, auto_save_error); auto_saved++; - b->auto_save_modified = BUF_MODIFF (b); + BUF_AUTOSAVE_MODIFF (b) = BUF_MODIFF (b); XSETFASTINT (current_buffer->save_length, Z - BEG); set_buffer_internal (old); @@ -5394,7 +5394,9 @@ No auto-save file will be written until the buffer changes again. */) () { - current_buffer->auto_save_modified = MODIFF; + /* FIXME: This should not be called in indirect buffers, since + they're not autosaved. */ + BUF_AUTOSAVE_MODIFF (current_buffer) = MODIFF; XSETFASTINT (current_buffer->save_length, Z - BEG); current_buffer->auto_save_failure_time = -1; return Qnil; @@ -5417,7 +5419,9 @@ then any auto-save counts as "recent". */) () { - return (SAVE_MODIFF < current_buffer->auto_save_modified) ? Qt : Qnil; + /* FIXME: maybe we should return nil for indirect buffers since + they're never autosaved. */ + return (SAVE_MODIFF < BUF_AUTOSAVE_MODIFF (current_buffer) ? Qt : Qnil); } /* Reading and completing file names */