Monday, June 18, 2012

Re: pydoc an run python snippets integration problems

2012/6/6 Pablo Giménez <pablogipi@gmail.com>:
> Hello.
> I am using a set of scripts to integrate Python in VIM done by Kirill
> Klenov know as Python mode Klen:
> http://www.vim.org/scripts/script.php?script_id=3770
>
> I am having trouble with pydoc and run python code.
> For pydoc it uses the next funtion to open a scratch buffer with the
> output of the help() pythom command:
> fun! pymode#doc#Show(word) "{{{
>    if a:word == ''
>        echoerr "No name/symbol under cursor!"
>    else
>        py import StringIO
>        py sys.stdout, _ = StringIO.StringIO(), sys.stdout
>        py help(vim.eval('a:word'))
>        py sys.stdout, out = _, sys.stdout.getvalue()
>        call pymode#TempBuffer()
>        py vim.current.buffer.append(out.split('\n'), 0)
>        wincmd p
>    endif
> endfunction "}}}
I fixed this problem the other day.
Seems python get confussed with the out variable, a cast to a tring
solves the problem.
So changing the line:
py vim.current.buffer.append(out.split('\n'), 0)
by:
py vim.current.buffer.append(str(out).split('\n'), 0)

Solves it.
Same thing applies for the other function below.
>
> When running it I got these errors:
> Error detected while processing function pymode#doc#Show:
> line    9:
> Traceback (most recent call last):
>  File "<string>", line 1, in <module>
> TypeError: bad argument type for built-in operation
> Error detected while processing function pymode#doc#Show:
> line    9:
> Traceback (most recent call last):
>  File "<string>", line 1, in <module>
> TypeError: bad argument type for built-in operation
>
> I have been looking the docs in vim about buffer methods in python,
> and the code using the append() method looks correct.
> I think the out variable is causing the error, but I dont know why.
>
> The other issue is related to the function that runs a snippet of code
> and returns a scratch buffer with the output.
> I have this simple python file:
> import os
>
> def main():
>    print 'Test run'
>
> if __name__ == '__main__':
>    main()
>
> The function to run a buffer is the next:
> fun! pymode#run#Run(line1, line2) "{{{
>    if &modifiable && &modified | write | endif
>    py import StringIO
>    py sys.stdout, _ = StringIO.StringIO(), sys.stdout
>    py execfile(vim.eval('expand("%s:p")'), {}, {})
>    py sys.stdout, out = _, sys.stdout.getvalue()
>    call pymode#TempBuffer()
>    py vim.current.buffer.append(out.split('\n'), 0)
>    wincmd p
> endfunction "}}}
>
> Then there  is a command mapped to this function:
> command! -buffer -nargs=0 -range=% Pyrun call
> pymode#run#Run(<f-line1>, <f-line2>)
>
> Well, if I execute this function it opens a scratch buffer but the
> output is empty, which is wrong it should be  showing the 'Tst run'
> string.
> I wonder if it is the same problem as in the previous case, because
> both of them use the append() method, and how the out variable get
> it's output is pretty much the same.
>
> I am using vim 7.3 wirh  Python 2.6.
>
> Thanks!
>
>
>
> --
> Un saludo
> Best Regards
> Pablo Giménez



--
Un saludo
Best Regards
Pablo Giménez

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

Post a Comment