Marc Weber wrote:
Imagine having the files:
------ >8 ------ >8 autoload/test.vim ----- >8 ------ >8 ------ >8
function test#DoTest(a)
if a == 1
call s:F1()
else
call s:F2()
endif
endfunction
function test#Test()
echo "test#Test()"
endfunction
let s:F1=function('test#Test')
let s:F2=function('test2#Test')
------ 8< ------ 8< ------ 8< ------ 8< ------ 8< ------ 8< ------ 8<
------ >8 ------ >8 autoload/test2.vim ----- >8 ------ >8 ------ >8
function test2#Test()
echo "test2#Test()"
endfunction
------ 8< ------ 8< ------ 8< ------ 8< ------ 8< ------ 8< ------ 8<
calling test#DoTest(2) doesn't work because vim doesn't know the
function yet. I can solve this using my custom function Function:
function! Function(name)
<find autoloadfile containing a:name>
exec 'source '.autoloadfile
return function(a:name)
endfunction
calling test#DoTest(1) doesn't work because test#Test isn't known by vim
when sourcing the file. Is the only option moving the function
test#Test() into another file?
Marc
If the autoload directory doesn't work, maybe you can use the FuncUndefined
autocommand event? Or else, maybe using function() for an autoload#function()
requires prior sourcing of the appropriate autoload script?
See
:help autoload-functions
:help autoload
:help Funcref
Best regards,
Tony.