parent
80c5b309da
commit
dd0f3349a2
|
@ -27,6 +27,8 @@ then simply copy and paste:
|
||||||
hierarchy until a match is found. This means, for example, the indent for
|
hierarchy until a match is found. This means, for example, the indent for
|
||||||
the first file in a brand new Ruby project might very well be derived from
|
the first file in a brand new Ruby project might very well be derived from
|
||||||
your `.irbrc`. I consider this a feature.
|
your `.irbrc`. I consider this a feature.
|
||||||
|
* If your file is consistently indented hard tabs, `'shiftwidth'` will be set
|
||||||
|
to your `'tabstop'` Otherwise, a `'tabstop'` of 8 is enforced.
|
||||||
* The algorithm is rolled from scratch, fairly simplistic, and only lightly
|
* The algorithm is rolled from scratch, fairly simplistic, and only lightly
|
||||||
battle tested. It's probably not (yet) as good as [DetectIndent][].
|
battle tested. It's probably not (yet) as good as [DetectIndent][].
|
||||||
Let me know what it fails on for you.
|
Let me know what it fails on for you.
|
||||||
|
|
|
@ -10,6 +10,7 @@ let g:loaded_sleuth = 1
|
||||||
|
|
||||||
function! s:guess(lines) abort
|
function! s:guess(lines) abort
|
||||||
let options = {}
|
let options = {}
|
||||||
|
let heuristics = {'spaces': 0, 'hard': 0, 'soft': 0}
|
||||||
let ccomment = 0
|
let ccomment = 0
|
||||||
|
|
||||||
for line in a:lines
|
for line in a:lines
|
||||||
|
@ -30,9 +31,12 @@ function! s:guess(lines) abort
|
||||||
|
|
||||||
let softtab = repeat(' ', 8)
|
let softtab = repeat(' ', 8)
|
||||||
if line =~# '^\t'
|
if line =~# '^\t'
|
||||||
let options.expandtab = 0
|
let heuristics.hard += 1
|
||||||
elseif line =~# '^' . softtab
|
elseif line =~# '^' . softtab
|
||||||
let options.expandtab = 1
|
let heuristics.soft += 1
|
||||||
|
endif
|
||||||
|
if line =~# '^ '
|
||||||
|
let heuristics.spaces += 1
|
||||||
endif
|
endif
|
||||||
let indent = len(matchstr(substitute(line, '\t', softtab, 'g'), '^ *'))
|
let indent = len(matchstr(substitute(line, '\t', softtab, 'g'), '^ *'))
|
||||||
if indent > 1 && get(options, 'shiftwidth', 99) > indent
|
if indent > 1 && get(options, 'shiftwidth', 99) > indent
|
||||||
|
@ -41,6 +45,15 @@ function! s:guess(lines) abort
|
||||||
|
|
||||||
endfor
|
endfor
|
||||||
|
|
||||||
|
if heuristics.hard && !heuristics.spaces
|
||||||
|
return {'expandtab': 0, 'shiftwidth': &tabstop}
|
||||||
|
elseif heuristics.soft != heuristics.hard
|
||||||
|
let options.expandtab = heuristics.soft > heuristics.spaces
|
||||||
|
if heuristics.hard
|
||||||
|
let options.tabstop = 8
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
return options
|
return options
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue