-
-
Save mattn/429678bca6fd5827af0c1e20905cc625 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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