Enable TrimTrailingWhitespace when commenting (#264)

Previously the `NERDTrimTrailingWhitespace` option was only evaluated when uncommenting a line. However sometimes trailing whitespace was being added when commenting, notably when commenting empty lines. This checks for and removes such space at comment time.
This commit is contained in:
Caleb Maclennan 2016-08-31 11:42:37 +03:00 committed by GitHub
commit fdc611c8f4

View File

@ -746,6 +746,10 @@ function s:CommentBlock(top, bottom, lSide, rSide, forceNested )
let theLine = s:ConvertLeadingSpacesToTabs(theLine)
endif
if g:NERDTrimTrailingWhitespace == 1
let theLine = s:TrimTrailingWhitespace(theLine)
endif
call setline(currentLine, theLine)
endif
@ -816,6 +820,10 @@ function s:CommentLines(forceNested, align, firstLine, lastLine)
let theLine = s:ConvertLeadingSpacesToTabs(theLine)
endif
if g:NERDTrimTrailingWhitespace == 1
let theLine = s:TrimTrailingWhitespace(theLine)
endif
" we are done with this line
call setline(currentLine, theLine)
let currentLine = currentLine + 1
@ -876,6 +884,11 @@ function s:CommentLinesMinimal(firstLine, lastLine)
if lineHasLeadingTabs
let theLine = s:ConvertLeadingSpacesToTabs(theLine)
endif
if g:NERDTrimTrailingWhitespace == 1
let theLine = s:TrimTrailingWhitespace(theLine)
endif
call setline(a:lastLine, theLine)
endfunction
@ -995,6 +1008,9 @@ function s:CommentLinesSexy(topline, bottomline)
let theLine = s:ConvertLeadingSpacesToTabs(theLine)
endif
if g:NERDTrimTrailingWhitespace == 1
let theLine = s:TrimTrailingWhitespace(theLine)
endif
" set the line and move onto the next one
call setline(currentLine, theLine)
@ -1049,6 +1065,10 @@ function s:CommentLinesToggle(forceNested, firstLine, lastLine)
let theLine = s:ConvertLeadingSpacesToTabs(theLine)
endif
if g:NERDTrimTrailingWhitespace == 1
let theLine = s:TrimTrailingWhitespace(theLine)
endif
" we are done with this line
call setline(currentLine, theLine)
let currentLine = currentLine + 1