Tony Mechelynck wrote:
> Unless you want to keep the result after displaying it, you
> could also use the VIM::message() function to display the
> message in Vim directly from Ruby.
Yes, I want to keep the result. And no, I don't really need to
display this result, at least in the "raw" form - the "echom" in
my simple example is just for convenience of testing. My real
goal is not to just print the message, but rather to post-process
it using existing set of VIML functions. Just to mention several
examples, some of those VIML functions are filling location list
of the current window with entries, extracted from the string,
returned by TestStringIf(). TestStringIf() is also invoked from
'completefunc' to get the information for the user-defined code
completion.
Generally speaking, TestStringIf() acts as a "protocol
implementation" for existing library of VIML functions.
So, my TestStringIf() must somehow takeover the string from the
ruby string variable and make it available in the VIML string
variable. What I don't like in my existing solution, that there
is potentially expensive processing of the string - decorate /
parse (I mean "decorate" is gsub(), "parse" is VIM::command("let
...")). Are there any way to avoid this "overhead" ? Something
like "raw assign VIML variable from the ruby variable" ?
> see ":help if_ruby.txt".
This I have already studied - ":help ruby" drops me on the same
page as ":help if_ruby.txt". Are there any other documents /
howto's for vim ruby integration ?
--
Anton.
2008/12/27, Tony Mechelynck <[email protected]>:
>
> On 27/12/08 22:38, Anton Sharonov wrote:
>> Hi, All,
>>
>> I have a following simple example, which illustrates my use case:
>>
>> function! TestStringIf()
>> ruby<< EOF
>> def bad_string()
>> return "'abc'" # can be very long string
>> end
>> # Is there any better way then gsub(...) ?
>> VIM::command("let result_viml = '" + bad_string().gsub("'", "''") +
>> "'")
>> EOF
>> return result_viml
>> endfunction
>> echom "result_viml is " . TestStringIf()
>>
>> In my real scenario bad_string() is ruby function which can
>> return arbitrary string, containing any bytes, excepting 0 (this
>> string is received over network from server). The length of the
>> string can be very big (I can imagine lengths of ~100 KB). I'm
>> new to both ruby and ruby's integration with VIM, therefore my
>> question: do I do it right way now - using gsub() to escape "'"
>> characters and VIM::command("let ...") to pass the string to VIML
>> variable? Are there better / more efficient ways of copying
>> string from ruby variable to the VIML variable ?
>>
>> --
>> Anton
>
> Unless you want to keep the result after displaying it, you could also
> use the VIM::message() function to display the message in Vim directly
> from Ruby.
>
> see ":help if_ruby.txt".
>
>
> Best regards,
> Tony.
> --
> [clop clop]
> MORTICIAN: Who's that then?
> CUSTOMER: I don't know.
> MORTICIAN: Must be a king.
> CUSTOMER: Why?
> MORTICIAN: He hasn't got shit all over him.
> The Quest for the Holy Grail (Monty
> Python)
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---