Friday, August 26, 2011

Re: display faster output of external app

On 2011-08-26, niva wrote:
> Hi,
>
> I am calling an external app from vim like that :
>
> 1/ calling the application
> let g:output=system(s:cmd)
>
> 2/ deleting old returned value and updating with new one
> call s:OPC.AddValueAtEndOfFile(g:output)
>
> " Write value at end of line {{{1
> fun! s:OPC.AddValueAtEndOfFile(value)
> exe "norm ^f d$"
> exe "norm ^".s:maxlinelength."l"
> exe "norm a ".a:value
> endfunction
> ==============================================
>
> In fact this algo is called at each line to process in my entry file.
> I have done another method that do this task on several lines 10.
>
> Is there another way to make the call of external app or the update
> method faster ?

Again generally speaking, it's faster to process text using Vim's
commands and functions than to write a bunch of instructions that
Vim has to parse as well as execute. Your AddValueAtEndOfFile()
function simply replaces everything after the first space in the
current line with g:output. Therefore you could replace

call s:OPC.AddValueAtEndOfFile(g:output)

with

exe "s/ .*/ ".g:output."/"

or even

exe "s/ .*/ ".system(s:cmd)."/"

That assumes that the output of s:cmd doesn't contain any slashes.
I doubt that that is the bottleneck, though.

Regards,
Gary

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