* On Wed, Jun 21, 2006 at 02:07:58PM +0200, Marc Weber <[EMAIL PROTECTED]>
wrote:
> Hi. Here is my enhanced script.
> Should now work for all windows users with python enabled vim too.
Perl is likely more portable than python. For instance I have perl
installed on the solaris box I'm working on at work, while Python is
not.
> If you don't have any comments I'll add it to vimscripts an vim.org
Here are a few new thoughts then.
> ============= runinbg.vim
> ======================================================
> " author : Marc Weber
> " purpose: run commands in background and continue with your work
> " os:
> " linux with bash or python enabled,
> " windows with bash or python enabled (not yet tested but should work)
>
> " usage: see RunMakeInBG
> " eg call RunMakeInBG('make all')
> " or
> " eg call RunMakeInBG(['make','all'])
I guess users will prefer commands over explicit functions calls.
NB: My plugins always start with
let s:cpo_save=&cpo
set cpo&vim
if exists("g:loaded_runinbg")
\ && !exists('g:force_reload_runinbg')
let &cpo=s:cpo_save
finish
endif
let g:loaded_runinbg = 1
and end with:
let &cpo = s:cpo_save
>
> " todo? kill processes on exit?
> " handle stderr output with python, too
Indeed, stderr is quite important. 2>&1 (or maybe even better
&shellredir, I don't know) is a good friend as it won't desynchronize
stdout and stderr.
> if has('gui-running') " FIXME: get vim executable name insteadn (cargs 0)
> let s:vim="gs:vim"
The string literal is odd.
> else
> let s:vim="s:vim"
> endif
> let s:vim="/usr/bin/gvim"
May be you can try executable('gvim') instead. In the perl module I've
defined, the heuristic I use is to search in $PATH : gvim.exe, vim.exe,
vim or gvim (in this order).
I guess on some *nix, we can always do a
:let vimpid = libcallnr("libc.so", "getpid", "")
:let vimpath = matchstr(system('pmap '.vimpid.' | head -2 | tail -1')
\ 'someregex')
On windows, (with the perl module when vim is not in the $path) I'm
looking for vim in the latest directory in $VIM (don't forget the
versionning scheme don't follow the lexical order;
i.e.: vim70 > vim63b > vim63 > vim62)
> " add your tasks here
> fun! BackgroundJobHasStarted()
Script local functions is often a better default choice.
HTH,
--
Luc Hermitte
http://hermitte.free.fr/vim/