joeytwiddle / sexy_scroller.vim

smooth animation of the cursor and the page whenever they move, with easing
89 stars 7 forks source link

Option to disable autocommands #9

Closed jackieleng closed 8 years ago

jackieleng commented 9 years ago

I think it may be useful to have an option to disable the cursor autocommands, for example if you want to use the exposed scroll function, so I've added this option. It does require all the commands in the autocmd block to be wrapped with another function; it's the easiest way I found to make this work without needing to restart VIM or anything like that. Let me know what you think.

joeytwiddle commented 9 years ago

Thanks for the contribution.

I am curious under what conditions you need to disable the autocmds. Are they causing late unwanted scroll animations for you?

(These are usually caused when the cursor/viewport move but SS doesn't notice ... until one of its autocmds fires later.)

Personally I have been calling g:SexyScroller_ScrollToCursor(...) from plugins which move the cursor but fail to trigger any of the autocmds (e.g. they use noauto for good reason). In other words, I create addition triggers, to keep SS up-to-date. I have never needed to disable them!

(Crucially, I make the call after the movement, passing 0 if I don't want to animate the scroll.)

" We have moved but without triggering.
" Tell SS to animate from last known position to current position.
call g:SexyScroller_ScrollToCursor()     " or equally
call g:SexyScroller_ScrollToCursor(1)

" We have moved but without triggering.
" Tell SS where we are now (update its last known position) but don't animate it.
call g:SexyScroller_ScrollToCursor(0)

When the autocmds do eventually trigger, they now know the new position from the call to ScrollToCursor, so they don't do a "late" scroll; they should do the right thing.

Another way to disable the autocmds would be to actually clear them directly:

function! g:SexyScroller_DisableAutocmds()
  augroup Smooth_Scroller
    autocmd!
  augroup END
endfun

Anyway, if you can show me how to reproduce your problematic situation, we may be able to find a gentler solution.

joeytwiddle commented 8 years ago

Merged. I hope it can be useful.