Skip to content

Instantly share code, notes, and snippets.

@filbranden
Created May 15, 2020 00:08
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save filbranden/5b92a445a09db86ba9681270fabcfe62 to your computer and use it in GitHub Desktop.
Script to evaluate cinoption for each line on the buffer
" 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