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

已查看 14 次
跳至第一个未读帖子

N i c o l a s

未读,
2023年1月11日 14:28:372023/1/11
收件人 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

未读,
2023年1月11日 14:58:042023/1/11
收件人 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

未读,
2023年1月11日 15:09:002023/1/11
收件人 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

未读,
2023年1月11日 15:17:582023/1/11
收件人 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

未读,
2023年1月11日 15:33:082023/1/11
收件人 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

未读,
2023年1月11日 15:50:372023/1/11
收件人 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

未读,
2023年1月12日 15:24:412023/1/12
收件人 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

未读,
2023年1月12日 16:49:582023/1/12
收件人 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
回复全部
回复作者
转发
0 个新帖子