Compare commits

...

9 Commits

Author SHA1 Message Date
Adam Stankiewicz
29ec69ffa0 Set default tabstop to 2, but only if not changed 2020-10-23 01:04:53 +02:00
Adam Stankiewicz
6636144497 Prevent setting expandtab by default, closes #599 2020-10-23 00:56:41 +02:00
Adam Stankiewicz
2a205569eb Set only softtabstop, not tabstop, fixes #600 2020-10-23 00:51:16 +02:00
Adam Stankiewicz
114f731483 Add missing menu file, fixes #597 2020-10-21 14:26:54 +02:00
Adam Stankiewicz
4b8687ebca Fix deteting tab indents, closes #596 2020-10-21 14:23:28 +02:00
Adam Stankiewicz
78f6c8f318 Improve autoindent heuristics (count diff of multiple lines of same indent) 2020-10-19 20:33:52 +02:00
Adam Stankiewicz
86bf33aa3b Use conf for /etc/hosts, fixes #595 2020-10-19 19:49:44 +02:00
Adam Stankiewicz
b64fcedd82 Count only increments in indent, also respect ftplugin settings 2020-10-19 11:24:31 +02:00
Adam Stankiewicz
903793ac04 Improve indent heuristics (count increments / decrements), fixes #592 2020-10-19 11:00:16 +02:00
3 changed files with 1266 additions and 35 deletions

1199
extras/menu.vim Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -2545,7 +2545,7 @@ if !has_key(s:disabled_packages, 'alsaconf')
endif endif
if !has_key(s:disabled_packages, 'conf') if !has_key(s:disabled_packages, 'conf')
au BufNewFile,BufRead *.conf,auto.master,config setf conf au BufNewFile,BufRead *.conf,*/etc/hosts,auto.master,config setf conf
endif endif
if !has_key(s:disabled_packages, 'master') if !has_key(s:disabled_packages, 'master')
@@ -2634,7 +2634,23 @@ if !has_key(s:disabled_packages, 'autoindent')
" Code below re-implements sleuth for vim-polyglot " Code below re-implements sleuth for vim-polyglot
let g:loaded_sleuth = 1 let g:loaded_sleuth = 1
function! s:guess(lines) abort if &tabstop == 8
let &tabstop = 2
endif
func! s:get_shiftwidth(indents) abort
let shiftwidth = 0
let max_count = 0
for [indent, indent_count] in items(a:indents)
if indent_count > max_count
let shiftwidth = indent
let max_count = indent_count
endif
endfor
return shiftwidth
endfunc
func! s:guess(lines) abort
let options = {} let options = {}
let ccomment = 0 let ccomment = 0
let podcomment = 0 let podcomment = 0
@@ -2644,12 +2660,14 @@ if !has_key(s:disabled_packages, 'autoindent')
let heredoc = '' let heredoc = ''
let minindent = 10 let minindent = 10
let spaces_minus_tabs = 0 let spaces_minus_tabs = 0
let i = 0 let lineno = 0
let stack = [0]
let indents = { '2': 0, '3': 0, '4': 0, '6': 0, '8': 0 }
for line in a:lines for line in a:lines
let i += 1 let lineno += 1
if !len(line) || line =~# '^\S+$' if line =~# '^\s*$'
continue continue
endif endif
@@ -2713,51 +2731,64 @@ if !has_key(s:disabled_packages, 'autoindent')
let heredoc = herematch[1] . '$' let heredoc = herematch[1] . '$'
endif endif
let spaces_minus_tabs += line[0] == "\t" ? 1 : -1
if line[0] == "\t" if line[0] == "\t"
setlocal noexpandtab let spaces_minus_tabs -= 1
let &l:shiftwidth=&tabstop else
let b:sleuth_culprit .= ':' . i if line[0] == " "
return 1 let spaces_minus_tabs += 1
elseif line[0] == " " endif
let indent = len(matchstr(line, '^ *')) let indent = len(matchstr(line, '^ *'))
if indent < minindent && index([2, 3, 4, 6, 8], indent) >= 0 while stack[-1] > indent
let minindent = indent call remove(stack, -1)
endwhile
let indent_inc = indent - stack[-1]
if indent_inc == 0 && len(stack) > 1
let indent_inc = indent - stack[-2]
endif
if has_key(indents, indent_inc)
let indents[indent_inc] += 1
let prev_indent = indent
endif
if stack[-1] != indent
call add(stack, indent)
endif endif
endif endif
endfor endfor
if minindent < 10 if spaces_minus_tabs < 0
setlocal expandtab setlocal noexpandtab
let &l:shiftwidth=minindent let &l:shiftwidth=&tabstop
if &tabstop == 8 return 1
let &l:tabstop=minindent
endif endif
let b:sleuth_culprit .= ':' . i
let shiftwidth = s:get_shiftwidth(indents)
if shiftwidth > 0
setlocal expandtab
let &l:shiftwidth=shiftwidth
let &l:softtabstop=shiftwidth
return 1 return 1
endif endif
return 0 return 0
endfunction endfunc
function! s:detect_indent() abort func! s:detect_indent() abort
if &buftype ==# 'help' if &buftype ==# 'help'
return return
endif endif
if &expandtab " Do not autodetect indent if language sets it
" Make tabstop to be synchronized with shiftwidth by default if &l:shiftwidth != &g:shiftwidth
" Some plugins are using &shiftwidth directly or accessing &tabstop return
if &tabstop != 8 || &shiftwidth == 0
let &shiftwidth = &tabstop
else
let &tabstop = &shiftwidth
endif
endif endif
let b:sleuth_culprit = expand("<afile>:p") let b:sleuth_culprit = expand("<afile>:p")
if s:guess(getline(1, 32)) if s:guess(getline(1, 128))
return return
endif endif
if s:guess(getline(1, 1024)) if s:guess(getline(1, 1024))
@@ -2794,12 +2825,12 @@ if !has_key(s:disabled_packages, 'autoindent')
let level -= 1 let level -= 1
endwhile endwhile
unlet b:sleuth_culprit let b:sleuth_culprit = "default"
endfunction endfunc
set smarttab set smarttab
function! SleuthIndicator() abort func! SleuthIndicator() abort
let sw = &shiftwidth ? &shiftwidth : &tabstop let sw = &shiftwidth ? &shiftwidth : &tabstop
if &expandtab if &expandtab
return 'sw='.sw return 'sw='.sw
@@ -2808,7 +2839,7 @@ if !has_key(s:disabled_packages, 'autoindent')
else else
return 'sw='.sw.',ts='.&tabstop return 'sw='.sw.',ts='.&tabstop
endif endif
endfunction endfunc
augroup polyglot-sleuth augroup polyglot-sleuth
au! au!

View File

@@ -1958,6 +1958,7 @@ filetypes:
filenames: filenames:
- auto.master - auto.master
- config - config
- '*/etc/hosts'
--- ---
name: b name: b
remote: vim/vim:runtime remote: vim/vim:runtime