mirror of
https://github.com/chenasraf/vim-matchup.git
synced 2026-05-18 01:38:57 +00:00
Make small perf improvements in matching/surround
This commit is contained in:
@@ -45,8 +45,8 @@ function! matchup#delim#get_matching(delim, ...) " {{{1
|
||||
" this gives us a context object which we use for the other side
|
||||
" TODO: what if no open is found here?
|
||||
let l:matches = []
|
||||
let l:save_pos = matchup#pos#get_cursor()
|
||||
for l:down in {'open': [1], 'close': [0], 'mid': [0,1]}[a:delim.side]
|
||||
let l:save_pos = matchup#pos#get_cursor()
|
||||
call matchup#pos#set_cursor(a:delim)
|
||||
|
||||
" second iteration: [] refers to the current match
|
||||
@@ -58,8 +58,8 @@ function! matchup#delim#get_matching(delim, ...) " {{{1
|
||||
if l:res[0][1] > 0
|
||||
call extend(l:matches, l:res)
|
||||
endif
|
||||
call matchup#pos#set_cursor(l:save_pos)
|
||||
endfor
|
||||
call matchup#pos#set_cursor(l:save_pos)
|
||||
|
||||
if a:delim.side ==# 'open'
|
||||
call insert(l:matches, [])
|
||||
@@ -156,6 +156,9 @@ function! matchup#delim#get_surrounding(type, ...) " {{{1
|
||||
endif
|
||||
|
||||
let l:matches = matchup#delim#get_matching(l:open, 1)
|
||||
if has_key(l:opts, 'matches')
|
||||
let l:opts.matches = l:matches
|
||||
endif
|
||||
|
||||
if len(l:matches)
|
||||
let l:close = l:local ? l:open.links.next : l:open.links.close
|
||||
|
||||
@@ -364,13 +364,20 @@ function! matchup#matchparen#offscreen(current) " {{{1
|
||||
endfunction
|
||||
|
||||
" }}}1
|
||||
function! matchup#matchparen#highlight_surrounding(...) " {{{1
|
||||
function! matchup#matchparen#highlight_surrounding() " {{{1
|
||||
call matchup#perf#timeout_start(500)
|
||||
let l:delims = matchup#delim#get_surrounding('delim_all', 1)
|
||||
call s:highlight_surrounding()
|
||||
endfunction
|
||||
|
||||
" }}}1
|
||||
|
||||
function! s:highlight_surrounding(...) " {{{1
|
||||
let l:opts = { 'local': 0, 'matches': [] }
|
||||
let l:delims = matchup#delim#get_surrounding('delim_all', 1, l:opts)
|
||||
let l:open = l:delims[0]
|
||||
if empty(l:open) | return | endif
|
||||
|
||||
let l:corrlist = matchup#delim#get_matching(l:open, 1)
|
||||
let l:corrlist = l:opts.matches
|
||||
if empty(l:corrlist) | return | endif
|
||||
|
||||
" store flag meaning highlighting is active
|
||||
|
||||
Reference in New Issue
Block a user