Thursday, May 13, 2010

Re: writing to a buffer (not only with python)

Tony Mechelynck-2 wrote:
>
> On 13/05/10 09:40, 0x0renegat0x0 wrote:
>>
>> Hi
>>
>> I don't like vim syntax for writing scripts (set let a: g:variable). I
>> choose to use python environment for writing things in vim.
>>
>> However I've encountered some problems.
>>
>> One:
>> I have access to buffers from vim python object. However I don't know if
>> I
>> can add buffer via vim objects or if this object is only for accessing
>> the
>> buffers.
>>
>> I cannot inherit Vim object. That is why I created my own wrapper for vim
>> native functions (line, getline, setline). I do that by vim.eval()
>> command.
>> The problem is that to write into a buffer I have to switch into other
>> buffer and then I have to call in a loop setline which can only write
>> into
>> current buffer.
>>
>> My Write function in python makes vim call by vim.eval() as following
>> :b1 (select buffer1)
>> getline(...)
>> setline(...)
>> setlocal(...)
>> :b4 (select previous buffer)
>>
>> When I am writing a lot of data to the buffer it takes time. It is too
>> long
>> for me to accept. The speed of execution is only determined by python
>> environment? Or I shouldn't be using eval function, or is there any way
>> to
>> speed things up?
>>
>
> For maximum efficiency and, most especially, portability, I would
> recommend to learn Vim commands. They aren't really difficult, and their
> documentation (the Vim help) is really top-class. Oh, the Perl, Python,
> etc., interfaces do work, if you have them compiled-in and, if
> dynamically linked, if you have the right versions of the libraries
> available. But using them means exchanging messages both ways between
> the Perl, Python, etc. interpreter and the Vim editor _in addition_ to
> whatever tasks the interpreter and the editor normally do.
>
> You _can_ use vim.command("edit foobar.py") in a python script to start
> editing the file foobar.py (which will then be your current buffer,
> unless Vim isn't willing to |abandon| (q.v.) the file you were editing
> previously and raises an exception); but if you open a new buffer by
> typing
>
> :py vim.command("edit foobar.py")
>
> at the command-line (which is valid if Vim was compiled with +python,
> the python libs are available, and you've already imported the vim
> module into the python side of the interface), I will start thinking
> that your preferred path from London to Westminster is through Rome.
>
>
> Best regards,
> Tony.
> --
> Philadelphia is not dull -- it just seems so because it is next to
> exciting Camden, New Jersey.
>
> --
> 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
>
>

Well yeah. It is not so simple for me. I am aware that using python with vim
is inefficient. But is there no way to speed things up?
I have installed some plugins and the other plugins are using (sometimes)
python too. I think that they are pretty fast. I don't know maybe I have
some bug in my code somewhere.

I do not want to use vim syntax because code does not look clear for me. I
do not feel that this vim-language will ever be useful for me. I know on the
other hand that python language may be. I do not know if in future work I
will not be using python? I want the language to be versatile.

I prefer switching buffer than opening the file, because I am developing
simple plugins for myself (for my work). I want to create something more
high-level than vim low level functions without classes.
With my plugins, my vim wrapper it is clear that writing is done only to a
current buffer (since only a buffer has write method), methods are grouped
by objects, not put in all in one in vim help documentation.
In non volatile buffers I am gathering informations, outputs from programs,
and other stuff.

Don't get me wrong - I like vim very much, although I want to use a better
language for scripting it.
I think that if I am going to use vim I will just have to get use to
inefficiency of this solution...

--
View this message in context: http://old.nabble.com/writing-to-a-buffer-%28not-only-with-python%29-tp28544564p28545864.html
Sent from the Vim - General mailing list archive at Nabble.com.

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