vim-patch:9.2.0267: 'autowrite' not triggered for :term

Problem:  'autowrite' not triggered for :term
Solution: Trigger autowrite for :term command
          (rendcrx)

closes: vim/vim#19855

466b5f531a

Co-authored-by: rendcrx <974449413@qq.com>
This commit is contained in:
zeertzjq
2026-03-30 13:27:56 +08:00
parent b346b87fb2
commit 76a917a81e
5 changed files with 19 additions and 3 deletions

View File

@@ -823,7 +823,7 @@ A jump table for the options with a short description can be found at |Q_op|.
global
Write the contents of the file, if it has been modified, on each
`:next`, `:rewind`, `:last`, `:first`, `:previous`, `:stop`,
`:suspend`, `:tag`, `:!`, `:make`, CTRL-] and CTRL-^ command; and when
`:suspend`, `:tag`, `:!`, `:make`, `:terminal`, CTRL-] and CTRL-^ command; and when
a `:buffer`, CTRL-O, CTRL-I, '{A-Z0-9}, or `{A-Z0-9} command takes one
to another file.
A buffer is not written if it becomes hidden, e.g. when 'bufhidden' is

View File

@@ -190,7 +190,7 @@ vim.go.ar = vim.go.autoread
--- Write the contents of the file, if it has been modified, on each
--- `:next`, `:rewind`, `:last`, `:first`, `:previous`, `:stop`,
--- `:suspend`, `:tag`, `:!`, `:make`, CTRL-] and CTRL-^ command; and when
--- `:suspend`, `:tag`, `:!`, `:make`, `:terminal`, CTRL-] and CTRL-^ command; and when
--- a `:buffer`, CTRL-O, CTRL-I, '{A-Z0-9}, or `{A-Z0-9} command takes one
--- to another file.
--- A buffer is not written if it becomes hidden, e.g. when 'bufhidden' is

View File

@@ -8197,6 +8197,11 @@ static void ex_terminal(exarg_T *eap)
{
char ex_cmd[1024];
size_t len = 0;
const int scroll_save = msg_scroll;
msg_scroll = false; // don't scroll here
autowrite_all();
msg_scroll = scroll_save;
if (cmdmod.cmod_tab > 0 || cmdmod.cmod_split != 0) {
bool multi_mods = false;

View File

@@ -324,7 +324,7 @@ local options = {
desc = [=[
Write the contents of the file, if it has been modified, on each
`:next`, `:rewind`, `:last`, `:first`, `:previous`, `:stop`,
`:suspend`, `:tag`, `:!`, `:make`, CTRL-] and CTRL-^ command; and when
`:suspend`, `:tag`, `:!`, `:make`, `:terminal`, CTRL-] and CTRL-^ command; and when
a `:buffer`, CTRL-O, CTRL-I, '{A-Z0-9}, or `{A-Z0-9} command takes one
to another file.
A buffer is not written if it becomes hidden, e.g. when 'bufhidden' is

View File

@@ -106,6 +106,17 @@ describe(':terminal', function()
eq(3, #jumps)
end)
it("triggers 'autowrite'", function()
api.nvim_set_option_value('autowrite', true, {})
command('vnew Xtermautowritetestfile | setlocal fileformat=unix')
finally(function()
os.remove('Xtermautowritetestfile')
end)
fn.setline(1, 'test content')
command('terminal')
eq('test content\n', t.read_file('Xtermautowritetestfile'))
end)
it('nvim_get_mode() in :terminal', function()
command('terminal')
eq({ blocking = false, mode = 'nt' }, api.nvim_get_mode())