Problem: ":write" increments b:changedtick even though nothing changed.
(Daniel Hahler)
Solution: Only increment b:changedtick if the modified flag is reset.
*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()
/* 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 */
if (!readonlymode && !BUFEMPTY())
changed();
else if (retval == OK)
- unchanged(curbuf, FALSE);
+ unchanged(curbuf, FALSE, TRUE);
if (retval == OK)
{
)
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
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;
/*
* 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)))
{
#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
}
else if (ret == VIM_NO)
{
- unchanged(buf, TRUE);
+ unchanged(buf, TRUE, FALSE);
}
else if (ret == VIM_ALL)
{
* mark all buffers as unchanged
*/
FOR_ALL_BUFFERS(buf2)
- unchanged(buf2, TRUE);
+ unchanged(buf2, TRUE, FALSE);
}
}
#endif
&& !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);
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);
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 */
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);
/* 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
static int included_patches[] =
{ /* Add new patch number below this line */
+/**/
+ 1498,
/**/
1497,
/**/