vim9 autoload script modified : How to reload it On-The-Fly

14 views
Skip to first unread message

N i c o l a s

unread,
Jan 11, 2023, 2:28:37 PM1/11/23
to vim_use
Hi,

Currently modifying an autoload/vim9fooscript.vim which can be started by typing a nnoremap as this :

  • _vimrc :
import autoload './vimfiles/some/thing/autoload/vim9fooscript  .vim'
as thatHelp
nnoremap inout <ScriptCmd> thatHelp.E10_InOut()<CR>


  • vimfiles/some/thing/autoload/vim9fooscript.vim  
            def Foo which is currently modifying


How to force "recompile" the new modified content of def Foo without touch the nnoremap ?

Thank you
N i  c  o l a s

Lifepillar

unread,
Jan 11, 2023, 2:58:04 PM1/11/23
to vim...@googlegroups.com
On 2023-01-11, N i c o l a s <niva...@gmail.com> wrote:
> Hi,
>
> Currently modifying an *autoload*/*vim9fooscript*.vim which can be started
> by typing a nnoremap as this :
>
>
> - *_vimrc* :
>
> import autoload './vimfiles/some/thing/*autoload*/*vim9fooscript* .vim'
> as thatHelp
> *nnoremap* inout <ScriptCmd> thatHelp.E10_InOut()<CR>
>
>
>
> - vimfiles/some/thing/*autoload*/*vim9fooscript*.vim
>
> def Foo which is currently modifying
>
>
> How to force "recompile" the new modified content of def Foo without touch
> the nnoremap ?

Sourcing the autoload script should clear the old definitions and
compile the new ones. See :help vim9-reload.

Hope this helps,
Life.

Bram Moolenaar

unread,
Jan 11, 2023, 3:09:00 PM1/11/23
to vim...@googlegroups.com, N i c o l a s

> Currently modifying an *autoload*/*vim9fooscript*.vim which can be started
> by typing a nnoremap as this :
>
>
> - *_vimrc* :
>
> import autoload './vimfiles/some/thing/*autoload*/*vim9fooscript* .vim'
> as thatHelp
> *nnoremap* inout <ScriptCmd> thatHelp.E10_InOut()<CR>
>
>
>
> - vimfiles/some/thing/*autoload*/*vim9fooscript*.vim
>
> def Foo which is currently modifying
>
>
> How to force "recompile" the new modified content of def Foo without touch
> the nnoremap ?

There is no reliable way to reload an autoload script and have all the
changes take effect. It's best to exit Vim and restart. Trying to make
this work without a Vim restart is not only complicated, it is also
going to be unreliable.

--
An alien life briefly visits earth. Just before departing it leaves a
message in the dust on the back of a white van. The world is shocked
and wants to know what it means. After months of studies the worlds
best linguistic scientists are able to decipher the message: "Wash me!".

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///

N i c o l a s

unread,
Jan 11, 2023, 3:17:58 PM1/11/23
to vim_use


Ok Bram that what I do each time I modify an autoload vim9script (so I do the best I can :)
effectively, sourcing does not work sorry lifepillar: it echoes to me a message E1091 Function HighCaller (below) is not compiled.

And the calling tree is as this :
nnoremap foo <ScriptCmd> Helper. HighCaller  ()<CR> ->  autoload/vim9fooscript.vim :: exported def HighCaller() ->  autoload/vim9fooscript.vim :: def SubCalled

So it seems to be  needed to add a mapping to launch gvim -c with the command test I need.
Thank you
Nicolas


Lifepillar

unread,
Jan 11, 2023, 3:33:08 PM1/11/23
to vim...@googlegroups.com
On 2023-01-11, N i c o l a s <niva...@gmail.com> wrote:
>
> effectively, sourcing does not work sorry lifepillar: it echoes to me a
> message E1091 Function HighCaller (below) is not compiled.
>
> And the calling tree is as this :
> nnoremap *foo *<ScriptCmd> Helper. *HighCaller* ()<CR> ->
> autoload/vim9fooscript.vim :: *exported *def *HighCaller() *->
> autoload/vim9fooscript.vim :: def *SubCalled*

There may be something else going on in your script, possibly a syntax
error in some function. This trivial example works for me:

~/.vim/autoload/vim9fooscript.vim

vim9script

export def HighCaller()
SubCalled()
enddef

def SubCalled()
echo 'I was called!'
enddef

~/.vim/vimrc

import autoload "vim9fooscript.vim" as Helper
nnoremap gG <Scriptcmd> Helper.HighCaller()<cr>

When I start Vim and type gG, Vim echoes 'I was called!'. If I then
change the echo message to something else, save the script and then
:source ~/.vim/autoload/vim9fooscript.vim, I get no errors and gG prints
the updated message.

Life.

N i c o l a s

unread,
Jan 11, 2023, 3:50:37 PM1/11/23
to vim_use
Hum, thanks a lot Life, after one more check:

./vimfiles/plugged/foo-helper.vim/autoload/vim9fooscript.vim

vim9script

# some many defs func

export def  High_Caller(): void
   Sub_Called(4)
enddef  

def  Sub_Called(code: number ): void
  # some job
enddef  


~/_vimc
import autoload './vimfiles/plugged/foo-helper.vim/autoload/vim9fooscript.vim' as Helper
nnoremap io <Scriptcmd>  Helper.High_Caller()<cr>


typing io it echoes  E1091: Function is not compiled:  vim9fooscript#High_Caller


Does foo-helper.vim directory must match vim9fooscript ?

Lifepillar

unread,
Jan 12, 2023, 3:24:41 PM1/12/23
to vim...@googlegroups.com
On 2023-01-11, N i c o l a s <niva...@gmail.com> wrote:
> Hum, thanks a lot Life, after one more check:
>
> *./vimfiles/plugged/foo-helper.vim/autoload/vim9fooscript.vim*
>
> vim9script
>
> *# some many defs func*
>
> export def *High_Caller*(): void
> Sub_Called(4)
> enddef
>
> def Sub_Called(code: number ): void
> *# some job*
> enddef
>
>
> *~/_vimc*
> import autoload './vimfiles/*plugged*/foo-helper.vim/autoload/
> *vim9fooscript*.vim' as *Helper*
> nnoremap io <Scriptcmd> *Helper*.High_Caller()<cr>
>
>
> typing io it echoes E1091: Function is not compiled: *vim9fooscript*#
> *High_Caller*

I'd start by removing the "many function defs", and possibly simplifying
the body fo Sub_Called(), and see if I can source without error. Then,
I would start to gradually re-add the removed material until I find what
is causing the error.

Hope this helps,
Life.

N i c o l a s

unread,
Jan 12, 2023, 4:49:58 PM1/12/23
to vim_use
Found and sorry.

vim9script

if exists("g:did_load_helper")
  finish    
endif
g:did_load_helper = 1


I thought in the help for vim9 same mecanism to prevent loading script can be applied. Maybe a mistake of reading from me.

Thank you Life
Nicolas
Reply all
Reply to author
Forward
0 new messages