On 5/24/06, Mohsin <[EMAIL PROTECTED]> wrote:
I am trying to use the  ':py' interface to evaluate text under cursor and show
the result in a balloon text.  I got the python and vim code to work easily,
however I have problem communicating between the two (py and vim):

1. How do I access vim variables in py commands
   (like text under cursor, all the 'let variables', 'set options')?
This is easy, see below

2. In the Balloon vim function, how do I access py variables.
    Note that I am not  happy with just printing the py result on the
message line -
    I want the py output (ot data structures
    in a vim variable to display it in a balloon.
Note that :py commands are not available in the sandbox.
I dont know whether Balloon function is executed in the
sandbox. Maybe it is not (then :py is available in the Balloon func),
maybe it is (then :py is not available in the Balloon func). If you
find out, I'm interested to hear your result.


To access vim variables in py commands
(like text under cursor, all the 'let variables', 'set options'):
Try along these lines:

let vimstringvar="mystring"
let numericvar=123
:exe ":py pythonvar=".numericvar           " we got vim numericvar
into pythonvar
:exe ":py pythonvar='".vimstringvar."'"   " we got vim string var into pythonvar
" similarly for options. nb difference needed between string vs numeric
:exe ":py pythonvar=".&readonly          " we got numeric vim option
into pythonvar
:exe ":py pythonvar='".&runtmepath."'"    " we got string vim option
into pythonvar

NB if rhs string contains apostrophe, then additional care is needed.

THis is what comes to mind. Maybe more direct method exists.
I don't know.

Yakov

Reply via email to