Spawning a new instance of Vim via OLE

4 views
Skip to first unread message

David Fishburn

unread,
May 7, 2010, 2:53:06 PM5/7/10
to vim_use

I was reading :h ole-interface.

Is there anyway to spawn a new instance of Vim via OLE, through some
command (or anything)?
OLE automatically picks up the first already running Vim instance which
supports OLE.
If one is not running it spawns one.

I was wanting to spawn a new one everytime.

TIA,
Dave

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

bill lam

unread,
May 7, 2010, 7:06:13 PM5/7/10
to vim_use
Птн, 07 Май 2010, David Fishburn писал(а):
>
> I was reading :h ole-interface.
>
> Is there anyway to spawn a new instance of Vim via OLE, through some
> command (or anything)?
> OLE automatically picks up the first already running Vim instance
> which supports OLE.
> If one is not running it spawns one.
>
> I was wanting to spawn a new one everytime.

I forgot nearly all visual basic ole stuff by now. IIRC when a ole
server is first registered, it stored a flag 'multiuse' inside window
registry. If this flag is set, then you the same loaded server will be
shared by different client. On the other hand, if it is 'singleuse',
it will be the behavior that you asked for. Therefore this property
is controlled by a flag in registry.

My memory may be incorrect but that should give you some words to
google. :-)

--
regards,
====================================================
GPG key 1024D/4434BAB3 2008-08-24
pg --keyserver subkeys.pgp.net --recv-keys 4434BAB3

David Fishburn

unread,
May 9, 2010, 11:26:15 PM5/9/10
to vim...@googlegroups.com
On Fri, May 7, 2010 at 7:06 PM, bill lam <cbil...@gmail.com> wrote:
> Птн, 07 Май 2010, David Fishburn писал(а):
>>
>> I was reading :h ole-interface.
>>
>> Is there anyway to spawn a new instance of Vim via OLE, through some
>> command (or anything)?
>> OLE automatically picks up the first already running Vim instance
>> which supports OLE.
>> If one is not running it spawns one.
>>
>> I was wanting to spawn a new one everytime.
>
> I forgot nearly all visual basic ole stuff by now.  IIRC  when a ole
> server is first registered, it stored a flag 'multiuse' inside window
> registry.  If this flag is set, then you the same loaded server will be
> shared by different client. On the other hand, if it is 'singleuse',
> it will be the behavior that you asked for.  Therefore this property
> is controlled by a flag in registry.


Thanks Bill.

I see in the code where we set the flags. These do not appear to set
in the Windows Registry though (or at least I couldn't find it). I
was originally hoping to tweak it after Vim was started.

Once I hit the above road block I started thinking about Vim's client
server feature. I have use the --servername and --remote-send
features from the command line in the past.

:h clientserver

Shows there are similar functions which can be used from within Vim
script. So in the end, I was able to accomplish what I was looking
for, by something as simple as:

function! MyFunction(filename, encoding)
let cmd = ':e '.' '.a:filename. "\n"

if g:my_servername == '' || g:my_servername == v:servername
exec cmd
else
if match( serverlist(), '\<'.g:my_servername.'\>' ) > -1
call remote_send( g:my_servername, cmd )
endif
endif


So this essentially forwarded my request on to the correct Vim
instance. Since all Vim's register OLE, you don't really have any
control over which one you talk to. So this works quite well.

Dave

David Fishburn

unread,
Aug 28, 2010, 8:34:26 AM8/28/10
to Jeenu, vim...@googlegroups.com

On Aug 28, 2010, at 4:16 AM, Jeenu <gro...@jeenuv.otherinbox.com> wrote:

>
>
> On May 7, 11:53 pm, David Fishburn <dfishburn....@gmail.com> wrote:
>> I was reading :hole-interface.


>>
>> Is there anyway to spawn a new instance of Vim viaOLE, through some

>> command (or anything)?OLEautomatically picks up the first already

>> running Vim instance which
>> supportsOLE.
>> If one is not running it spawns one.
>>
>> I was wanting to spawn a new one everytime.
>

> Wondering if there's been any changes to this with Vim 7.3. I'm too
> find it needy to spawn an individual instance every time. I find it a
> deadlock that server name can only be set at startup using --
> servername, and I can't pass anything to
> CreateObject("Vim.Application") (from VBA).
>
> Alternatively, is there any registry tweaks that I can do to get what
> I want? I'm not that familiar with Windows technologies, and maybe
> this is stupid: is there hack/procedure to get something like
> CreateObject("Vim.Application2") work so that the instance registers
> itself as a server, say "MyServer"?
>
>
I can't remember if I responded back on this thread.

I have everything working as I need it but this is how I did it.

From VB do the usual call. This will either spawn a new instance of
Vim or connect to an already running version.

My plugin, OutlookVim, creates a number of different public functions.
When I want VB to do something it calls a pulic function.

In Vim the public function checks if this Vim instance is the correct
one. If so, continues. If not uses Vim's built in remote_send()
function to send the command to the correct instance.

There is error checking all the way along.

This allowed me to do exactly what I wanted all via Vim with no
external hacks.

HTH,
Dave

Jeenu

unread,
Aug 28, 2010, 8:51:04 AM8/28/10
to vim_use


On Aug 28, 5:34 pm, David Fishburn <dfishburn....@gmail.com> wrote:
> [...]
> My plugin, OutlookVim, creates a number of different public functions.  
> When I want VB to do something it calls a pulic function.
>
> In Vim the public function checks if this Vim instance is the correct  
> one. If so, continues. If not uses Vim's built in remote_send()  
> function to send the command to the correct instance.
>
> There is error checking all the way along.
>
> This allowed me to do exactly what I wanted all via Vim with no  
> external hacks.

In fact I was reading your plugin. In function Outlook_EditFile
there's a check:

if g:outlook_servername == '' || g:outlook_servername == v:servername

If the servername is not set, I think this makes Vim open up another
buffer/tab on the last used/existing Vim window instead of opening its
own one. That's something I'm trying to avoid because I typically use
individual Vim windows for grouping related work - code browsing, or
Wiki editing. I don't want a completely unrelated tab/buffer popping
up in the middle.

Jeenu
Reply all
Reply to author
Forward
0 new messages