Error in Ruby code embedded in vim9script

13 views
Skip to first unread message

Ni Va

unread,
Jun 2, 2021, 11:36:52 AM6/2/21
to vim_use
Hi all,

I got an error using Ruby code embedded in vim9script, seems something has changed in vim9script in this case. Like it understand $ as begin  of a range no ?

Thank you

Error detected while compiling command line..function readxml#mainruby[1]..<SNR>131_rubyCaller:
line    8:
E1050: Colon required before a range: $LOAD_PATH << Vim::evaluate('expand("$vim/extensions/ruby/lib/ruby/3.0.0")')


This is the code

vim9script
# MIT License. Copyright (c) 2021 June 02 Niva.

# Ruby code section
def readxml#mainruby()
  call s:rubyCaller() 
enddef
def s:rubyCaller()


ruby << EOF

# Core
$LOAD_PATH << Vim::evaluate('expand("$vim/extensions/ruby/lib/ruby/3.0.0")')

Bram Moolenaar

unread,
Jun 2, 2021, 1:23:30 PM6/2/21
to vim...@googlegroups.com, Ni Va
Your example looks like it's incomplete. Can you give a minimal example
that fails?

--
Citizens are not allowed to attend a movie house or theater nor ride in a
public streetcar within at least four hours after eating garlic.
[real standing law in Indiana, United States of America]

/// 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 ///

Ni Va

unread,
Jun 2, 2021, 1:37:49 PM6/2/21
to vim_use
Yes.

This is in my _vimrc
nnoremap <F6>            :exe '!start '.expand('$vimruntime/gvim.exe').' -c "call readxml\#mainruby()"'<cr>


Under this dir  vimfiles\plugged\readxml\autoload this code is in a script called readxml.vim
vim9script
# MIT License. Copyright (c) 2021 June 02 Niva.

# Ruby code section
def readxml#mainruby()
  call s:rubyCaller() 
enddef

def s:rubyCaller()


ruby << EOF

# Core
$LOAD_PATH << Vim::evaluate('expand("$vim/extensions/ruby/lib/ruby/3.0.0")')
EOF
enddef


Use Case : then I type <F6>

Thank you Bram.



Bram Moolenaar

unread,
Jun 3, 2021, 3:56:57 PM6/3/21
to vim...@googlegroups.com, Ni Va

Ni Va wrote:

> This is in my _vimrc
> nnoremap <F6> :exe '!start '.expand('$vimruntime/gvim.exe').' -c
> "call readxml\#mainruby()"'<cr>
>
>
> Under this dir vimfiles\plugged\readxml\autoload this code is in a script
> called readxml.vim
> vim9script
> # MIT License. Copyright (c) 2021 June 02 Niva.
>
> # Ruby code section
> def readxml#mainruby()
> call s:rubyCaller()
> enddef
>
> def s:rubyCaller()
>
> #https://ruby-doc.org/core-3.0.0/
> #http://www.ohler.com/ox/#label-Object+Dump+Sample-3A
>
> ruby << EOF
>
> # Core
> $LOAD_PATH << Vim::evaluate('expand("$vim/extensions/ruby/lib/ruby/3.0.0")')
> EOF
> enddef
>
>
> Use Case : then I type <F6>

OK, using "ruby << EOF", aka heredoc, in a :def function is not
supported yet. You can use a legacy function for now.

--
A programmer's wife asks him: "Please run to the store and pick up a loaf of
bread. If they have eggs, get a dozen". The programmer comes home with 12
loafs of bread.

Ni Va

unread,
Jun 4, 2021, 7:38:32 AM6/4/21
to vim_use
Ok, Can I code legacy function in a vim9script just for this case and keep all rest with def function ?

Thank you Bram

Reply all
Reply to author
Forward
0 new messages