To: vim_dev@googlegroups.com Subject: Patch 8.2.2070 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.2070 Problem: Can't get the exit value in VimLeave or VimLeavePre autocommands. Solution: Add v:exiting like in Neovim. (Yegappan Lakshmanan, closes #7395) Files: runtime/doc/autocmd.txt, runtime/doc/eval.txt, src/evalvars.c, src/main.c, src/testdir/test_exit.vim, src/vim.h *** ../vim-8.2.2069/runtime/doc/autocmd.txt 2020-11-12 14:20:32.013927316 +0100 --- runtime/doc/autocmd.txt 2020-11-30 17:29:26.066185245 +0100 *************** *** 70,75 **** --- 70,79 ---- The special pattern or defines a buffer-local autocommand. See |autocmd-buflocal|. + If the `:autocmd` is in Vim9 script then {cmd} will be executed as in Vim9 + script. Thus this depends on where the autocmd is defined, not where it is + triggered. + Note: The ":autocmd" command can only be followed by another command when the '|' appears before {cmd}. This works: > :augroup mine | au! BufRead | augroup END *************** *** 1210,1215 **** --- 1214,1220 ---- To detect an abnormal exit use |v:dying|. When v:dying is 2 or more this event is not triggered. + To get the exit code use |v:exiting|. *VimLeavePre* VimLeavePre Before exiting Vim, just before writing the .viminfo file. This is executed only once, *************** *** 1220,1225 **** --- 1225,1231 ---- < To detect an abnormal exit use |v:dying|. When v:dying is 2 or more this event is not triggered. + To get the exit code use |v:exiting|. *VimResized* VimResized After the Vim window was resized, thus 'lines' and/or 'columns' changed. Not when starting *** ../vim-8.2.2069/runtime/doc/eval.txt 2020-11-12 14:20:32.017927303 +0100 --- runtime/doc/eval.txt 2020-11-30 17:33:51.853221159 +0100 *************** *** 1822,1827 **** --- 1850,1862 ---- < Note: if another deadly signal is caught when v:dying is one, VimLeave autocommands will not be executed. + *v:exiting* *exiting-variable* + v:exiting Vim exit code. Normally zero, non-zero when something went + wrong. The value is v:null before invoking the |VimLeavePre| + and |VimLeave| autocmds. See |:q|, |:x| and |:cquit|. + Example: > + :au VimLeave * echo "Exit value is " .. v:exiting + < *v:echospace* *echospace-variable* v:echospace Number of screen cells that can be used for an `:echo` message in the last screen line before causing the |hit-enter-prompt|. *** ../vim-8.2.2069/src/evalvars.c 2020-11-19 21:47:52.722076508 +0100 --- src/evalvars.c 2020-11-30 17:29:26.070185231 +0100 *************** *** 146,151 **** --- 146,152 ---- {VV_NAME("echospace", VAR_NUMBER), VV_RO}, {VV_NAME("argv", VAR_LIST), VV_RO}, {VV_NAME("collate", VAR_STRING), VV_RO}, + {VV_NAME("exiting", VAR_SPECIAL), VV_RO}, }; // shorthand *************** *** 218,223 **** --- 219,225 ---- set_vim_var_nr(VV_SEARCHFORWARD, 1L); set_vim_var_nr(VV_HLSEARCH, 1L); + set_vim_var_nr(VV_EXITING, VVAL_NULL); set_vim_var_dict(VV_COMPLETED_ITEM, dict_alloc_lock(VAR_FIXED)); set_vim_var_list(VV_ERRORS, list_alloc()); set_vim_var_dict(VV_EVENT, dict_alloc_lock(VAR_FIXED)); *** ../vim-8.2.2069/src/main.c 2020-11-27 19:01:25.872894362 +0100 --- src/main.c 2020-11-30 17:34:56.700983817 +0100 *************** *** 1505,1511 **** /* ! * Exit properly. */ void getout(int exitval) --- 1505,1512 ---- /* ! * Exit properly. This is the only way to exit Vim after startup has ! * succeeded. We are certain to exit here, no way to abort it. */ void getout(int exitval) *************** *** 1521,1526 **** --- 1522,1532 ---- if (exmode_active) exitval += ex_exitval; + #ifdef FEAT_EVAL + set_vim_var_type(VV_EXITING, VAR_NUMBER); + set_vim_var_nr(VV_EXITING, exitval); + #endif + // Position the cursor on the last screen line, below all the text #ifdef FEAT_GUI if (!gui.in_use) *** ../vim-8.2.2069/src/testdir/test_exit.vim 2020-08-12 18:50:31.875655822 +0200 --- src/testdir/test_exit.vim 2020-11-30 17:29:26.070185231 +0100 *************** *** 82,85 **** --- 82,112 ---- call delete('Xtestout') endfunc + " Test for getting the Vim exit code from v:exiting + func Test_exit_code() + call assert_equal(v:null, v:exiting) + + let before =<< trim [CODE] + au QuitPre * call writefile(['qp = ' .. v:exiting], 'Xtestout', 'a') + au ExitPre * call writefile(['ep = ' .. v:exiting], 'Xtestout', 'a') + au VimLeavePre * call writefile(['lp = ' .. v:exiting], 'Xtestout', 'a') + au VimLeave * call writefile(['l = ' .. v:exiting], 'Xtestout', 'a') + [CODE] + + if RunVim(before, ['quit'], '') + call assert_equal(['qp = v:null', 'ep = v:null', 'lp = 0', 'l = 0'], readfile('Xtestout')) + endif + call delete('Xtestout') + + if RunVim(before, ['cquit'], '') + call assert_equal(['lp = 1', 'l = 1'], readfile('Xtestout')) + endif + call delete('Xtestout') + + if RunVim(before, ['cquit 4'], '') + call assert_equal(['lp = 4', 'l = 4'], readfile('Xtestout')) + endif + call delete('Xtestout') + endfunc + " vim: shiftwidth=2 sts=2 expandtab *** ../vim-8.2.2069/src/vim.h 2020-11-25 20:09:05.509445589 +0100 --- src/vim.h 2020-11-30 17:29:26.074185217 +0100 *************** *** 1996,2002 **** #define VV_ECHOSPACE 93 #define VV_ARGV 94 #define VV_COLLATE 95 ! #define VV_LEN 96 // number of v: vars // used for v_number in VAR_BOOL and VAR_SPECIAL #define VVAL_FALSE 0L // VAR_BOOL --- 1996,2003 ---- #define VV_ECHOSPACE 93 #define VV_ARGV 94 #define VV_COLLATE 95 ! #define VV_EXITING 96 ! #define VV_LEN 97 // number of v: vars // used for v_number in VAR_BOOL and VAR_SPECIAL #define VVAL_FALSE 0L // VAR_BOOL *** ../vim-8.2.2069/src/version.c 2020-11-29 14:20:23.677476671 +0100 --- src/version.c 2020-11-30 17:38:49.732126713 +0100 *************** *** 752,753 **** --- 752,755 ---- { /* Add new patch number below this line */ + /**/ + 2070, /**/ -- Windows M!uqoms /// Bram Moolenaar -- Bram@Moolenaar.net -- 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 ///