mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
vim-patch:8.1.1498: ":write" increments b:changedtick even though nothing changed
Problem: ":write" increments b:changedtick even though nothing changed.
(Daniel Hahler)
Solution: Only increment b:changedtick if the modified flag is reset.
c024b46678
This commit is contained in:
parent
d7aea13fee
commit
83c5701fe6
@ -1313,8 +1313,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()
|
||||
|
@ -144,7 +144,7 @@ read_buffer(
|
||||
if (!readonlymode && !BUFEMPTY()) {
|
||||
changed();
|
||||
} else if (retval != FAIL) {
|
||||
unchanged(curbuf, false);
|
||||
unchanged(curbuf, false, true);
|
||||
}
|
||||
|
||||
apply_autocmds_retval(EVENT_STDINREADPOST, NULL, NULL, false,
|
||||
@ -299,7 +299,7 @@ int open_buffer(
|
||||
|| (aborting() && vim_strchr(p_cpo, CPO_INTMOD) != NULL)) {
|
||||
changed();
|
||||
} else if (retval != FAIL && !read_stdin && !read_fifo) {
|
||||
unchanged(curbuf, false);
|
||||
unchanged(curbuf, false, true);
|
||||
}
|
||||
save_file_ff(curbuf); // keep this fileformat
|
||||
|
||||
@ -641,13 +641,11 @@ void close_buffer(win_T *win, buf_T *buf, int action, int abort_if_last)
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Make buffer not contain a file.
|
||||
*/
|
||||
/// Make buffer not contain a file.
|
||||
void buf_clear_file(buf_T *buf)
|
||||
{
|
||||
buf->b_ml.ml_line_count = 1;
|
||||
unchanged(buf, true);
|
||||
unchanged(buf, true, true);
|
||||
buf->b_p_eol = true;
|
||||
buf->b_start_eol = true;
|
||||
buf->b_p_bomb = false;
|
||||
|
@ -478,9 +478,11 @@ changed_lines(
|
||||
}
|
||||
}
|
||||
|
||||
/// Called when the changed flag must be reset for buffer "buf".
|
||||
/// When "ff" is true also reset 'fileformat'.
|
||||
void unchanged(buf_T *buf, int ff)
|
||||
/// 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 even
|
||||
/// when the changed flag was off.
|
||||
void unchanged(buf_T *buf, int ff, bool always_inc_changedtick)
|
||||
{
|
||||
if (buf->b_changed || (ff && file_ff_differs(buf, false))) {
|
||||
buf->b_changed = false;
|
||||
@ -491,8 +493,10 @@ void unchanged(buf_T *buf, int ff)
|
||||
check_status(buf);
|
||||
redraw_tabline = true;
|
||||
need_maketitle = true; // set window title later
|
||||
buf_inc_changedtick(buf);
|
||||
} else if (always_inc_changedtick) {
|
||||
buf_inc_changedtick(buf);
|
||||
}
|
||||
buf_inc_changedtick(buf);
|
||||
}
|
||||
|
||||
/// Insert string "p" at the cursor position. Stops at a NUL byte.
|
||||
|
@ -1323,7 +1323,7 @@ void dialog_changed(buf_T *buf, bool checkall)
|
||||
(void)buf_write_all(buf, false);
|
||||
}
|
||||
} else if (ret == VIM_NO) {
|
||||
unchanged(buf, true);
|
||||
unchanged(buf, true, false);
|
||||
} else if (ret == VIM_ALL) {
|
||||
// Write all modified files that can be written.
|
||||
// Skip readonly buffers, these need to be confirmed
|
||||
@ -1348,7 +1348,7 @@ void dialog_changed(buf_T *buf, bool checkall)
|
||||
} else if (ret == VIM_DISCARDALL) {
|
||||
// mark all buffers as unchanged
|
||||
FOR_ALL_BUFFERS(buf2) {
|
||||
unchanged(buf2, true);
|
||||
unchanged(buf2, true, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3485,10 +3485,10 @@ restore_backup:
|
||||
if (reset_changed && whole && !append
|
||||
&& !write_info.bw_conv_error
|
||||
&& (overwriting || vim_strchr(p_cpo, CPO_PLUS) != NULL)) {
|
||||
unchanged(buf, true);
|
||||
unchanged(buf, true, false);
|
||||
const varnumber_T changedtick = buf_get_changedtick(buf);
|
||||
if (buf->b_last_changedtick + 1 == changedtick) {
|
||||
// changedtick is always incremented in unchanged() but that
|
||||
// b:changedtick may be incremented in unchanged() but that
|
||||
// should not trigger a TextChanged event.
|
||||
buf->b_last_changedtick = changedtick;
|
||||
}
|
||||
@ -5107,14 +5107,14 @@ void buf_reload(buf_T *buf, int orig_mode)
|
||||
}
|
||||
(void)move_lines(savebuf, buf);
|
||||
}
|
||||
} else if (buf == curbuf) { /* "buf" still valid */
|
||||
/* Mark the buffer as unmodified and free undo info. */
|
||||
unchanged(buf, TRUE);
|
||||
} else if (buf == curbuf) { // "buf" still valid.
|
||||
// Mark the buffer as unmodified and free undo info.
|
||||
unchanged(buf, true, true);
|
||||
if ((flags & READ_KEEP_UNDO) == 0) {
|
||||
u_blockfree(buf);
|
||||
u_clearall(buf);
|
||||
} else {
|
||||
/* Mark all undo states as changed. */
|
||||
// Mark all undo states as changed.
|
||||
u_unchanged(curbuf);
|
||||
}
|
||||
}
|
||||
|
@ -1003,7 +1003,7 @@ void ml_recover(void)
|
||||
set_option_value("fenc", 0L, (char *)b0_fenc, OPT_LOCAL);
|
||||
xfree(b0_fenc);
|
||||
}
|
||||
unchanged(curbuf, TRUE);
|
||||
unchanged(curbuf, true, true);
|
||||
|
||||
bnum = 1; /* start with block 1 */
|
||||
page_count = 1; /* which is 1 page */
|
||||
|
@ -2294,7 +2294,7 @@ static void u_undoredo(int undo, bool do_buf_event)
|
||||
if (old_flags & UH_CHANGED) {
|
||||
changed();
|
||||
} else {
|
||||
unchanged(curbuf, FALSE);
|
||||
unchanged(curbuf, false, true);
|
||||
}
|
||||
|
||||
// because the calls to changed()/unchanged() above will bump changedtick
|
||||
|
Loading…
Reference in New Issue
Block a user