summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2020-11-30 17:42:10 +0100
committerBram Moolenaar <Bram@vim.org>2020-11-30 17:42:10 +0100
commitf0068c5154a99b86b2c4515a4b93c003b2445cf4 (patch)
tree18198d6cb57c407acaddf8c7ed8b62a41fed2805 /src
parent23515b4ef7580af8b9d3b964a558ab2007cacda5 (diff)
downloadvim-git-f0068c5154a99b86b2c4515a4b93c003b2445cf4.tar.gz
patch 8.2.2070: can't get the exit value in VimLeave(Pre) autocommandsv8.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)
Diffstat (limited to 'src')
-rw-r--r--src/evalvars.c2
-rw-r--r--src/main.c8
-rw-r--r--src/testdir/test_exit.vim27
-rw-r--r--src/version.c2
-rw-r--r--src/vim.h3
5 files changed, 40 insertions, 2 deletions
diff --git a/src/evalvars.c b/src/evalvars.c
index 75893bb27..dea56be75 100644
--- a/src/evalvars.c
+++ b/src/evalvars.c
@@ -146,6 +146,7 @@ static struct vimvar
{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,6 +219,7 @@ evalvars_init(void)
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));
diff --git a/src/main.c b/src/main.c
index e3ce9e4a6..1b7811a67 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1505,7 +1505,8 @@ getout_preserve_modified(int exitval)
/*
- * Exit properly.
+ * 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,6 +1522,11 @@ getout(int exitval)
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)
diff --git a/src/testdir/test_exit.vim b/src/testdir/test_exit.vim
index 2b29c3766..93b8f5171 100644
--- a/src/testdir/test_exit.vim
+++ b/src/testdir/test_exit.vim
@@ -82,4 +82,31 @@ func Test_exiting()
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
diff --git a/src/version.c b/src/version.c
index 6e9dfbcd9..4eb7f4b59 100644
--- a/src/version.c
+++ b/src/version.c
@@ -751,6 +751,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 2070,
+/**/
2069,
/**/
2068,
diff --git a/src/vim.h b/src/vim.h
index 6dcc509aa..eda07348c 100644
--- a/src/vim.h
+++ b/src/vim.h
@@ -1996,7 +1996,8 @@ typedef int sock_T;
#define VV_ECHOSPACE 93
#define VV_ARGV 94
#define VV_COLLATE 95
-#define VV_LEN 96 // number of v: vars
+#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