blob: baee0db52e430403f356edd5a88a41d28c0e0d13 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
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()
|