Skip to content

Instantly share code, notes, and snippets.

@mattn
Created November 13, 2019 06:19
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattn/429678bca6fd5827af0c1e20905cc625 to your computer and use it in GitHub Desktop.
Save mattn/429678bca6fd5827af0c1e20905cc625 to your computer and use it in GitHub Desktop.
if empty(prop_type_get('tapioca'))
let s:id = 0
let s:m = {}
call prop_type_add('tapioca', {
\ 'highlight': 'TODO',
\ 'start_incl': 1,
\ 'end_incl': 1,
\})
endif
function! s:Add(...) abort
let s:id += 1
call prop_add(line('.'), col('.'), {'length': strlen('●'), 'type': 'tapioca', 'id': s:id})
let s:m[s:id] = v:char
let v:char = '●'
endfunction
function! s:TapiocaOn() abort
augroup Tapioca
au!
autocmd InsertCharPre <buffer> call s:Add()
augroup END
endfunction
function! s:TapiocaOff() abort
augroup Tapioca
au!
augroup END
for l:l in range(1, line('$'))
let l:rs = getline(l:l)
for l:p in prop_list(l:l, {'type': 'tapioca'})
if l:p.col > 1
let l:rs = l:rs[: l:p.col-1] . get(s:m, l:p.id, '') . l:rs[l:p.col+l:p.length-1 :]
else
let l:rs = get(s:m, l:p.id, '') . l:rs[l:p.col+l:p.length-1 :]
endif
endfor
call setline(l:l, l:rs)
endfor
endfunction
command TapiocaOn call s:TapiocaOn()
command TapiocaOff call s:TapiocaOff()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment