Tuesday, June 7, 2011

Re: How to get returned value from python functions in vim scripts ?

On 07/06/11 15:17, Marko Mahnič wrote:
> On 07. 06. 2011 15:13, Tony Mechelynck wrote:
>> On 07/06/11 14:56, Tony Mechelynck wrote:
>>> On 07/06/11 13:55, Marko Mahnič wrote:
>>>> On 07. 06. 2011 13:39, Tony Mechelynck wrote:
>>>>> On 07/06/11 09:31, Marko Mahnič wrote:
>>>>>> On Jun 7, 9:26 am, Marko Mahnič<marko.mah...@gmail.com> wrote:
>>>>>>> On Jun 7, 8:36 am, Ivan Krasilnikov<inf...@gmail.com> wrote:
>>>>>>>
>>>>>>> function s:MyCallback(param)
>>>>>>> " process
>>>>>>> endfunc
>>>>>>> python DoSomething(s:SNR . 'MyCallback', ...)
>>>>>>
>>>>>> This should probably be:
>>>>>> exec "python DoSomething(\"" . s:SNR . "MyCallback\", ...)"
>>>>>>
>>>>>> Marko
>>>>>>
>>>>>
>>>>> This last one cannot be right: as a minimum, it lacks a backslash left
>>>>> of "MyCallback".
>>>>>
>>>>
>>>> If you keep the quotes and backsalshes, but change the rest you can
>>>> write (
>>>> s:SNR -> getcwd(), MyCallback -> /. ) :
>>>>
>>>> :python import os
>>>> :exec "python print os.path.exists(\"" . getcwd() . "/.\")"
>>>>
>>>> which works for me (Vim 7.3). If getcwd() returns "/home/user", the
>>>> generated
>>>> Python statement is:
>>>>
>>>> print os.path.exists("/home/user/.")
>>>>
>>>> In the above case you would get the Python statement:
>>>>
>>>> DoSomething("32_MyCallback", ...)
>>>
>>> no, you would get:
>>> E???: invalid expression
>>> because
>>> >>> exec "python DoSomething(\"" . s:SNR . "MyCallback\", ...)"
>>> string ^---------------------------------^
>>> something Vim cannot understand ^--------...
>>
>> P.S. I think you should have written
>>
>> :exec 'python DoSomething("' . s:SNR . 'MyCallback", ...)'
>>
>
> This is equivalent to the above. Note that Vim treats "" and '' strings
> differently: single-quote strings are accepted as they are written while
> double-quote strings undergo some fancy parsing and escaping. The following
> strings are equivalent:
> "\""
> '"'

you forgot to backslash-escape the opening quote of "MyCallback". Third
edition. Are you blind or what? Or do you need some coffee?

>
> Marko
>

Best regards,
Tony.
--
"It was pleasant to me to get a letter from you the other day. Perhaps
I should have found it pleasanter if I had been able to decipher it. I
don't think that I mastered anything beyond the date (which I knew) and
the signature (which I guessed at). There's a singular and a perpetual
charm in a letter of yours; it never grows old, it never loses its
novelty .... Other letters are read and thrown away and forgotten, but
yours are kept forever -- unread. One of them will last a reasonable
man a lifetime."
-- Thomas Aldrich

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

No comments: