summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2019-06-08 18:07:21 +0200
committerBram Moolenaar <Bram@vim.org>2019-06-08 18:07:21 +0200
commitc024b4667875e5bc6fd0ed791530e33c3161bff7 (patch)
tree4b7c358c24cb5f5d6d36a40250afbd44eaf6dda7
parentaef5c62a6fff7654bb8df7b9359e811f7a6e428f (diff)
downloadvim-git-c024b4667875e5bc6fd0ed791530e33c3161bff7.tar.gz
patch 8.1.1498: ":write" increments b:changedtick even though nothing changedv8.1.1498
Problem: ":write" increments b:changedtick even though nothing changed. (Daniel Hahler) Solution: Only increment b:changedtick if the modified flag is reset.
-rw-r--r--runtime/doc/eval.txt6
-rw-r--r--src/buffer.c10
-rw-r--r--src/change.c8
-rw-r--r--src/ex_cmds2.c4
-rw-r--r--src/fileio.c6
-rw-r--r--src/memline.c2
-rw-r--r--src/proto/change.pro2
-rw-r--r--src/undo.c2
-rw-r--r--src/version.c2
9 files changed, 26 insertions, 16 deletions
diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt
index 0b44e58e2..85230a60a 100644
--- a/runtime/doc/eval.txt
+++ b/runtime/doc/eval.txt
@@ -1504,8 +1504,10 @@ One local buffer variable is predefined:
*b:changedtick* *changetick*
b:changedtick The total number of changes to the current buffer. It is
incremented for each change. An undo command is also a change
- in this case. This can be used to perform an action only when
- the buffer has changed. Example: >
+ in this case. Resetting 'modified' when writing the buffer is
+ also counted.
+ This can be used to perform an action only when the buffer has
+ changed. Example: >
:if my_changedtick != b:changedtick
: let my_changedtick = b:changedtick
: call My_Update()
diff --git a/src/buffer.c b/src/buffer.c
index 66f6fc654..e6ae09d25 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -60,7 +60,9 @@ static char *e_auabort = N_("E855: Autocommands caused command to abort");
/* Number of times free_buffer() was called. */
static int buf_free_count = 0;
-/* Read data from buffer for retrying. */
+/*
+ * Read data from buffer for retrying.
+ */
static int
read_buffer(
int read_stdin, /* read file from stdin, otherwise fifo */
@@ -104,7 +106,7 @@ read_buffer(
if (!readonlymode && !BUFEMPTY())
changed();
else if (retval == OK)
- unchanged(curbuf, FALSE);
+ unchanged(curbuf, FALSE, TRUE);
if (retval == OK)
{
@@ -275,7 +277,7 @@ open_buffer(
)
changed();
else if (retval == OK && !read_stdin && !read_fifo)
- unchanged(curbuf, FALSE);
+ unchanged(curbuf, FALSE, TRUE);
save_file_ff(curbuf); /* keep this fileformat */
/* Set last_changedtick to avoid triggering a TextChanged autocommand right
@@ -700,7 +702,7 @@ aucmd_abort:
buf_clear_file(buf_T *buf)
{
buf->b_ml.ml_line_count = 1;
- unchanged(buf, TRUE);
+ unchanged(buf, TRUE, TRUE);
buf->b_shortname = FALSE;
buf->b_p_eol = TRUE;
buf->b_start_eol = TRUE;
diff --git a/src/change.c b/src/change.c
index fcaa5708a..b928786eb 100644
--- a/src/change.c
+++ b/src/change.c
@@ -842,9 +842,11 @@ changed_lines(
/*
* Called when the changed flag must be reset for buffer "buf".
* When "ff" is TRUE also reset 'fileformat'.
+ * When "always_inc_changedtick" is TRUE b:changedtick is incremented also when
+ * the changed flag was off.
*/
void
-unchanged(buf_T *buf, int ff)
+unchanged(buf_T *buf, int ff, int always_inc_changedtick)
{
if (buf->b_changed || (ff && file_ff_differs(buf, FALSE)))
{
@@ -857,8 +859,10 @@ unchanged(buf_T *buf, int ff)
#ifdef FEAT_TITLE
need_maketitle = TRUE; // set window title later
#endif
+ ++CHANGEDTICK(buf);
}
- ++CHANGEDTICK(buf);
+ else if (always_inc_changedtick)
+ ++CHANGEDTICK(buf);
#ifdef FEAT_NETBEANS_INTG
netbeans_unmodified(buf);
#endif
diff --git a/src/ex_cmds2.c b/src/ex_cmds2.c
index 66e5fca12..3c73030e6 100644
--- a/src/ex_cmds2.c
+++ b/src/ex_cmds2.c
@@ -1197,7 +1197,7 @@ dialog_changed(
}
else if (ret == VIM_NO)
{
- unchanged(buf, TRUE);
+ unchanged(buf, TRUE, FALSE);
}
else if (ret == VIM_ALL)
{
@@ -1240,7 +1240,7 @@ dialog_changed(
* mark all buffers as unchanged
*/
FOR_ALL_BUFFERS(buf2)
- unchanged(buf2, TRUE);
+ unchanged(buf2, TRUE, FALSE);
}
}
#endif
diff --git a/src/fileio.c b/src/fileio.c
index d746298a7..e6fb6bfae 100644
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -4908,8 +4908,8 @@ restore_backup:
&& !write_info.bw_conv_error
&& (overwriting || vim_strchr(p_cpo, CPO_PLUS) != NULL))
{
- unchanged(buf, TRUE);
- /* b:changedtick is always incremented in unchanged() but that
+ unchanged(buf, TRUE, FALSE);
+ /* b:changedtick is may be incremented in unchanged() but that
* should not trigger a TextChanged event. */
if (buf->b_last_changedtick + 1 == CHANGEDTICK(buf))
buf->b_last_changedtick = CHANGEDTICK(buf);
@@ -7081,7 +7081,7 @@ buf_reload(buf_T *buf, int orig_mode)
else if (buf == curbuf) /* "buf" still valid */
{
/* Mark the buffer as unmodified and free undo info. */
- unchanged(buf, TRUE);
+ unchanged(buf, TRUE, TRUE);
if ((flags & READ_KEEP_UNDO) == 0)
{
u_blockfree(buf);
diff --git a/src/memline.c b/src/memline.c
index 5ae99dfd9..e7ae6dfb5 100644
--- a/src/memline.c
+++ b/src/memline.c
@@ -1435,7 +1435,7 @@ ml_recover(int checkext)
set_option_value((char_u *)"fenc", 0L, b0_fenc, OPT_LOCAL);
vim_free(b0_fenc);
}
- unchanged(curbuf, TRUE);
+ unchanged(curbuf, TRUE, TRUE);
bnum = 1; /* start with block 1 */
page_count = 1; /* which is 1 page */
diff --git a/src/proto/change.pro b/src/proto/change.pro
index 79306e306..de3a94a9d 100644
--- a/src/proto/change.pro
+++ b/src/proto/change.pro
@@ -14,7 +14,7 @@ void appended_lines_mark(linenr_T lnum, long count);
void deleted_lines(linenr_T lnum, long count);
void deleted_lines_mark(linenr_T lnum, long count);
void changed_lines(linenr_T lnum, colnr_T col, linenr_T lnume, long xtra);
-void unchanged(buf_T *buf, int ff);
+void unchanged(buf_T *buf, int ff, int always_inc_changedtick);
void ins_bytes(char_u *p);
void ins_bytes_len(char_u *p, int len);
void ins_char(int c);
diff --git a/src/undo.c b/src/undo.c
index cf3f866e8..dd4667001 100644
--- a/src/undo.c
+++ b/src/undo.c
@@ -2805,7 +2805,7 @@ u_undoredo(int undo)
/* per netbeans undo rules, keep it as modified */
if (!isNetbeansModified(curbuf))
#endif
- unchanged(curbuf, FALSE);
+ unchanged(curbuf, FALSE, TRUE);
/*
* restore marks from before undo/redo
diff --git a/src/version.c b/src/version.c
index 8aac5d5f6..79b0d55ae 100644
--- a/src/version.c
+++ b/src/version.c
@@ -768,6 +768,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 1498,
+/**/
1497,
/**/
1496,