summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Stankiewicz <sheerun@sher.pl>2020-10-18 23:57:00 +0200
committerAdam Stankiewicz <sheerun@sher.pl>2020-10-18 23:57:00 +0200
commit88cae16fcad307d2a2c6d7f7ba6e4aecb1c8de0b (patch)
tree24adad0ef10133ad9230603d9958979a9e336ec5
parent6d7f437b84aa76e5a69d420565123f75b040f836 (diff)
downloadvim-polyglot-88cae16fcad307d2a2c6d7f7ba6e4aecb1c8de0b.tar.gz
vim-polyglot-88cae16fcad307d2a2c6d7f7ba6e4aecb1c8de0b.zip
Autodetect only 2, 3, 4, or 8 space indent, fixes #592
-rw-r--r--ftdetect/polyglot.vim23
1 files changed, 15 insertions, 8 deletions
diff --git a/ftdetect/polyglot.vim b/ftdetect/polyglot.vim
index 73d2e385..747c79d2 100644
--- a/ftdetect/polyglot.vim
+++ b/ftdetect/polyglot.vim
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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