On Thu, Oct 19, 2006 at 11:43:22PM +0200, Yakov Lerner wrote:
> I am making a plugin which naturally requires &nocp
> because it uses <keys> in lhs and rhs of mappings it defines.
> What if that plugin sees &cp, what it shall do ? Shall I
> save old value of &cp, then temporarily 'set nocp', define
> mappings, then restore &cp ? Is this OK ?
>
> Or it shall check &cp and silently not load if it's &cp!=0 ?
> Or it shall not check &cp and define bogus mappings and
> to hell with checking &cp ?
>
> Yakov
Have a look at some of the default plugins.
" Exit quickly when:
" - this plugin was already loaded (or disabled)
" - when 'compatible' is set
" - the "CursorMoved" autocmd event is not availble.
if exists("g:loaded_matchparen") || &cp || !exists("##CursorMoved")
finish
endif
let g:loaded_matchparen = 1
if v:version < 700
echohl WarningMsg | echo "***netrw*** you need vim version 7.0 for this
version of netrw" | echohl None
finish
endif
let s:keepcpo= &cpo
set cpo&vim
" [snip]
let &cpo= s:keepcpo
unlet s:keepcpo
The matchparen plugin works "automatically," which seems likely to annoy
someone who wants vim to be 'compatible', so it makes sense for it to
bail out. The netrw plugin provides new commands, so it is less likely
to annoy. So one bails out when 'cp' is set, and the other saves and
restores.
HTH --Benji Fisher