From b6dae9abfc50d8a0cdde55b2fa92e679b45e0d39 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Fri, 20 Jul 2018 21:59:09 +1200 Subject: Don't report deleted lines as trimmed --- plugin/strip_trailing_whitespace.vim | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'plugin') 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) -- cgit v1.2.3