Created
May 15, 2020 00:08
Star
You must be signed in to star a gist
Script to evaluate cinoption for each line on the buffer
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
" tell which cinoption take effect for current line | |
command! WhichCinoption call WhichCinoption() | |
function! WhichCinoption() abort | |
" test if cindent take effect | |
if !empty(&indentexpr) | |
echo "'indentexpr' exists, it overrides 'cindent'." | |
return | |
endif | |
if !&cindent | |
echo "'cindent' is currently disabled." | |
return | |
endif | |
setlocal scrollbind | |
leftabove 16vnew | |
let signbuf = bufnr() | |
setlocal buftype=nofile | |
setlocal bufhidden=hide | |
setlocal noswapfile | |
wincmd p | |
" test cinoption one by one | |
" copied from :h cino- <ctrl-a> in vim8.2 1-677 | |
let opts = ['#','(',')','+','/',':','=','>','^','{','}','C','E','J','L','M','N','U','W','b','c','e','f','g','h','i','j','k','l','m','n','p','t','u','w','*'] | |
for l in range(1, line('$')) | |
let indent = cindent(l) | |
let results = [] | |
let cinopt = &l:cinoptions | |
for opt in opts | |
try | |
" test it with 8s, it should be big enough to make difference | |
exe printf('setlocal cinoptions+=%s8s', opt) | |
if indent != cindent(l) | |
let results += [opt] | |
endif | |
catch /.*/ | |
echom 'failed to test ' . opt | |
echom 'internal error : ' . v:exception | |
finally | |
let &l:cinoptions = cinopt | |
endtry | |
endfor | |
call setbufline(signbuf, l, join(results)) | |
endfor | |
syncbind | |
endfunction |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment