Skip to content

Commit

Permalink
Autodetect only 2, 3, 4, or 8 space indent, fixes #592
Browse files Browse the repository at this point in the history
  • Loading branch information
sheerun committed Oct 18, 2020
1 parent 6d7f437 commit 88cae16
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions ftdetect/polyglot.vim
Original file line number Diff line number Diff line change
Expand Up @@ -2629,11 +2629,6 @@ if !has_key(s:disabled_packages, 'autoindent')
" Code below re-implements sleuth for vim-polyglot
let g:loaded_sleuth = 1

" Makes shiftwidth to be synchronized with tabstop by default
if &shiftwidth == &tabstop
let &shiftwidth = 0
endif

function! s:guess(lines) abort
let options = {}
let ccomment = 0
Expand Down Expand Up @@ -2718,11 +2713,12 @@ if !has_key(s:disabled_packages, 'autoindent')
if line[0] == "\t"
setlocal noexpandtab
let &l:shiftwidth=&tabstop
let &l:tabstop=minindent
let b:sleuth_culprit .= ':' . i
return 1
elseif line[0] == " "
let indent = len(matchstr(line, '^ *'))
if (indent % 2 == 0 || indent % 3 == 0) && indent < minindent
if indent < minindent && index([2, 3, 4, 8], indent) >= 0
let minindent = indent
endif
endif
Expand All @@ -2731,6 +2727,7 @@ if !has_key(s:disabled_packages, 'autoindent')
if minindent < 10
setlocal expandtab
let &l:shiftwidth=minindent
let &l:tabstop=minindent
let b:sleuth_culprit .= ':' . i
return 1
endif
Expand All @@ -2743,6 +2740,16 @@ if !has_key(s:disabled_packages, 'autoindent')
return
endif

if &expandtab
" Make tabstop to be synchronized with shiftwidth by default
" Some plugins are using &shiftwidth directly or accessing &tabstop
if &tabstop != 8 || &shiftwidth == 0
let &shiftwidth = &tabstop
else
let &tabstop = &shiftwidth
endif
endif

let b:sleuth_culprit = expand("<afile>:p")
if s:guess(getline(1, 32))
return
Expand Down Expand Up @@ -2784,7 +2791,7 @@ if !has_key(s:disabled_packages, 'autoindent')
unlet b:sleuth_culprit
endfunction

setglobal smarttab
set smarttab

function! SleuthIndicator() abort
let sw = &shiftwidth ? &shiftwidth : &tabstop
Expand All @@ -2799,7 +2806,7 @@ if !has_key(s:disabled_packages, 'autoindent')

augroup polyglot-sleuth
au!
au FileType * call s:detect_indent()
au BufEnter * call s:detect_indent()
au User Flags call Hoist('buffer', 5, 'SleuthIndicator')
augroup END

Expand Down

0 comments on commit 88cae16

Please sign in to comment.