mirror of
https://github.com/preservim/nerdcommenter.git
synced 2024-12-05 07:24:18 +08:00
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:
commit
fdc611c8f4
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user