diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2020-11-14 23:16:01 +1300 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2020-11-14 23:16:01 +1300 |
commit | 96f46cae148517e4b8e8a5bbe13b623ddde6b705 (patch) | |
tree | 4d3282123c70620cb4d65311f52a0d0e6de78987 | |
parent | Merge branch 'hotfix/v0.1.3' (diff) | |
parent | Bump VERSION (diff) | |
download | vim-detect-indent-96f46cae148517e4b8e8a5bbe13b623ddde6b705.tar.gz vim-detect-indent-96f46cae148517e4b8e8a5bbe13b623ddde6b705.zip |
* hotfix/v0.1.4:
Avoid changing indent settings unnecessarily
-rw-r--r-- | VERSION | 2 | ||||
-rw-r--r-- | autoload/detect_indent.vim | 23 |
2 files changed, 12 insertions, 13 deletions
@@ -1 +1 @@ -0.1.3 +0.1.4 diff --git a/autoload/detect_indent.vim b/autoload/detect_indent.vim index ab3f485..bae5f7c 100644 --- a/autoload/detect_indent.vim +++ b/autoload/detect_indent.vim @@ -61,25 +61,20 @@ function! detect_indent#() abort endfor - " If the value for 'expandtab' as determined by the user's configuration - " matches the expected dominance of space-indented lines over tab-indented - " lines, we're already using the right setting, and we stop here - " - if &expandtab == (spaces['total'] >= tabs) - return - endif - - " If 'expandtab' is set, we need to unset it and switch to pure tab + " If 'expandtab' is set, but more lines in the existing buffer have tab + " indents than space indents, we need to unset it and switch to pure tab " indenting; that's straightforward, we just need to make sure 'shiftwidth' " matches 'tabstop', and that 'softtabstop' is off. " - if &expandtab + if &expandtab && tabs > spaces['total'] setlocal noexpandtab softtabstop=0 let &l:shiftwidth = &tabstop - " If 'expandtab' is not set, we need to set it, and guess an appropriate + " If 'expandtab' is unset, but more lines in the existing buffer have space + " indents than tab indents, we need to set it, and guess an appropriate " 'shiftwidth'. - else + " + elseif !&expandtab && tabs < spaces['total'] setlocal expandtab " Iterate through the keys of the histogram from smallest to largest. @@ -102,6 +97,10 @@ function! detect_indent#() abort let &l:shiftwidth = shiftwidth let &l:softtabstop = shiftwidth + " If the 'expandtab' setting looks like it was already accurate to the + " buffer, stop here + else + return endif " Since we just messed with indent settings, stack up a command to revert |