diff options
author | Adam Stankiewicz <sheerun@sher.pl> | 2020-10-19 20:32:40 +0200 |
---|---|---|
committer | Adam Stankiewicz <sheerun@sher.pl> | 2020-10-19 20:33:52 +0200 |
commit | 78f6c8f318ad6ce429877498271d968961a83481 (patch) | |
tree | f0f649ee8ecdf5b2cc7c533294ed11805fcf57f7 | |
parent | 86bf33aa3bdaa836fbd1537d1ba6a63b58b088bd (diff) | |
download | vim-polyglot-78f6c8f318ad6ce429877498271d968961a83481.tar.gz vim-polyglot-78f6c8f318ad6ce429877498271d968961a83481.zip |
Improve autoindent heuristics (count diff of multiple lines of same indent)
-rw-r--r-- | ftdetect/polyglot.vim | 27 |
1 files changed, 17 insertions, 10 deletions
diff --git a/ftdetect/polyglot.vim b/ftdetect/polyglot.vim index 02554c1f..29c13c35 100644 --- a/ftdetect/polyglot.vim +++ b/ftdetect/polyglot.vim @@ -2657,9 +2657,8 @@ if !has_key(s:disabled_packages, 'autoindent') let minindent = 10 let spaces_minus_tabs = 0 let lineno = 0 + let stack = [0] let indents = { '2': 0, '3': 0, '4': 0, '6': 0, '8': 0 } - let next_indent_lineno = 1 - let prev_indent = 0 for line in a:lines let lineno += 1 @@ -2733,16 +2732,24 @@ if !has_key(s:disabled_packages, 'autoindent') else let spaces_minus_tabs += 1 let indent = len(matchstr(line, '^ *')) - let indent_inc = indent - prev_indent + while stack[-1] > indent + call remove(stack, -1) + endwhile - if indent_inc > 0 && lineno == next_indent_lineno - if has_key(indents, indent_inc) - let indents[indent_inc] += 1 - endif + let indent_inc = indent - stack[-1] + + if indent_inc == 0 && len(stack) > 1 + let indent_inc = indent - stack[-2] endif - let next_indent_lineno = lineno + 1 - let prev_indent = indent + 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 endfor @@ -2777,7 +2784,7 @@ if !has_key(s:disabled_packages, 'autoindent') endif let b:sleuth_culprit = expand("<afile>:p") - if s:guess(getline(1, 64)) + if s:guess(getline(1, 128)) return endif if s:guess(getline(1, 1024)) |