summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorShougo Matsushita <Shougo.Matsu@gmail.com>2022-10-15 11:48:00 +0100
committerBram Moolenaar <Bram@vim.org>2022-10-15 11:48:00 +0100
commit4ccaedfcd7526983f4b6b3b06b0bfb54f333f1f3 (patch)
treeba5cebcced4528b7a7ce20ccc5f546f4bd8585ed
parentd988ef3a555df2c686899a74393ed53b3186370c (diff)
patch 9.0.0756: no autocmd event for changing text in a terminal windowv9.0.0756
Problem: No autocmd event for changing text in a terminal window. Solution: Add TextChangedT. (Shougo Matsushita, closes #11366)
-rw-r--r--runtime/doc/autocmd.txt5
-rw-r--r--src/autocmd.c1
-rw-r--r--src/terminal.c12
-rw-r--r--src/testdir/test_terminal.vim49
-rw-r--r--src/version.c2
-rw-r--r--src/vim.h1
6 files changed, 70 insertions, 0 deletions
diff --git a/runtime/doc/autocmd.txt b/runtime/doc/autocmd.txt
index 61db274bb4..5051cc3dc0 100644
--- a/runtime/doc/autocmd.txt
+++ b/runtime/doc/autocmd.txt
@@ -409,6 +409,7 @@ Name triggered by ~
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
@@ -1237,6 +1238,10 @@ TextChangedP After a change was made to the text in the
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
diff --git a/src/autocmd.c b/src/autocmd.c
index 93da0bbbb1..cf0f0946a8 100644
--- a/src/autocmd.c
+++ b/src/autocmd.c
@@ -182,6 +182,7 @@ static struct event_name
{"TextChanged", EVENT_TEXTCHANGED},
{"TextChangedI", EVENT_TEXTCHANGEDI},
{"TextChangedP", EVENT_TEXTCHANGEDP},
+ {"TextChangedT", EVENT_TEXTCHANGEDT},
{"User", EVENT_USER},
{"VimEnter", EVENT_VIMENTER},
{"VimLeave", EVENT_VIMLEAVE},
diff --git a/src/terminal.c b/src/terminal.c
index ae532dc721..d9f1e0f821 100644
--- a/src/terminal.c
+++ b/src/terminal.c
@@ -1222,6 +1222,8 @@ update_cursor(term_T *term, int redraw)
setcursor();
if (redraw)
{
+ aco_save_T aco;
+
if (term->tl_buffer == curbuf && term->tl_cursor_visible)
cursor_on();
out_flush();
@@ -1232,6 +1234,16 @@ update_cursor(term_T *term, int redraw)
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;
}
}
diff --git a/src/testdir/test_terminal.vim b/src/testdir/test_terminal.vim
index 69faa3dfc4..d0ffe3bdbb 100644
--- a/src/testdir/test_terminal.vim
+++ b/src/testdir/test_terminal.vim
@@ -2321,5 +2321,54 @@ func Test_term_wait_in_close_cb()
bwipe!
endfunc
+func Test_term_TextChangedT()
+ augroup TermTest
+ autocmd TextChangedT * ++once
+ \ execute expand('<abuf>') . '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
diff --git a/src/version.c b/src/version.c
index a917dfdf2d..d987d915fc 100644
--- a/src/version.c
+++ b/src/version.c
@@ -696,6 +696,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 756,
+/**/
755,
/**/
754,
diff --git a/src/vim.h b/src/vim.h
index 57368f3b40..5d8c73848d 100644
--- a/src/vim.h
+++ b/src/vim.h
@@ -1394,6 +1394,7 @@ enum auto_event
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