[EMAIL PROTECTED] wrote:
"A.J.Mechelynck" <[EMAIL PROTECTED]> wrote:
The ps solution is difficult to use, because there may be several instances
of Vim running in parallel (whose prognames might or might not be different)
and I want to make sure to access the "current" instance: so I would have to
know the process ID of the current Vim and I don't know how to do that.
Using system('ls -l /proc/self') wouldn't work, because that would return
the PID of the ls process called by a subshell called by Vim.
libcallnr("/usr/lib/libc.so", "getpid", "")
should do the trick on most *nix flavours.
From here, it should be possible to play with /proc related utilities.
Maybe I'found something... or have I?
(first try omitted, it didn't work)
(second try is better)
(third try:)
" (try to) detect whether we have clipboard and X
if has('clipboard')
let x = @+
let @+ = '--' . x
redir @"
silent reg
redir END
let @+ = x
unlet x
let clipboard_present = (@" =~ '^"+ ')
else
let clipboard_present = 0
endif
let X_available = has('x11') && clipboard_present
The above would fail in a Vim compiled with X support but without clipboard
support. I think that that risk is negligible. Do you (or does anyone) see
other cases where the above algorithm would fail? It relies on the fact that
when the clipboard is not available (for whatever reason: not compiled-in,
-X, or terminal with no X access) the ":reg" command never lists the "+
register, not even if we just yanked a nonempty value into it.
Just in case it may help, this code returns 0 in every situation (gvim, vim, vim
-X) in my config (Solaris custom build)
However it seems tied to the fact the "^" prevents '"+' from being matched --
while (@" =~ "\n".'"+ ') is non null. With this new regex, I always end up with
1.
Well, I dodn't test well enough. Here's a new snippet:
" (try to) detect whether we have clipboard and X
if has('clipboard')
function TestForX()
let x = @+
let @+ = '--' . x
redir @"
silent reg
redir END
let @+ = x
" unlet x
return (@" =~ '\n"+ ')
endfunction
else
function TestForX()
return 0
endfunction
endif
augroup vimrclocal
au VimEnter *
\ let clipboard_present = TestForX()
\ | let X_available = has('x11') && clipboard_present
augroup END
"
" and further down in the vimrc
"
" Define these mappings only if we have access to a clipboard
augroup vimrclocal
au VimEnter *
\ if clipboard_present
\ | map <F4> :$put +<CR>
\ | map <S-F4> :0put +<CR>
\ | imap <F4> <C-O>:$put +<CR>
\ | imap <S-F4> <C-O>:0put +<CR>
\ | endif
augroup END
I didn't succeed to define the variables when sourcing the vimrc, apparently
in gvim it only works after the GUI has started. Previously I had tested it
only in various versions of console Vim with and without -X.
Best regards,
Tony.
--
Who's on first?