Getting the Vim exit code value (v:exiting)

19 views
Skip to first unread message

Yegappan Lakshmanan

unread,
Nov 25, 2020, 3:39:40 PM11/25/20
to vim_dev
Hi all,

Neovim has support for getting the Vim exit code using the
v:exiting variable:


This is useful with the VimLeavePre and VimLeave autocommands.
Vim usually exits with exit code 0 or 1. But a user can use the ":cquit"
command to exit with different values. Should we port this to Vim?

Thanks,
Yegappan

Bram Moolenaar

unread,
Nov 25, 2020, 4:08:46 PM11/25/20
to vim...@googlegroups.com, Yegappan Lakshmanan
I suppose it could be useful for the autocommands.
The help isn't very clear about when the value is valid.
There are four autocommand events related to exiting.
How about "QuitPre" ?

Also, v:exiting suggests it's a flag about whether Vim will exit.
But the help says it's the exit value. Shouldn't it be v:exitvalue
then?

There are situations where Vim may exit, but it is cancelled (when using
a prompt or dialog). What happens then?

--
MORTICIAN: Bring out your dead!
[clang]
Bring out your dead!
[clang]
Bring out your dead!
CUSTOMER: Here's one -- nine pence.
DEAD PERSON: I'm not dead!
The Quest for the Holy Grail (Monty Python)

/// Bram Moolenaar -- Br...@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 ///

Yegappan Lakshmanan

unread,
Nov 25, 2020, 9:59:19 PM11/25/20
to Bram Moolenaar, vim_dev
Hi Bram,

On Wed, Nov 25, 2020 at 1:08 PM Bram Moolenaar <Br...@moolenaar.net> wrote:

Yegappan Lakshmanan wrote:

> Neovim has support for getting the Vim exit code using the
> v:exiting variable:
>
> https://github.com/neovim/neovim/pull/5651
>
> This is useful with the VimLeavePre and VimLeave autocommands.
> Vim usually exits with exit code 0 or 1. But a user can use the ":cquit"
> command to exit with different values. Should we port this to Vim?

I suppose it could be useful for the autocommands.
The help isn't very clear about when the value is valid.
There are four autocommand events related to exiting.
How about "QuitPre" ?

It looks like the v:exiting variable is set only for the VimLeavePre
and VimLeave autocmds. For the QuitPre and ExitPre autocmds,
the value is set to v:null.
 

Also, v:exiting suggests it's a flag about whether Vim will exit.
But the help says it's the exit value.  Shouldn't it be v:exitvalue
then?

I agree. It should be named as v:exitvalue or v:exitval. But then it
will be different from NeoVim and the plugin authors need to handle
the difference.
 

There are situations where Vim may exit, but it is cancelled (when using
a prompt or dialog).  What happens then?


In these cases, the VimLeavePre and VimLeave autocmds are not invoked.
The v:exiting value is set to a number only when the VimLeavePre and
VimLeave autocmds are invoked.

- Yegappan
 

Bram Moolenaar

unread,
Nov 26, 2020, 6:28:19 AM11/26/20
to vim...@googlegroups.com, Yegappan Lakshmanan
Would be good to add all this to the help.

I suppose there is no good reason to do this differently than neovim,
unless some have made remarks it's not good enough.

--
MORTICIAN: What?
CUSTOMER: Nothing -- here's your nine pence.
DEAD PERSON: I'm not dead!
MORTICIAN: Here -- he says he's not dead!
CUSTOMER: Yes, he is.
DEAD PERSON: I'm not!

Yegappan Lakshmanan

unread,
Nov 26, 2020, 4:42:15 PM11/26/20
to Bram Moolenaar, vim_dev
We can keep the same name (v:exiting). But one thing I noticed is the
type of this variable. Initially the type of the variable is "Special" and
the value is v:null. When exiting Vim, the type is changed to "Number"
and the value is an integer (exit code). Will changing the variable type
from Special to Number cause a problem?

- Yegappan

Bram Moolenaar

unread,
Nov 27, 2020, 5:23:31 AM11/27/20
to vim...@googlegroups.com, Yegappan Lakshmanan
Yeah, I don't like that very much. It's like a language where a number
is an Object, so it can be null to indicate it wasn't set. But in Vim
we have real numbers, so it doesn't fit well.

Using -1 for "not set" works better. But then it's different from
neovim...


--
[clop clop]
ARTHUR: Old woman!
DENNIS: Man!
ARTHUR: Man, sorry. What knight lives in that castle over there?
DENNIS: I'm thirty seven.
ARTHUR: What?
DENNIS: I'm thirty seven -- I'm not old!
Reply all
Reply to author
Forward
0 new messages