Mercurial > vim
changeset 9106:97a9538c37ff v7.4.1837
commit https://github.com/vim/vim/commit/c67e89213476b5f4756d92208b57ce9ef4a4cf24
Author: Bram Moolenaar <Bram@vim.org>
Date: Tue May 24 16:07:40 2016 +0200
patch 7.4.1837
Problem: The BufUnload event is triggered twice, when :bunload is used with
set to or .
Solution: Do not trigger the event when ml_mfp is NULL. (Hirohito Higashi)
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Tue, 24 May 2016 16:15:07 +0200 |
parents | 06f8149137c9 |
children | b2301e342fc5 |
files | src/buffer.c src/testdir/test_autocmd.vim src/version.c |
diffstat | 3 files changed, 56 insertions(+), 24 deletions(-) [+] |
line wrap: on
line diff
--- a/src/buffer.c +++ b/src/buffer.c @@ -574,9 +574,12 @@ buf_freeall(buf_T *buf, int flags) int is_curbuf = (buf == curbuf); buf->b_closing = TRUE; - apply_autocmds(EVENT_BUFUNLOAD, buf->b_fname, buf->b_fname, FALSE, buf); - if (!buf_valid(buf)) /* autocommands may delete the buffer */ - return; + if (buf->b_ml.ml_mfp != NULL) + { + apply_autocmds(EVENT_BUFUNLOAD, buf->b_fname, buf->b_fname, FALSE, buf); + if (!buf_valid(buf)) /* autocommands may delete the buffer */ + return; + } if ((flags & BFA_DEL) && buf->b_p_bl) { apply_autocmds(EVENT_BUFDELETE, buf->b_fname, buf->b_fname, FALSE, buf);
--- a/src/testdir/test_autocmd.vim +++ b/src/testdir/test_autocmd.vim @@ -7,29 +7,56 @@ func Test_vim_did_enter() " becomes one. endfunc -if !has('timers') - finish +if has('timers') + func ExitInsertMode(id) + call feedkeys("\<Esc>") + endfunc + + func Test_cursorhold_insert() + let g:triggered = 0 + au CursorHoldI * let g:triggered += 1 + set updatetime=20 + call timer_start(100, 'ExitInsertMode') + call feedkeys('a', 'x!') + call assert_equal(1, g:triggered) + endfunc + + func Test_cursorhold_insert_ctrl_x() + let g:triggered = 0 + au CursorHoldI * let g:triggered += 1 + set updatetime=20 + call timer_start(100, 'ExitInsertMode') + " CursorHoldI does not trigger after CTRL-X + call feedkeys("a\<C-X>", 'x!') + call assert_equal(0, g:triggered) + endfunc endif -func ExitInsertMode(id) - call feedkeys("\<Esc>") -endfunc +function Test_bufunload() + augroup test_bufunload_group + autocmd! + autocmd BufUnload * call add(s:li, "bufunload") + autocmd BufDelete * call add(s:li, "bufdelete") + autocmd BufWipeout * call add(s:li, "bufwipeout") + augroup END + + let s:li=[] + new + setlocal bufhidden= + bunload + call assert_equal(["bufunload", "bufdelete"], s:li) -func Test_cursorhold_insert() - let g:triggered = 0 - au CursorHoldI * let g:triggered += 1 - set updatetime=20 - call timer_start(100, 'ExitInsertMode') - call feedkeys('a', 'x!') - call assert_equal(1, g:triggered) -endfunc + let s:li=[] + new + setlocal bufhidden=delete + bunload + call assert_equal(["bufunload", "bufdelete"], s:li) -func Test_cursorhold_insert_ctrl_x() - let g:triggered = 0 - au CursorHoldI * let g:triggered += 1 - set updatetime=20 - call timer_start(100, 'ExitInsertMode') - " CursorHoldI does not trigger after CTRL-X - call feedkeys("a\<C-X>", 'x!') - call assert_equal(0, g:triggered) + let s:li=[] + new + setlocal bufhidden=unload + bwipeout + call assert_equal(["bufunload", "bufdelete", "bufwipeout"], s:li) + + augroup! test_bufunload_group endfunc