To: vim_dev@googlegroups.com Subject: Patch 8.0.1633 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.0.1633 Problem: A TextChanged autocmd triggers when it is defined after creating a buffer. Solution: Set b_last_changedtick when opening a buffer. (Hirohito Highlight, closes #2742) Files: src/buffer.c, src/testdir/test_autocmd.vim *** ../vim-8.0.1632/src/buffer.c 2018-03-04 20:14:08.236064419 +0100 --- src/buffer.c 2018-03-23 22:30:41.737228104 +0100 *************** *** 291,296 **** --- 291,303 ---- unchanged(curbuf, FALSE); save_file_ff(curbuf); /* keep this fileformat */ + /* Set last_changedtick to avoid triggering a TextChanged autocommand right + * after it was added. */ + 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 if (aborting()) *** ../vim-8.0.1632/src/testdir/test_autocmd.vim 2018-02-10 18:15:00.758098776 +0100 --- src/testdir/test_autocmd.vim 2018-03-23 22:37:03.326275731 +0100 *************** *** 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,1306 **** --- 1306,1327 ---- 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 call writefile(['No'], 'Xchanged.txt')\") + call term_sendkeys(buf, "\\:qa!\") + call WaitFor({-> term_getstatus(buf) == 'finished'}) + call assert_equal([''], readfile('Xchanged.txt')) + + " clean up + call delete('Xchanged.txt') + bwipe! + endfunc *** ../vim-8.0.1632/src/version.c 2018-03-23 22:10:26.164804315 +0100 --- src/version.c 2018-03-23 22:32:14.116499665 +0100 *************** *** 768,769 **** --- 768,771 ---- { /* Add new patch number below this line */ + /**/ + 1633, /**/ -- "Oh, no! NOT the Spanish Inquisition!" "NOBODY expects the Spanish Inquisition!!!" -- Monty Python sketch -- "Oh, no! NOT another option!" "EVERYBODY expects another option!!!" -- Discussion in vim-dev mailing list -- /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///