Zdenek Sekera wrote:
Perhaps a strange question so maybe a small explanation
of "why" is in order:

When I :source or :runtime a *.vim file, commands in that
file build a buffer. To know when the buffer is complete,
I have to know what follows, and if complete (because
the following has an indicator of the start of a new buffer)
add it to a vim variable g:xxx and start a new buffer.
In essence I have to always "know ahead".

Clearly the last buffer will not be ever complete because
there is nothing to tell me it should be completed. There
is nothing read from *.vim, since the :source ran to its end.
I can handle that last buffer only when I start using
the g:xxx variable and find out the buffer is not empty
and then add it to g:xxx.

That complicates the algorithm quite a bit so I was thinking
"is there a way to know :source or :runtime has finished"?
I was thinking of some autocmd, but unfortunately the only
event of interest in this context I found is 'SourcePre' but
no 'SourceAfter' which would ideal.

Would anyone have an idea how to recognize the end of
:source/:runtime?

Thanks,

---Zdenek


The source/runtime operation is complete when it returns to its caller:

        if exists("g:FooBarIsRunning")
                let s:FooBarIsRunning = g:FooBarIsRunning
        else
                let s:FooBarIsRunning = 0
        endif
        let g:FooBarIsRunning = 1
        source foobar.vim
        let g:FooBarIsRunning = s:FooBarIsRunning
        ...
        ...
        ...
        ...
        ...
        function DoSomething()
                ...
                ...
                ...
                if g:FooBarIsRunning
                        ...
                        ...
                else
                        ...
                        ...
                endif
                ...
                ...
                ...
        endfunction


Doing it with commands intrinsic to the script (i.e., inside it) is trickier because the script can terminate in several ways:

a) by falling through to its end
b) by executing a ":finish" command
c) because of an error

(a) is simplest: just add an instruction at the end.
(b) is almost as simple: search the script for \<finish\> and add an instruction before each occurrence (c) is the hardest: since we don't know what error may be triggered where, it may requiring wrapping the whole script in a try...endtry block, which makes it incompatible with pre-6.2 Vim.


Best regards,
Tony.

Reply via email to