diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2020-11-14 23:14:36 +1300 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2020-11-14 23:14:36 +1300 |
commit | e97d0fda6017b69effe8a56016bd5765293c951f (patch) | |
tree | 4dfbec7cd9f25eda0f05b8db484b4bb8b139fd65 | |
parent | Merge branch 'hotfix/v0.1.3' (diff) | |
download | vim-detect-indent-e97d0fda6017b69effe8a56016bd5765293c951f.tar.gz vim-detect-indent-e97d0fda6017b69effe8a56016bd5765293c951f.zip |
Avoid changing indent settings unnecessarily
-rw-r--r-- | autoload/detect_indent.vim | 23 |
1 files changed, 11 insertions, 12 deletions
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 |