patch 8.2.2128: there is no way to do something on CTRL-Z
Problem: There is no way to do something on CTRL-Z.
Solution: Add VimSuspend and VimResume autocommand events. (closes #7450)
diff --git a/src/autocmd.c b/src/autocmd.c
index a82659f..c3aa324 100644
--- a/src/autocmd.c
+++ b/src/autocmd.c
@@ -191,6 +191,8 @@
{"WinLeave", EVENT_WINLEAVE},
{"VimResized", EVENT_VIMRESIZED},
{"TextYankPost", EVENT_TEXTYANKPOST},
+ {"VimSuspend", EVENT_VIMSUSPEND},
+ {"VimResume", EVENT_VIMRESUME},
{NULL, (event_T)0}
};
diff --git a/src/ex_docmd.c b/src/ex_docmd.c
index 11e4bf5..0788fa3 100644
--- a/src/ex_docmd.c
+++ b/src/ex_docmd.c
@@ -5864,6 +5864,7 @@
{
if (!eap->forceit)
autowrite_all();
+ apply_autocmds(EVENT_VIMSUSPEND, NULL, NULL, FALSE, NULL);
windgoto((int)Rows - 1, 0);
out_char('\n');
out_flush();
@@ -5881,6 +5882,7 @@
scroll_start(); // scroll screen before redrawing
redraw_later_clear();
shell_resized(); // may have resized window
+ apply_autocmds(EVENT_VIMRESUME, NULL, NULL, FALSE, NULL);
}
}
diff --git a/src/normal.c b/src/normal.c
index da0ffc1..8dca538 100644
--- a/src/normal.c
+++ b/src/normal.c
@@ -5787,7 +5787,7 @@
clearop(cap->oap);
if (VIsual_active)
end_visual_mode(); // stop Visual mode
- do_cmdline_cmd((char_u *)"st");
+ do_cmdline_cmd((char_u *)"stop");
}
/*
diff --git a/src/testdir/test_suspend.vim b/src/testdir/test_suspend.vim
index bf3f93a..327fe06 100644
--- a/src/testdir/test_suspend.vim
+++ b/src/testdir/test_suspend.vim
@@ -61,4 +61,48 @@
call delete('Xfoo')
endfunc
+func Test_suspend_autocmd()
+ CheckFeature terminal
+ CheckExecutable /bin/sh
+
+ let buf = term_start('/bin/sh', #{term_rows: 6})
+ " Wait for shell prompt.
+ call WaitForAssert({-> assert_match('[$#] $', term_getline(buf, '.'))})
+
+ call term_sendkeys(buf, v:progpath
+ \ . " --clean -X"
+ \ . " -c 'set nu'"
+ \ . " -c 'let g:count = 0'"
+ \ . " -c 'au VimSuspend * let g:count += 1'"
+ \ . " -c 'au VimResume * let g:count += 1'"
+ \ . " -c 'call setline(1, \"foo\")'"
+ \ . " Xfoo\<CR>")
+ " Cursor in terminal buffer should be on first line in spawned vim.
+ call WaitForAssert({-> assert_equal(' 1 foo', term_getline(buf, '.'))})
+
+ for suspend_cmd in [":suspend\<CR>",
+ \ ":stop\<CR>",
+ \ ":suspend!\<CR>",
+ \ ":stop!\<CR>",
+ \ "\<C-Z>"]
+ " Suspend and wait for shell prompt. Then "fg" will restore Vim.
+ call term_sendkeys(buf, suspend_cmd)
+ call CheckSuspended(buf, 0)
+ endfor
+
+ call term_sendkeys(buf, ":echo g:count\<CR>")
+ call TermWait(buf)
+ call WaitForAssert({-> assert_match('^10', term_getline(buf, 6))})
+
+ " Quit gracefully to dump coverage information.
+ call term_sendkeys(buf, ":qall!\<CR>")
+ call TermWait(buf)
+ " Wait until Vim actually exited and shell shows a prompt
+ call WaitForAssert({-> assert_match('[$#] $', term_getline(buf, '.'))})
+ call StopShellInTerminal(buf)
+
+ exe buf . 'bwipe!'
+ call delete('Xfoo')
+endfunc
+
" vim: shiftwidth=2 sts=2 expandtab
diff --git a/src/version.c b/src/version.c
index 1a534ee..24a8390 100644
--- a/src/version.c
+++ b/src/version.c
@@ -751,6 +751,8 @@
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 2128,
+/**/
2127,
/**/
2126,
diff --git a/src/vim.h b/src/vim.h
index eda0734..d6c1f46 100644
--- a/src/vim.h
+++ b/src/vim.h
@@ -1344,6 +1344,8 @@
EVENT_WINENTER, // after entering a window
EVENT_WINLEAVE, // before leaving a window
EVENT_WINNEW, // when entering a new window
+ EVENT_VIMSUSPEND, // before Vim is suspended
+ EVENT_VIMRESUME, // after Vim is resumed
NUM_EVENTS // MUST be the last one
};