From 4fd876271a8bc3349fccb14d2e0203af1f9e6698 Mon Sep 17 00:00:00 2001 From: Shougo Date: Mon, 7 Nov 2022 12:02:29 +0900 Subject: vim-patch:9.0.0756 #20680 Problem: No autocmd event for changing text in a terminal window. Solution: Add TextChangedT. (Shougo Matsushita, closes vim/vim#11366) https://github.com/vim/vim/commit/4ccaedfcd7526983f4b6b3b06b0bfb54f333f1f3 --- src/nvim/auevents.lua | 1 + src/nvim/terminal.c | 12 ++++++++++++ 2 files changed, 13 insertions(+) (limited to 'src/nvim') diff --git a/src/nvim/auevents.lua b/src/nvim/auevents.lua index 93a870fe04..65c22c922a 100644 --- a/src/nvim/auevents.lua +++ b/src/nvim/auevents.lua @@ -108,6 +108,7 @@ return { 'TextChanged', -- text was modified 'TextChangedI', -- text was modified in Insert mode(no popup) 'TextChangedP', -- text was modified in Insert mode(popup) + 'TextChangedT', -- text was modified in Terminal mode 'TextYankPost', -- after a yank or delete was done (y, d, c) 'UIEnter', -- after UI attaches 'UILeave', -- after UI detaches diff --git a/src/nvim/terminal.c b/src/nvim/terminal.c index 5e221e13df..890b04a614 100644 --- a/src/nvim/terminal.c +++ b/src/nvim/terminal.c @@ -523,6 +523,18 @@ static int terminal_check(VimState *state) if (must_redraw) { update_screen(); + + // Make sure an invoked autocmd doesn't delete the buffer (and the + // terminal) under our fingers. + curbuf->b_locked++; + + // save and restore curwin and curbuf, in case the autocmd changes them + aco_save_T aco; + aucmd_prepbuf(&aco, curbuf); + apply_autocmds(EVENT_TEXTCHANGEDT, NULL, NULL, false, curbuf); + aucmd_restbuf(&aco); + + curbuf->b_locked--; } if (need_maketitle) { // Update title in terminal-mode. #7248 -- cgit