On 23/03/29 5:42 PM, Tony Mechelynck wrote:
On Wed, Mar 29, 2023 at 9:58 PM Ernie Rael <err...@raelity.com> wrote:
[...]
The interesting thing is that if the vimscript
exits with an exception or :cquit, then after the bash shell
script exits, the return code is 1 (as hoped for), otherwise it
exits with 0. This seems to be undocumented behavior.
[...]
It is documented under ":help :cquit" — I looked for behaviour on :qa
with an uncaught exception but didn't find anything. Maybe that's what
":h v:exiting" covers.
Also, :cquit 5 or :5cquit makes Vim exit with return code 5 (or
similarly for other values). I think that in such a case the bash
script would exit with the return code of the last command it ran but
I'm not 100% sure (another possibility would be 1 for false, 0 for
true, nothing else).

Best regards,
Tony.

Thanks Tony,

Didn't know about v:exiting, and I think I've only used an autocmd
once (in an app I'm porting to vim9).

I'm getting good behavior. I generally want this stuff to run quietly,
and the most important thing is to have error information show up and
be able to detect problems from the exit status. When I first started
looking at this I think I confused myself by thinking that somehow
vim's "source" command was independent, something like unix fork().
Also when the sourced script got an exception, the "queued" commands
like "-c q" still got executed. After I cleared my head, there is only
one vim process in play (even if it's called "ex"), things make sense.

I've run into some quirky behavior, see below; but I have quirky
behavior; so so what. The first two are my typical use case. I tried a
few things with :cquit; in the 3rd example, somewhere it seems to be
adding one to the cquit argument if there's been an exception.

t.bash sets up things and does: =============================
ex -s \
    -c "redir >> /dev/stdout" \
    -c "source $vimscript" \
    -c "echo 'ex quitting'" \
    -c q
rc=$?
echo
exit $rc

-1- =========================================================
=== Started with 'ex -s -c "source $vimscript"' in t.bash ===
vim9script
autocmd VimLeave * echo "vim exiting:" v:exiting v:dying
echo 'DONE'
===== console =====
$ ./t.bash

DONE
ex quitting
vim exiting: 0 0
err@harmony:~/experiment/vim/vimprofiling
$ echo $?
0

-2- =========================================================
=== Started with 'ex -s -c "source $vimscript"' in t.bash ===
vim9script
autocmd VimLeave * echo "vim exiting:" v:exiting v:dying
throw "FORCE EXIT"
===== console =====
$ ./t.bash

Error detected while processing command line..script ...
line    4:
E605: Exception not caught: FORCE EXIT
ex quitting
vim exiting: 1 0
err@harmony:~/experiment/vim/vimprofiling
$ echo $?
1

-3- =========================================================
=== Started with 'ex -s -c "source $vimscript"' in t.bash ===
vim9script
autocmd VimLeave * echo "vim exiting:" v:exiting v:dying
autocmd VimLeave * cquit 7
throw "FORCE EXIT"
===== console =====
$ ./t.bash

Error detected while processing command line..script ...
line    4:
E605: Exception not caught: FORCE EXIT
ex quitting
vim exiting: 1 0
err@harmony:~/experiment/vim/vimprofiling
$ echo $?
8

--
--
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 vim_dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/eae44b94-d8dd-a713-42da-f819af730510%40raelity.com.

Raspunde prin e-mail lui