Skip to content

Instantly share code, notes, and snippets.

@b0o b0o/hlmgr.vim
Last active Mar 6, 2019

Embed
What would you like to do?
function s:hlmgr(...)
let this = {}
let this.stack = []
func! this.push(rect)
let self.stack = [ a:rect ] + self.stack
endfunc
func! this.pop()
let [ l:rect; self.stack ] = self.stack
return l:rect
endfunc
func! this.matchRect(group, rect)
let [l:l1, l:c1, l:l2, l:c2] = a:rect
let l:cmd = 'match ' . a:group . ' /'
let l:cmd .= '\%>' . (l:l1 - 1) . 'l'
let l:cmd .= '\%<' . (l:l2 + 1) . 'l'
let l:cmd .= '\%>' . (l:c1 - 1) . 'c'
let l:cmd .= '\%<' . (l:c2 + 1) . 'c'
let l:cmd .= '/'
execute l:cmd | redraw!
endfunc
func! this.hlRect(group, rect)
call self.push(a:rect)
call self.matchRect(a:group, a:rect)
endfunc
func! this.unhl(...)
let l:count = (a:0 > 0) ? a:1 : 1
while l:count > 0
try
let l:rect = self.pop()
call self.matchRect('None', l:rect)
catch
break
endtry
let l:count -= 1
endwhile
endfunc
func! this.unhlRect(rect)
let l:i = 0
for l:rect in self.stack
if l:rect != a:rect
let l:i += 1
continue
endif
call remove(self.stack, l:i)
call self.matchRect('None', l:rect)
return
endfor
throw "rect " . string(rect) . " not found"
endfunc
return this
endfunction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.