On Fri, 5 May 2006 at 9:22am, Bram Moolenaar wrote: > > Hari Krishna Dara wrote: > > > Using Vim 70g, I am seeing a weird problem with CursorMoved autocommand. > > In a function, I am removing my CursorMoved autocommand, moving the > > cursor and adding the CursorMoved autocommand back, but the cursor > > movement somehow ends up triggering the autocommand. At the time of > > cursor movement, there is no way the autocommand could have been > > defined, but instead of using the state at the time of cursor movement, > > the state at the end of the execution of the function is being used. > > That's very well possible. Vim compares the current cursor position to > the one when CursorMoved was last triggered. And you would get a > trigger right after adding the first CursorMoved autocommand. > > Perhaps what you want to do can be done by adding CursorMoved to > 'eventignore'?
That doesn't work either. I also tried adding a :redraw to force an immediate movement of the cursor, in case it is queued. cmap <F12> <End><C-U><BS>:<C-R>=TT()<CR><BS> function! TT() "aug TT " au! "aug END let _eventignore = &eventignore set eventignore+=CursorMoved try normal j redraw return "" finally let &eventignore = _eventignore endtry endfunction aug TT au! au CursorMoved * :call input('CursorMoved') aug END > > Or somehow add a flag to the code that is triggered, so that it does nothing. This will work if the autocommand behaves consistently. The autocommand is being triggered after the map finishes execution, not immediately after adding the CursorMoved autocommand, so I can't have a flag only for the duration of the function execution. I tried the below: cmap <F12> <End><C-U><BS>:<C-R>=TT()<CR><BS> let g:ignore = 0 function! TT() aug TT au! aug END let g:ignore = 1 try normal j return "" finally aug TT au! au CursorMoved * :call input('CursorMoved ignore is:'.g:ignore) | let g:ignore = 0 aug END endtry endfunction If the autocommand is always triggered, I can check for the state of the flag, ignore the event and reset the flag. Thanks, Hari __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com