Skip to content

Instantly share code, notes, and snippets.

@h-east
Last active March 23, 2018 05:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save h-east/db4472b2e104ca79f6dce56974e791d4 to your computer and use it in GitHub Desktop.
Save h-east/db4472b2e104ca79f6dce56974e791d4 to your computer and use it in GitHub Desktop.
diff --git a/src/buffer.c b/src/buffer.c
index b292150a2..a153dd46a 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -290,6 +290,10 @@ open_buffer(
else if (retval == OK && !read_stdin && !read_fifo)
unchanged(curbuf, FALSE);
save_file_ff(curbuf); /* keep this fileformat */
+ curbuf->b_last_changedtick = CHANGEDTICK(curbuf);
+#ifdef FEAT_INS_EXPAND
+ curbuf->b_last_changedtick_pum = CHANGEDTICK(curbuf);
+#endif
/* require "!" to overwrite the file, because it wasn't read completely */
#ifdef FEAT_EVAL
diff --git a/src/testdir/test_autocmd.vim b/src/testdir/test_autocmd.vim
index d1ce56197..a55f13071 100644
--- a/src/testdir/test_autocmd.vim
+++ b/src/testdir/test_autocmd.vim
@@ -1,5 +1,7 @@
" Tests for autocommands
+source shared.vim
+
func! s:cleanup_buffers() abort
for bnr in range(1, bufnr('$'))
if bufloaded(bnr) && bufnr('%') != bnr
@@ -1304,3 +1306,22 @@ func Test_ChangedP()
bw!
endfunc
+
+func Test_Changed_FirstTime()
+ if !has('terminal') || has('gui_running')
+ return
+ endif
+ " Prepare file for TextChanged event.
+ call writefile([''], 'Xchanged.txt')
+ let buf = term_start([GetVimProg(), '--clean', '-c', 'set noswapfile'], {'term_rows': 3})
+ call assert_equal('running', term_getstatus(buf))
+ " It's only adding autocmd, so that no event occurs.
+ call term_sendkeys(buf, ":au! TextChanged <buffer> call writefile(['No'], 'Xchanged.txt')\<cr>")
+ call term_sendkeys(buf, "\<C-\\>\<C-N>:qa!\<cr>")
+ call WaitFor({-> term_getstatus(buf) == 'finished'})
+ call assert_equal([''], readfile('Xchanged.txt'))
+ " clean up
+ call delete('Xchanged.txt')
+
+ bwipe!
+endfunc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment