Patch 8.2.2128
Problem:    There is no way to do something on CTRL-Z.
Solution:   Add VimSuspend and VimResume autocommand events. (closes #7450)
Files:      runtime/doc/autocmd.txt, src/autocmd.c, src/ex_docmd.c,
            src/normal.c, src/testdir/test_suspend.vim, src/vim.h


*** ../vim-8.2.2127/runtime/doc/autocmd.txt     2020-11-30 17:40:41.299714396 
+0100
--- runtime/doc/autocmd.txt     2020-12-11 19:22:47.220290654 +0100
***************
*** 305,310 ****
--- 306,314 ----
  |VimLeavePre|         before exiting Vim, before writing the viminfo file
  |VimLeave|            before exiting Vim, after writing the viminfo file
  
+ |VimSuspend|          when suspending Vim
+ |VimResume|           when Vim is resumed after being suspended
+ 
        Terminal
  |TerminalOpen|                after a terminal buffer was created
  |TerminalWinOpen|     after a terminal buffer was created in a new window
***************
*** 1230,1235 ****
--- 1234,1250 ----
  VimResized                    After the Vim window was resized, thus 'lines'
                                and/or 'columns' changed.  Not when starting
                                up though.
+                                                       *VimResume*
+ VimResume                     When the Vim instance is resumed after being
+                               suspended and |VimSuspend| was triggered.
+                               Useful for triggering |:checktime| and ensure
+                               the buffers content did not change while Vim
+                               was suspended: >
+       :autocmd VimResume * checktime
+ <                                                     *VimSuspend*
+ VimSuspend                    When the Vim instance is suspended.  Only when
+                               CTRL-Z was typed inside Vim, not when the
+                               SIGSTOP or SIGTSTP signal was sent to Vim.
                                                        *WinEnter*
  WinEnter                      After entering another window.  Not done for
                                the first window, when Vim has just started.
*** ../vim-8.2.2127/src/autocmd.c       2020-11-07 16:58:55.894354883 +0100
--- src/autocmd.c       2020-12-11 19:18:10.762531473 +0100
***************
*** 191,196 ****
--- 191,198 ----
      {"WinLeave",      EVENT_WINLEAVE},
      {"VimResized",    EVENT_VIMRESIZED},
      {"TextYankPost",  EVENT_TEXTYANKPOST},
+     {"VimSuspend",    EVENT_VIMSUSPEND},
+     {"VimResume",     EVENT_VIMRESUME},
      {NULL,            (event_T)0}
  };
  
*** ../vim-8.2.2127/src/ex_docmd.c      2020-12-01 21:47:55.156840720 +0100
--- src/ex_docmd.c      2020-12-11 19:18:10.762531473 +0100
***************
*** 5864,5869 ****
--- 5864,5870 ----
      {
        if (!eap->forceit)
            autowrite_all();
+       apply_autocmds(EVENT_VIMSUSPEND, NULL, NULL, FALSE, NULL);
        windgoto((int)Rows - 1, 0);
        out_char('\n');
        out_flush();
***************
*** 5881,5886 ****
--- 5882,5888 ----
        scroll_start();         // scroll screen before redrawing
        redraw_later_clear();
        shell_resized();        // may have resized window
+       apply_autocmds(EVENT_VIMRESUME, NULL, NULL, FALSE, NULL);
      }
  }
  
*** ../vim-8.2.2127/src/normal.c        2020-12-03 19:54:38.181924268 +0100
--- src/normal.c        2020-12-11 19:17:34.546869308 +0100
***************
*** 5787,5793 ****
      clearop(cap->oap);
      if (VIsual_active)
        end_visual_mode();              // stop Visual mode
!     do_cmdline_cmd((char_u *)"st");
  }
  
  /*
--- 5787,5793 ----
      clearop(cap->oap);
      if (VIsual_active)
        end_visual_mode();              // stop Visual mode
!     do_cmdline_cmd((char_u *)"stop");
  }
  
  /*
*** ../vim-8.2.2127/src/testdir/test_suspend.vim        2020-08-12 
18:50:31.887655765 +0200
--- src/testdir/test_suspend.vim        2020-12-11 19:29:04.849861563 +0100
***************
*** 61,64 ****
--- 61,108 ----
    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
*** ../vim-8.2.2127/src/vim.h   2020-11-30 17:40:41.303714382 +0100
--- src/vim.h   2020-12-11 19:18:10.762531473 +0100
***************
*** 1344,1349 ****
--- 1344,1351 ----
      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
  };
*** ../vim-8.2.2127/src/version.c       2020-12-10 21:01:26.772252256 +0100
--- src/version.c       2020-12-11 19:19:45.693700314 +0100
***************
*** 752,753 ****
--- 752,755 ----
  {   /* Add new patch number below this line */
+ /**/
+     2128,
  /**/

-- 
ARTHUR: CHARGE!
   [The mighty ARMY charges.  Thundering noise of feet.  Clatter of coconuts.
   Shouts etc.   Suddenly there is a wail of a siren and a couple of police
   cars roar round in front of the charging ARMY and the POLICE leap out and
   stop them.  TWO POLICEMAN and the HISTORIAN'S WIFE.  Black Marias skid up
   behind them.]
HISTORIAN'S WIFE: They're the ones, I'm sure.
                 "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/202012111831.0BBIV46k2582255%40masaka.moolenaar.net.

Raspunde prin e-mail lui