Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cursor move throttling for better performance #40

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 39 additions & 2 deletions autoload/MatchTagAlways.vim
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,39 @@
" You should have received a copy of the GNU General Public License
" along with MatchTagAlways. If not, see <http://www.gnu.org/licenses/>.

function! LongEnough( timer, delay, ... )
let result = 0
let suppressionCount = 0
if ( exists( 'a:1' ) )
let suppressionCount = a:1
endif
" This is the first time we're being called.
if ( !exists( a:timer ) )
let result = 1
else
let timeElapsed = localtime() - {a:timer}
" If it's been a while...
if ( timeElapsed >= a:delay )
let result = 1
elseif ( suppressionCount > 0 )
let {a:timer}_callCount += 1
" It hasn't been a while, but the number of times we have been called has hit the suppression limit, so we activate
" anyway.
if ( {a:timer}_callCount >= suppressionCount )
let result = 1
endif
endif
endif
" Reset both the timer and the number of times we've been called since the last update.
if ( result )
let {a:timer} = localtime()
let {a:timer}_callCount = 0
endif
return result
endfunction

let s:script_folder_path = escape( expand( '<sfile>:p:h' ), '\' )

if has('python')
" Python 2
py import sys
Expand Down Expand Up @@ -51,15 +82,21 @@ function! MatchTagAlways#Setup()
endif

augroup matchtagalways
autocmd! CursorMoved,CursorMovedI,WinEnter <buffer>
\ call s:HighlightEnclosingTagsIfPossible()
autocmd! CursorMoved,CursorMovedI,WinEnter <buffer> call s:RunHighLightEnclosingTag()
autocmd! CursorHold,CursorHoldI <buffer> call s:HighlightEnclosingTagsIfPossible()
augroup END

if !g:mta_use_matchparen_group && g:mta_set_default_matchtag_color
hi MatchTag ctermfg=black ctermbg=lightblue guifg=black guibg=lightblue
endif
endfunction

function! s:RunHighLightEnclosingTag()
" debounce
if LongEnough("s:countDebaunce", 1, 4)
call s:HighlightEnclosingTagsIfPossible()
endif
endfunction

function! s:HighlightEnclosingTagsIfPossible()
" Remove any previous highlighting.
Expand Down