Add v:exiting

Contains the exit value nvim will use.

Before exiting, it is v:null. That way jobs or autocmds (in VimLeavePre or
VimLeave) can check if Neovim is about to quit and with what exit value.

Closes #4666.
This commit is contained in:
Marco Hinz 2016-11-22 14:53:07 +01:00
parent 5194e3bc45
commit 147b03e7d0
No known key found for this signature in database
GPG Key ID: 1C980A1B657B4A4F
4 changed files with 12 additions and 0 deletions

View File

@ -1383,6 +1383,9 @@ v:dying Normally zero. When a deadly signal is caught it's set to
< Note: if another deadly signal is caught when v:dying is one, < Note: if another deadly signal is caught when v:dying is one,
VimLeave autocommands will not be executed. VimLeave autocommands will not be executed.
*v:exiting* *exiting-variable*
v:exiting The exit value Nvim will use. Before exiting, it is |v:null|.
*v:errmsg* *errmsg-variable* *v:errmsg* *errmsg-variable*
v:errmsg Last given error message. It's allowed to set this variable. v:errmsg Last given error message. It's allowed to set this variable.
Example: > Example: >

View File

@ -394,6 +394,7 @@ static struct vimvar {
VV(VV_TYPE_DICT, "t_dict", VAR_NUMBER, VV_RO), VV(VV_TYPE_DICT, "t_dict", VAR_NUMBER, VV_RO),
VV(VV_TYPE_FLOAT, "t_float", VAR_NUMBER, VV_RO), VV(VV_TYPE_FLOAT, "t_float", VAR_NUMBER, VV_RO),
VV(VV_TYPE_BOOL, "t_bool", VAR_NUMBER, VV_RO), VV(VV_TYPE_BOOL, "t_bool", VAR_NUMBER, VV_RO),
VV(VV_EXITING, "exiting", VAR_NUMBER, VV_RO),
}; };
#undef VV #undef VV
@ -581,6 +582,7 @@ void eval_init(void)
set_vim_var_special(VV_FALSE, kSpecialVarFalse); set_vim_var_special(VV_FALSE, kSpecialVarFalse);
set_vim_var_special(VV_TRUE, kSpecialVarTrue); set_vim_var_special(VV_TRUE, kSpecialVarTrue);
set_vim_var_special(VV_NULL, kSpecialVarNull); set_vim_var_special(VV_NULL, kSpecialVarNull);
set_vim_var_special(VV_EXITING, kSpecialVarNull);
set_reg_var(0); // default for v:register is not 0 but '"' set_reg_var(0); // default for v:register is not 0 but '"'
} }
@ -17763,6 +17765,8 @@ void set_vcount(long count, long count1, int set_prevcount)
/// @param[in] val Value to set to. /// @param[in] val Value to set to.
void set_vim_var_nr(const VimVarIndex idx, const varnumber_T val) void set_vim_var_nr(const VimVarIndex idx, const varnumber_T val)
{ {
clear_tv(&vimvars[idx].vv_tv);
vimvars[idx].vv_type = VAR_NUMBER;
vimvars[idx].vv_nr = val; vimvars[idx].vv_nr = val;
} }
@ -17772,6 +17776,8 @@ void set_vim_var_nr(const VimVarIndex idx, const varnumber_T val)
/// @param[in] val Value to set to. /// @param[in] val Value to set to.
void set_vim_var_special(const VimVarIndex idx, const SpecialVarValue val) void set_vim_var_special(const VimVarIndex idx, const SpecialVarValue val)
{ {
clear_tv(&vimvars[idx].vv_tv);
vimvars[idx].vv_type = VAR_SPECIAL;
vimvars[idx].vv_special = val; vimvars[idx].vv_special = val;
} }

View File

@ -134,6 +134,7 @@ typedef enum {
VV_TYPE_DICT, VV_TYPE_DICT,
VV_TYPE_FLOAT, VV_TYPE_FLOAT,
VV_TYPE_BOOL, VV_TYPE_BOOL,
VV_EXITING,
} VimVarIndex; } VimVarIndex;
/// All recognized msgpack types /// All recognized msgpack types

View File

@ -557,6 +557,8 @@ void getout(int exitval)
if (exmode_active) if (exmode_active)
exitval += ex_exitval; exitval += ex_exitval;
set_vim_var_nr(VV_EXITING, exitval);
/* Position the cursor on the last screen line, below all the text */ /* Position the cursor on the last screen line, below all the text */
ui_cursor_goto((int)Rows - 1, 0); ui_cursor_goto((int)Rows - 1, 0);