Skip to content

Instantly share code, notes, and snippets.

@b0o
Last active March 6, 2019 10:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save b0o/64a7bd45975db98f89c6fa1f01e646da to your computer and use it in GitHub Desktop.
Save b0o/64a7bd45975db98f89c6fa1f01e646da to your computer and use it in GitHub Desktop.
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