diff options
-rw-r--r-- | vim/plugin/detect_indent.vim | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/vim/plugin/detect_indent.vim b/vim/plugin/detect_indent.vim new file mode 100644 index 00000000..baee0db5 --- /dev/null +++ b/vim/plugin/detect_indent.vim @@ -0,0 +1,53 @@ +function Count() abort + let spaces = { + \ 'histogram': {}, + \ 'total': 0, + \} + let tabs = 0 + let total = line('$') + for lnum in range(1, total) + let line = getline(lnum) + let tabs += matchstr(line, '^\t*') != '' + let ls = strlen(matchstr(line, '^ *')) + if ls == 0 + continue + endif + if !has_key(spaces['histogram'], ls) + let spaces['histogram'][ls] = 0 + endif + let spaces['histogram'][ls] += 1 + let spaces['total'] += 1 + endfor + setlocal + + echo spaces + echo tabs + + if tabs > spaces['total'] * 5 + echo 'TABS' + setlocal noexpandtab shiftwidth=0 softtabstop=-1 + elseif spaces['total'] > tabs * 5 + echo 'SPACES' + let set = [] + for ls in keys(spaces['histogram']) + if spaces['histogram'][ls] * 100 / spaces['total'] >= 10 + call add(set, ls) + endif + endfor + for div in range(1, max(set)) + for ls in set + if ls % div != 0 + break + endif + let gcd = div + endfor + endfor + echo gcd + echo set + else + echo 'UNCLEAR' + endif + +endfunction + +autocmd FileType * call Count() |