To: vim_dev@googlegroups.com Subject: Patch 9.0.0756 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 9.0.0756 Problem: No autocmd event for changing text in a terminal window. Solution: Add TextChangedT. (Shougo Matsushita, closes #11366) Files: runtime/doc/autocmd.txt, src/autocmd.c, src/terminal.c, src/vim.h, src/testdir/test_terminal.vim *** ../vim-9.0.0755/runtime/doc/autocmd.txt 2022-06-28 11:21:05.000000000 +0100 --- runtime/doc/autocmd.txt 2022-10-15 11:41:05.006166346 +0100 *************** *** 409,414 **** --- 409,415 ---- when popup menu is not visible |TextChangedP| after a change was made to the text in Insert mode when popup menu visible + |TextChangedT| after a change was made to the text in Terminal mode |TextYankPost| after text has been yanked or deleted |SafeState| nothing pending, going to wait for the user to type a *************** *** 1235,1240 **** --- 1238,1247 ---- current buffer in Insert mode, only when the popup menu is visible. Otherwise the same as TextChanged. + *TextChangedT* + TextChangedT After a change was made to the text in the + current buffer in Terminal mode. + Otherwise the same as TextChanged. *TextYankPost* TextYankPost After text has been yanked or deleted in the current buffer. The following values of *** ../vim-9.0.0755/src/autocmd.c 2022-10-10 13:46:09.977158083 +0100 --- src/autocmd.c 2022-10-15 11:41:05.006166346 +0100 *************** *** 182,187 **** --- 182,188 ---- {"TextChanged", EVENT_TEXTCHANGED}, {"TextChangedI", EVENT_TEXTCHANGEDI}, {"TextChangedP", EVENT_TEXTCHANGEDP}, + {"TextChangedT", EVENT_TEXTCHANGEDT}, {"User", EVENT_USER}, {"VimEnter", EVENT_VIMENTER}, {"VimLeave", EVENT_VIMLEAVE}, *** ../vim-9.0.0755/src/terminal.c 2022-10-13 22:12:07.172673790 +0100 --- src/terminal.c 2022-10-15 11:41:05.006166346 +0100 *************** *** 1222,1227 **** --- 1222,1229 ---- setcursor(); if (redraw) { + aco_save_T aco; + if (term->tl_buffer == curbuf && term->tl_cursor_visible) cursor_on(); out_flush(); *************** *** 1232,1237 **** --- 1234,1249 ---- gui_mch_flush(); } #endif + // Make sure an invoked autocmd doesn't delete the buffer (and the + // terminal) under our fingers. + ++term->tl_buffer->b_locked; + + // save and restore curwin and curbuf, in case the autocmd changes them + aucmd_prepbuf(&aco, curbuf); + apply_autocmds(EVENT_TEXTCHANGEDT, NULL, NULL, FALSE, term->tl_buffer); + aucmd_restbuf(&aco); + + --term->tl_buffer->b_locked; } } *** ../vim-9.0.0755/src/vim.h 2022-10-08 13:49:41.893378443 +0100 --- src/vim.h 2022-10-15 11:41:05.006166346 +0100 *************** *** 1394,1399 **** --- 1394,1400 ---- EVENT_TEXTCHANGED, // text was modified not in Insert mode EVENT_TEXTCHANGEDI, // text was modified in Insert mode EVENT_TEXTCHANGEDP, // TextChangedI with popup menu visible + EVENT_TEXTCHANGEDT, // text was modified in Terminal mode EVENT_TEXTYANKPOST, // after some text was yanked EVENT_USER, // user defined autocommand EVENT_VIMENTER, // after starting Vim *** ../vim-9.0.0755/src/testdir/test_terminal.vim 2022-10-10 11:46:12.206333720 +0100 --- src/testdir/test_terminal.vim 2022-10-15 11:41:05.006166346 +0100 *************** *** 2321,2325 **** --- 2321,2374 ---- bwipe! endfunc + func Test_term_TextChangedT() + augroup TermTest + autocmd TextChangedT * ++once + \ execute expand('') . 'buffer' | + \ let b:called = 1 | + \ split | + \ enew + augroup END + + terminal + + let term_buf = bufnr() + + let b:called = 0 + + call term_sendkeys(term_buf, "aaabbc\r") + call TermWait(term_buf) + + call assert_equal(1, getbufvar(term_buf, 'called')) + + " Current buffer will be restored + call assert_equal(bufnr(), term_buf) + + bwipe! + augroup TermTest + au! + augroup END + endfunc + + func Test_term_TextChangedT_close() + augroup TermTest + autocmd TextChangedT * ++once split | enew | 1close! + augroup END + + terminal + + let term_buf = bufnr() + + call term_sendkeys(term_buf, "aaabbc\r") + call TermWait(term_buf) + + " Current buffer will be restored + call assert_equal(bufnr(), term_buf) + + bwipe! + augroup TermTest + au! + augroup END + endfunc " vim: shiftwidth=2 sts=2 expandtab *** ../vim-9.0.0755/src/version.c 2022-10-15 10:54:22.986157723 +0100 --- src/version.c 2022-10-15 11:47:15.009740028 +0100 *************** *** 697,698 **** --- 697,700 ---- { /* Add new patch number below this line */ + /**/ + 756, /**/ -- BROTHER MAYNARD: Armaments Chapter Two Verses Nine to Twenty One. ANOTHER MONK: And St. Attila raised his hand grenade up on high saying "O Lord bless this thy hand grenade that with it thou mayest blow thine enemies to tiny bits, in thy mercy. "and the Lord did grin and people did feast upon the lambs and sloths and carp and anchovies and orang-utans and breakfast cereals and fruit bats and... BROTHER MAYNARD: Skip a bit brother ... "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// \\\ \\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///