On Thu 9-Nov-06 5:27pm -0600, Yakov Lerner wrote:

> I filed another change at
> http://www.vim.org/tips/tip.php?tip_id=1379
> to this piece that makes it safe when two or more scripts use
> this same technique simultaneously (otheriwse, &ut restoration
> can go wrong, order of autocommands triggering is unpredictable).

> Bill, do you think the "if s:Pecho!=''|' check in autocommand is necessary ?

No I do not - it was just there from your original.

> " further improvement in restoration of the &updatetime. To make this
> " usable in the plugins, we want it to be safe for the case when
> " two plugins use same this same technique. Two independent
> " restorations of &ut can run in unpredictable order. In order to
> " make it safe, we add additional check in &ut restoration.

> let s:Pecho=''
> fu! s:Pecho(msg)
>   let s:hold_ut=&ut | if &ut>1|let &ut=1|en
>   let s:Pecho=a:msg
>   aug Pecho
>   au CursorHold * if s:Pecho!=''|echo s:Pecho
>     \|let s:Pecho=''|if s:hold_ut > &ut |let &ut=s:hold_ut|en|en
>     \|aug Pecho|exe 'au!'|aug END|aug! Pecho
>   aug END
> endf

> In this form, I think it's safe for use in plugins.

I don't see the protection from collision.  I haven't
updated the tip yet, but the following code appears to solve
the potential problem and removes unnecessary logic:

    " This update eliminates all "if" statements and introduces
    " a locked variable to prevent collisions.  Should a call to
    " Pecho occur before the CursorHold is triggered, that call
    " will wait for the triggering to unlock.

    let g:PechoLock = 0
    
    fu! s:Pecho(msg)
      wh islocked("g:PechoLock")|sl|endw
      lockv g:PechoLock|let s:hold_ut=&ut|let &ut=1
      let s:Pecho=a:msg
      aug Pecho
      au CursorHold * ec s:Pecho
        \|let &ut=s:hold_ut|unlo g:PechoLock
        \|aug Pecho|exe 'au!'|aug END|aug! Pecho
      aug END
    endf

-- 
Best regards,
Bill

Reply via email to