Re: using vim to run vim9script

2023-03-30 Fir de Conversatie Ernie Rael

On 23/03/29 5:42 PM, Tony Mechelynck wrote:

On Wed, Mar 29, 2023 at 9:58 PM Ernie Rael  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.


Re: using vim to run vim9script

2023-03-29 Fir de Conversatie Tony Mechelynck
On Wed, Mar 29, 2023 at 9:58 PM Ernie Rael  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.

-- 
-- 
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/CAJkCKXuauRJ6o_i7AswemJ%3D%2B0JLV4atC8AmYM6%2BWonOxr4wC3g%40mail.gmail.com.


Re: using vim to run vim9script

2023-03-29 Fir de Conversatie Ernie Rael

Wrapping the invocation of "ex -s ..." seems to work pretty well;
args can be processed by the wrapper script, passed to vim as globals.

In the following test, note the final "-c q", it is needed to prevent
vim waiting in exmode. 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.

The only weirdness is that the last echo of the vimscript
does not have a trailing newline, but that's remedied
with an echo in the bash script.

   ex -s -c "$arg" \
    -c "redir >> /dev/stdout" \
    -c "source $vimscript" \
    -c q
   echo

-ernie



On 23/03/28 12:15 PM, Ernie Rael wrote:


I want to run some vim stuff from a shell script.

Some issues I can think of

  * passing arguments to vim
  * don't draw a screen
  * seeing output
  * seeing errors

The following more or less works; it would be nice
if vim, on an error, automatically exited with an error;
"echo g:what" in this case.

Looking for suggestions and/or alternatives and/or doc ref?

Thanks,
-ernie

Doing:

ex -s -c 'let g:arg = 123' -c 'redir >> /dev/stdout' -c 'source t.vim'

where t.vim is

vim9script
echo g:arg
echo 'foo'
echo g:what
echo "\n"
q

produces the output

123
foo
Error detected while processing command line..script /.../t.vim:
line    4:
E121: Undefined variable: g:what
Entering Ex mode.  Type "visual" to go to Normal mode.



--
--
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/6443a0af-f327-43ec-b6ee-49f855466fe7%40raelity.com 
.


--
--
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/7f360287-0059-dfe3-ed6f-3f17967e37de%40raelity.com.


using vim to run vim9script

2023-03-28 Fir de Conversatie Ernie Rael

I want to run some vim stuff from a shell script.

Some issues I can think of

 * passing arguments to vim
 * don't draw a screen
 * seeing output
 * seeing errors

The following more or less works; it would be nice
if vim, on an error, automatically exited with an error;
"echo g:what" in this case.

Looking for suggestions and/or alternatives and/or doc ref?

Thanks,
-ernie

Doing:

   ex -s -c 'let g:arg = 123' -c 'redir >> /dev/stdout' -c 'source t.vim'

where t.vim is

   vim9script
   echo g:arg
   echo 'foo'
   echo g:what
   echo "\n"
   q

produces the output

   123
   foo
   Error detected while processing command line..script /.../t.vim:
   line    4:
   E121: Undefined variable: g:what
   Entering Ex mode.  Type "visual" to go to Normal mode.


--
--
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/6443a0af-f327-43ec-b6ee-49f855466fe7%40raelity.com.