Add option to allow deleting trailing whitespace (#251)

Add option g:NERDTrimTrailingWhitespace to allow deleting trailing
whitespace when uncommenting a line.
This commit is contained in:
Alexandre Constantino
2016-06-10 15:49:17 +01:00
committed by Caleb Maclennan
parent e1aeec12be
commit e2d47bec26
3 changed files with 34 additions and 1 deletions

View File

@@ -64,6 +64,7 @@ call s:InitVariable("g:NERDRemoveExtraSpaces", 0)
call s:InitVariable("g:NERDRPlace", "<]")
call s:InitVariable("g:NERDSpaceDelims", 0)
call s:InitVariable("g:NERDDefaultAlign", "none")
call s:InitVariable("g:NERDTrimTrailingWhitespace", 0)
let s:NERDFileNameEscape="[]#*$%'\" ?`!&();<>\\"
@@ -1419,6 +1420,15 @@ function s:RecoverStateAfterLineComment(state)
endif
endfunction
" Function: s:TrimTrailingWhitespace(line) {{{2
" This function removes all the trailing whitespace
" Args:
" -line: the target line
function s:TrimTrailingWhitespace(line)
let toReturn = substitute(a:line, '\s\+$', '', 'g')
return toReturn
endfunction
" Function: s:UncommentLines(topLine, bottomLine) {{{2
" This function uncomments the given lines
"
@@ -1511,6 +1521,10 @@ function s:UncommentLinesSexy(topline, bottomline)
let theLine = s:ConvertLeadingWhiteSpace(theLine)
if g:NERDTrimTrailingWhitespace == 1
let theLine = s:TrimTrailingWhitespace(theLine)
endif
" move onto the next line
call setline(currentLine, theLine)
let currentLine = currentLine + 1
@@ -1652,6 +1666,10 @@ function s:UncommentLineNormal(line)
let line = s:ConvertLeadingWhiteSpace(line)
if g:NERDTrimTrailingWhitespace == 1
let line = s:TrimTrailingWhitespace(line)
endif
return line
endfunction