diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2020-05-29 23:24:13 +1200 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2020-05-29 23:24:13 +1200 |
commit | eeebdbb8a2059ab46500f33ffe7b565e0fa0f3e5 (patch) | |
tree | 4b29ae7710b63af20eaa4085b53b20ec21ce99ad | |
parent | Merge branch 'hotfix/v9.10.5' into develop (diff) | |
download | dotfiles-eeebdbb8a2059ab46500f33ffe7b565e0fa0f3e5.tar.gz dotfiles-eeebdbb8a2059ab46500f33ffe7b565e0fa0f3e5.zip |
Working on a plugin for detecting tab indent
-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() |