diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2018-07-20 22:00:00 +1200 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2018-07-20 22:00:00 +1200 |
commit | 77148fa855e7b1095e70819d03517ede42e68fcb (patch) | |
tree | 826539d63cae879ffbe45e1519336cdd73558d97 | |
parent | Merge branch 'hotfix/v2.0.1' (diff) | |
parent | Bump VERSION (diff) | |
download | vim-strip-trailing-whitespace-2.0.2.tar.gz (sig) vim-strip-trailing-whitespace-2.0.2.zip |
Merge branch 'hotfix/v2.0.2'v2.0.2
* hotfix/v2.0.2:
Bump VERSION
Don't report deleted lines as trimmed
-rw-r--r-- | VERSION | 2 | ||||
-rw-r--r-- | plugin/strip_trailing_whitespace.vim | 20 |
2 files changed, 14 insertions, 8 deletions
@@ -1 +1 @@ -2.0.1 +2.0.2 diff --git a/plugin/strip_trailing_whitespace.vim b/plugin/strip_trailing_whitespace.vim index ed9ad66..207863a 100644 --- a/plugin/strip_trailing_whitespace.vim +++ b/plugin/strip_trailing_whitespace.vim @@ -22,22 +22,28 @@ function s:Strip(start, end) abort let l:line = line('.') let l:col = col('.') - " Strip horizontal space - let l:horizontal = s:StripHorizontal(a:start, a:end) - let l:msg = l:horizontal.' trimmed' - let l:changed = l:horizontal > 0 + " Whether we made changes + let l:changed = 0 - " If we're going to the end, strip vertical space + " If we're going to the end, strip vertical space; we do this first so we + " don't end up reporting having trimmed lines that we deleted if a:end == line('$') let l:vertical = s:StripVertical() - let l:msg = l:msg.', '.l:vertical.' deleted' let l:changed = l:changed || l:vertical > 0 endif + " Strip horizontal space + let l:horizontal = s:StripHorizontal(a:start, a:end) + let l:changed = l:changed || l:horizontal > 0 + " Return the cursor call s:Cursor(l:line, l:col) " Report what changed + let l:msg = l:horizontal.' trimmed' + if exists('l:vertical') + let l:msg = l:msg.', '.l:vertical.' deleted' + endif echomsg l:msg " Return whether anything changed @@ -53,7 +59,7 @@ function s:StripHorizontal(start, end) abort " Iterate through buffer let l:num = a:start - while l:num <= a:end + while l:num <= line('$') && l:num <= a:end " If the line has trailing whitespace, strip it off and bump the count let l:line = getline(l:num) |