After recovery check if the text changed. If it did mark the buffer as
modified.
diff --git a/src/memline.c b/src/memline.c
index 74f94ed..145c2a8 100644
--- a/src/memline.c
+++ b/src/memline.c
@@ -870,6 +870,7 @@
int serious_error = TRUE;
long mtime;
int attr;
+ int orig_file_status = NOTDONE;
recoverymode = TRUE;
called_from_main = (curbuf->b_ml.ml_mfp == NULL);
@@ -1119,12 +1120,8 @@
* 'fileencoding', etc. Ignore errors. The text itself is not used.
*/
if (curbuf->b_ffname != NULL)
- {
- (void)readfile(curbuf->b_ffname, NULL, (linenr_T)0,
+ orig_file_status = readfile(curbuf->b_ffname, NULL, (linenr_T)0,
(linenr_T)0, (linenr_T)MAXLNUM, NULL, READ_NEW);
- while (!(curbuf->b_ml.ml_flags & ML_EMPTY))
- ml_delete((linenr_T)1, FALSE);
- }
/* Use the 'fileformat' and 'fileencoding' as stored in the swap file. */
if (b0_ff != 0)
@@ -1325,10 +1322,46 @@
}
/*
- * The dummy line from the empty buffer will now be after the last line in
- * the buffer. Delete it.
+ * Compare the buffer contents with the original file. When they differ
+ * set the 'modified' flag.
+ * Lines 1 - lnum are the new contents.
+ * Lines lnum + 1 to ml_line_count are the original contents.
+ * Line ml_line_count + 1 in the dummy empty line.
*/
- ml_delete(curbuf->b_ml.ml_line_count, FALSE);
+ if (orig_file_status != OK || curbuf->b_ml.ml_line_count != lnum * 2 + 1)
+ {
+ /* Recovering an empty file results in two lines and the first line is
+ * empty. Don't set the modified flag then. */
+ if (!(curbuf->b_ml.ml_line_count == 2 && *ml_get(1) == NUL))
+ {
+ changed_int();
+ ++curbuf->b_changedtick;
+ }
+ }
+ else
+ {
+ for (idx = 1; idx <= lnum; ++idx)
+ {
+ /* Need to copy one line, fetching the other one may flush it. */
+ p = vim_strsave(ml_get(idx));
+ i = STRCMP(p, ml_get(idx + lnum));
+ vim_free(p);
+ if (i != 0)
+ {
+ changed_int();
+ ++curbuf->b_changedtick;
+ break;
+ }
+ }
+ }
+
+ /*
+ * Delete the lines from the original file and the dummy line from the
+ * empty buffer. These will now be after the last line in the buffer.
+ */
+ while (curbuf->b_ml.ml_line_count > lnum
+ && !(curbuf->b_ml.ml_flags & ML_EMPTY))
+ ml_delete(curbuf->b_ml.ml_line_count, FALSE);
curbuf->b_flags |= BF_RECOVERED;
recoverymode = FALSE;
@@ -1345,10 +1378,15 @@
}
else
{
- MSG(_("Recovery completed. You should check if everything is OK."));
- MSG_PUTS(_("\n(You might want to write out this file under another name\n"));
- MSG_PUTS(_("and run diff with the original file to check for changes)\n"));
- MSG_PUTS(_("Delete the .swp file afterwards.\n\n"));
+ if (curbuf->b_changed)
+ {
+ MSG(_("Recovery completed. You should check if everything is OK."));
+ MSG_PUTS(_("\n(You might want to write out this file under another name\n"));
+ MSG_PUTS(_("and run diff with the original file to check for changes)"));
+ }
+ else
+ MSG(_("Recovery completed. Buffer contents equals file contents."));
+ MSG_PUTS(_("\nYou may want to delete the .swp file now.\n\n"));
cmdline_row = msg_row;
}
redraw_curbuf_later(NOT_VALID);
diff --git a/src/misc1.c b/src/misc1.c
index ffd0b83..d476f31 100644
--- a/src/misc1.c
+++ b/src/misc1.c
@@ -2514,19 +2514,28 @@
msg_scroll = save_msg_scroll;
}
}
- curbuf->b_changed = TRUE;
- ml_setflags(curbuf);
-#ifdef FEAT_WINDOWS
- check_status(curbuf);
- redraw_tabline = TRUE;
-#endif
-#ifdef FEAT_TITLE
- need_maketitle = TRUE; /* set window title later */
-#endif
+ changed_int();
}
++curbuf->b_changedtick;
}
+/*
+ * Internal part of changed(), no user interaction.
+ */
+ void
+changed_int()
+{
+ curbuf->b_changed = TRUE;
+ ml_setflags(curbuf);
+#ifdef FEAT_WINDOWS
+ check_status(curbuf);
+ redraw_tabline = TRUE;
+#endif
+#ifdef FEAT_TITLE
+ need_maketitle = TRUE; /* set window title later */
+#endif
+}
+
static void changedOneline __ARGS((buf_T *buf, linenr_T lnum));
static void changed_lines_buf __ARGS((buf_T *buf, linenr_T lnum, linenr_T lnume, long xtra));
static void changed_common __ARGS((linenr_T lnum, colnr_T col, linenr_T lnume, long xtra));
diff --git a/src/proto/misc1.pro b/src/proto/misc1.pro
index a036e3e..e7a820f 100644
--- a/src/proto/misc1.pro
+++ b/src/proto/misc1.pro
@@ -30,6 +30,7 @@
int inindent __ARGS((int extra));
char_u *skip_to_option_part __ARGS((char_u *p));
void changed __ARGS((void));
+void changed_int __ARGS((void));
void changed_bytes __ARGS((linenr_T lnum, colnr_T col));
void appended_lines __ARGS((linenr_T lnum, long count));
void appended_lines_mark __ARGS((linenr_T lnum, long count));