Fix lint warning: use robust operators

This commit is contained in:
Caleb Maclennan
2019-12-30 11:02:22 +03:00
parent ac3db1e70a
commit 277986725d

View File

@@ -528,7 +528,7 @@ function s:SetUpForNewFiletype(filetype, forceReset)
"for compound filetypes, if we don't know how to handle the full filetype "for compound filetypes, if we don't know how to handle the full filetype
"then break it down and use the first part that we know how to handle "then break it down and use the first part that we know how to handle
if ft =~ '\.' && !has_key(s:delimiterMap, ft) if ft =~# '\.' && !has_key(s:delimiterMap, ft)
let filetypes = split(a:filetype, '\.') let filetypes = split(a:filetype, '\.')
for i in filetypes for i in filetypes
if has_key(s:delimiterMap, i) if has_key(s:delimiterMap, i)
@@ -565,7 +565,7 @@ function s:SetUpForNewFiletype(filetype, forceReset)
endfunction endfunction
function s:CreateDelimMapFromCms() function s:CreateDelimMapFromCms()
if &ft == '' && exists('g:NERDDefaultDelims') if &ft ==# '' && exists('g:NERDDefaultDelims')
let delims = g:NERDDefaultDelims let delims = g:NERDDefaultDelims
for i in ['left', 'leftAlt', 'right', 'rightAlt'] for i in ['left', 'leftAlt', 'right', 'rightAlt']
if !has_key(delims, i) if !has_key(delims, i)
@@ -598,7 +598,7 @@ function s:SwitchToAlternativeDelimiters(printMsgs)
endif endif
"if both of the alternative delimiters are empty then there is no "if both of the alternative delimiters are empty then there is no
"alternative comment style so bail out "alternative comment style so bail out
if b:NERDCommenterDelims['leftAlt'] == '' && b:NERDCommenterDelims['rightAlt'] == '' if b:NERDCommenterDelims['leftAlt'] ==# '' && b:NERDCommenterDelims['rightAlt'] ==# ''
if a:printMsgs if a:printMsgs
call s:NerdEcho('Cannot use alternative delimiters, none are specified', 0) call s:NerdEcho('Cannot use alternative delimiters, none are specified', 0)
endif endif
@@ -645,8 +645,8 @@ function s:AppendCommentToLine()
" get the length of the right delimiter " get the length of the right delimiter
let lenRight = strlen(right) let lenRight = strlen(right)
let isLineEmpty = strlen(getline('.')) == 0 let isLineEmpty = strlen(getline('.')) ==# 0
let insOrApp = (isLineEmpty==1 ? 'i' : 'A') let insOrApp = (isLineEmpty==#1 ? 'i' : 'A')
"stick the delimiters down at the end of the line. We have to format the "stick the delimiters down at the end of the line. We have to format the
"comment with spaces as appropriate "comment with spaces as appropriate
@@ -740,7 +740,7 @@ function s:CommentBlock(top, bottom, lSide, rSide, forceNested )
"don't comment lines that begin after the right boundary of the "don't comment lines that begin after the right boundary of the
"block unless the user has specified to do so "block unless the user has specified to do so
if theLine !~ '^ \{' . rSide . '\}' || !g:NERDBlockComIgnoreEmpty if theLine !~# '^ \{' . rSide . '\}' || !g:NERDBlockComIgnoreEmpty
"attempt to place the cursor in on the left of the boundary box, "attempt to place the cursor in on the left of the boundary box,
"then check if we were successful, if not then we cant comment this "then check if we were successful, if not then we cant comment this
@@ -761,7 +761,7 @@ function s:CommentBlock(top, bottom, lSide, rSide, forceNested )
let firstLeftDelim = s:FindDelimiterIndex(s:Left(), theLine) let firstLeftDelim = s:FindDelimiterIndex(s:Left(), theLine)
let lastRightDelim = s:LastIndexOfDelim(s:Right(), theLine) let lastRightDelim = s:LastIndexOfDelim(s:Right(), theLine)
if firstLeftDelim != -1 && lastRightDelim != -1 if firstLeftDelim !=# -1 && lastRightDelim !=# -1
let searchStr = strpart(theLine, 0, lastRightDelim) let searchStr = strpart(theLine, 0, lastRightDelim)
let searchStr = strpart(searchStr, firstLeftDelim+strlen(s:Left())) let searchStr = strpart(searchStr, firstLeftDelim+strlen(s:Left()))
@@ -781,7 +781,7 @@ function s:CommentBlock(top, bottom, lSide, rSide, forceNested )
let theLine = s:ConvertLeadingSpacesToTabs(theLine) let theLine = s:ConvertLeadingSpacesToTabs(theLine)
endif endif
if g:NERDTrimTrailingWhitespace == 1 if g:NERDTrimTrailingWhitespace ==# 1
let theLine = s:TrimTrailingWhitespace(theLine) let theLine = s:TrimTrailingWhitespace(theLine)
endif endif
@@ -792,7 +792,7 @@ function s:CommentBlock(top, bottom, lSide, rSide, forceNested )
endwhile endwhile
"if we switched delimiterss then we gotta go back to what they were before "if we switched delimiterss then we gotta go back to what they were before
if switchedDelims == 1 if switchedDelims ==# 1
call s:SwitchToAlternativeDelimiters(0) call s:SwitchToAlternativeDelimiters(0)
endif endif
endfunction endfunction
@@ -809,7 +809,7 @@ function s:CommentLines(forceNested, align, firstLine, lastLine)
" we need to get the left and right indexes of the leftmost char in the " we need to get the left and right indexes of the leftmost char in the
" block of of lines and the right most char so that we can do alignment of " block of of lines and the right most char so that we can do alignment of
" the delimiters if the user has specified " the delimiters if the user has specified
let leftAlignIndx = a:align == 'start' ? 0 : s:LeftMostIndx(a:forceNested, 0, a:firstLine, a:lastLine) let leftAlignIndx = a:align ==# 'start' ? 0 : s:LeftMostIndx(a:forceNested, 0, a:firstLine, a:lastLine)
let rightAlignIndx = s:RightMostIndx(a:forceNested, 0, a:firstLine, a:lastLine) let rightAlignIndx = s:RightMostIndx(a:forceNested, 0, a:firstLine, a:lastLine)
" gotta add the length of the left delimiter onto the rightAlignIndx cos " gotta add the length of the left delimiter onto the rightAlignIndx cos
@@ -837,12 +837,12 @@ function s:CommentLines(forceNested, align, firstLine, lastLine)
" check if we can comment this line " check if we can comment this line
if !isCommented || g:NERDUsePlaceHolders || s:Multipart() if !isCommented || g:NERDUsePlaceHolders || s:Multipart()
if a:align == 'left' || a:align == 'start' || a:align == 'both' if a:align ==# 'left' || a:align ==# 'start' || a:align ==# 'both'
let theLine = s:AddLeftDelimAligned(s:Left({'space': 1}), theLine, leftAlignIndx) let theLine = s:AddLeftDelimAligned(s:Left({'space': 1}), theLine, leftAlignIndx)
else else
let theLine = s:AddLeftDelim(s:Left({'space': 1}), theLine) let theLine = s:AddLeftDelim(s:Left({'space': 1}), theLine)
endif endif
if a:align == 'both' if a:align ==# 'both'
let theLine = s:AddRightDelimAligned(s:Right({'space': 1}), theLine, rightAlignIndx) let theLine = s:AddRightDelimAligned(s:Right({'space': 1}), theLine, rightAlignIndx)
else else
let theLine = s:AddRightDelim(s:Right({'space': 1}), theLine) let theLine = s:AddRightDelim(s:Right({'space': 1}), theLine)
@@ -855,7 +855,7 @@ function s:CommentLines(forceNested, align, firstLine, lastLine)
let theLine = s:ConvertLeadingSpacesToTabs(theLine) let theLine = s:ConvertLeadingSpacesToTabs(theLine)
endif endif
if g:NERDTrimTrailingWhitespace == 1 if g:NERDTrimTrailingWhitespace ==# 1
let theLine = s:TrimTrailingWhitespace(theLine) let theLine = s:TrimTrailingWhitespace(theLine)
endif endif
@@ -920,7 +920,7 @@ function s:CommentLinesMinimal(firstLine, lastLine)
let theLine = s:ConvertLeadingSpacesToTabs(theLine) let theLine = s:ConvertLeadingSpacesToTabs(theLine)
endif endif
if g:NERDTrimTrailingWhitespace == 1 if g:NERDTrimTrailingWhitespace ==# 1
let theLine = s:TrimTrailingWhitespace(theLine) let theLine = s:TrimTrailingWhitespace(theLine)
endif endif
@@ -940,7 +940,7 @@ function s:CommentLinesSexy(topline, bottomline)
let right = s:GetSexyComRight(0, 0) let right = s:GetSexyComRight(0, 0)
"check if we can do a sexy comment with the available delimiters "check if we can do a sexy comment with the available delimiters
if left == -1 || right == -1 if left ==# -1 || right ==# -1
throw 'NERDCommenter.Delimiters exception: cannot perform sexy comments with available delimiters.' throw 'NERDCommenter.Delimiters exception: cannot perform sexy comments with available delimiters.'
endif endif
@@ -979,7 +979,7 @@ function s:CommentLinesSexy(topline, bottomline)
call setline(a:topline, theLine) call setline(a:topline, theLine)
"comment the bottom line "comment the bottom line
if a:bottomline != a:topline if a:bottomline !=# a:topline
let theLine = getline(a:bottomline) let theLine = getline(a:bottomline)
let lineHasTabs = s:HasLeadingTabs(theLine) let lineHasTabs = s:HasLeadingTabs(theLine)
if lineHasTabs if lineHasTabs
@@ -1051,7 +1051,7 @@ function s:CommentLinesSexy(topline, bottomline)
let theLine = s:ConvertLeadingSpacesToTabs(theLine) let theLine = s:ConvertLeadingSpacesToTabs(theLine)
endif endif
if g:NERDTrimTrailingWhitespace == 1 if g:NERDTrimTrailingWhitespace ==# 1
let theLine = s:TrimTrailingWhitespace(theLine) let theLine = s:TrimTrailingWhitespace(theLine)
endif endif
@@ -1073,7 +1073,7 @@ function s:CommentLinesToggle(forceNested, firstLine, lastLine)
let currentLine = a:firstLine let currentLine = a:firstLine
let align = g:NERDDefaultAlign let align = g:NERDDefaultAlign
let leftAlignIndx = align == 'start' ? 0 : s:LeftMostIndx(a:forceNested, 0, a:firstLine, a:lastLine) let leftAlignIndx = align ==# 'start' ? 0 : s:LeftMostIndx(a:forceNested, 0, a:firstLine, a:lastLine)
let rightAlignIndx = s:RightMostIndx(a:forceNested, 0, a:firstLine, a:lastLine) let rightAlignIndx = s:RightMostIndx(a:forceNested, 0, a:firstLine, a:lastLine)
let rightAlignIndx = rightAlignIndx + strlen(s:Left({'space': 1})) let rightAlignIndx = rightAlignIndx + strlen(s:Left({'space': 1}))
@@ -1091,12 +1091,12 @@ function s:CommentLinesToggle(forceNested, firstLine, lastLine)
let theLine = s:SwapOuterMultiPartDelimsForPlaceHolders(theLine) let theLine = s:SwapOuterMultiPartDelimsForPlaceHolders(theLine)
endif endif
if align == 'left' || align == 'start' || align == 'both' if align ==# 'left' || align ==# 'start' || align ==# 'both'
let theLine = s:AddLeftDelimAligned(s:Left({'space': 1}), theLine, leftAlignIndx) let theLine = s:AddLeftDelimAligned(s:Left({'space': 1}), theLine, leftAlignIndx)
else else
let theLine = s:AddLeftDelim(s:Left({'space': 1}), theLine) let theLine = s:AddLeftDelim(s:Left({'space': 1}), theLine)
endif endif
if align == 'both' if align ==# 'both'
let theLine = s:AddRightDelimAligned(s:Right({'space': 1}), theLine, rightAlignIndx) let theLine = s:AddRightDelimAligned(s:Right({'space': 1}), theLine, rightAlignIndx)
else else
let theLine = s:AddRightDelim(s:Right({'space': 1}), theLine) let theLine = s:AddRightDelim(s:Right({'space': 1}), theLine)
@@ -1108,7 +1108,7 @@ function s:CommentLinesToggle(forceNested, firstLine, lastLine)
let theLine = s:ConvertLeadingSpacesToTabs(theLine) let theLine = s:ConvertLeadingSpacesToTabs(theLine)
endif endif
if g:NERDTrimTrailingWhitespace == 1 if g:NERDTrimTrailingWhitespace ==# 1
let theLine = s:TrimTrailingWhitespace(theLine) let theLine = s:TrimTrailingWhitespace(theLine)
endif endif
@@ -1139,7 +1139,7 @@ function s:CommentRegion(topLine, topCol, bottomLine, bottomCol, forceNested)
endif endif
"if there is only one line in the comment then just do it "if there is only one line in the comment then just do it
if a:topLine == a:bottomLine if a:topLine ==# a:bottomLine
call s:CommentBlock(a:topLine, a:bottomLine, a:topCol, a:bottomCol, a:forceNested) call s:CommentBlock(a:topLine, a:bottomLine, a:topCol, a:bottomCol, a:forceNested)
"there are multiple lines in the comment "there are multiple lines in the comment
@@ -1165,7 +1165,7 @@ function s:CommentRegion(topLine, topCol, bottomLine, bottomCol, forceNested)
call cursor(a:topLine, a:topCol + strlen(s:Left()) + g:NERDSpaceDelims) call cursor(a:topLine, a:topCol + strlen(s:Left()) + g:NERDSpaceDelims)
"if we switched delimiters then we gotta go back to what they were before "if we switched delimiters then we gotta go back to what they were before
if switchedDelims == 1 if switchedDelims ==# 1
call s:SwitchToAlternativeDelimiters(0) call s:SwitchToAlternativeDelimiters(0)
endif endif
@@ -1228,9 +1228,9 @@ function! NERDComment(mode, type) range
exe 'call NERDCommenter_before()' exe 'call NERDCommenter_before()'
endif endif
let isVisual = a:mode =~ '[vsx]' let isVisual = a:mode =~# '[vsx]'
if !exists('g:did_load_ftplugin') || g:did_load_ftplugin != 1 if !exists('g:did_load_ftplugin') || g:did_load_ftplugin !=# 1
call s:NerdEcho('filetype plugins should be enabled. See :help NERDComInstallation and :help :filetype-plugin-on', 0) call s:NerdEcho('filetype plugins should be enabled. See :help NERDComInstallation and :help :filetype-plugin-on', 0)
endif endif
@@ -1238,7 +1238,7 @@ function! NERDComment(mode, type) range
let firstLine = line("'<") let firstLine = line("'<")
let lastLine = line("'>") let lastLine = line("'>")
let firstCol = col("'<") let firstCol = col("'<")
let lastCol = col("'>") - (&selection == 'exclusive' ? 1 : 0) let lastCol = col("'>") - (&selection ==# 'exclusive' ? 1 : 0)
else else
let firstLine = a:firstline let firstLine = a:firstline
let lastLine = a:lastline let lastLine = a:lastline
@@ -1247,14 +1247,14 @@ function! NERDComment(mode, type) range
" Save options we need to change so we can recover them later " Save options we need to change so we can recover them later
let state = s:SetupStateBeforeLineComment(firstLine, lastLine) let state = s:SetupStateBeforeLineComment(firstLine, lastLine)
let countWasGiven = (!isVisual && firstLine != lastLine) let countWasGiven = (!isVisual && firstLine !=# lastLine)
let forceNested = (a:type ==? 'Nested' || g:NERDDefaultNesting) let forceNested = (a:type ==? 'Nested' || g:NERDDefaultNesting)
if a:type ==? 'Comment' || a:type ==? 'Nested' if a:type ==? 'Comment' || a:type ==? 'Nested'
if isVisual && visualmode() == "\<C-V>" if isVisual && visualmode() ==# "\<C-V>"
call s:CommentBlock(firstLine, lastLine, firstCol, lastCol, forceNested) call s:CommentBlock(firstLine, lastLine, firstCol, lastCol, forceNested)
elseif isVisual && visualmode() == 'v' && (g:NERDCommentWholeLinesInVMode==0 || (g:NERDCommentWholeLinesInVMode==2 && s:HasMultipartDelims())) elseif isVisual && visualmode() ==# 'v' && (g:NERDCommentWholeLinesInVMode==#0 || (g:NERDCommentWholeLinesInVMode==#2 && s:HasMultipartDelims()))
call s:CommentRegion(firstLine, firstCol, lastLine, lastCol, forceNested) call s:CommentRegion(firstLine, firstCol, lastLine, lastCol, forceNested)
else else
call s:CommentLines(forceNested, g:NERDDefaultAlign, firstLine, lastLine) call s:CommentLines(forceNested, g:NERDDefaultAlign, firstLine, lastLine)
@@ -1294,7 +1294,7 @@ function! NERDComment(mode, type) range
for i in range(firstLine, lastLine) for i in range(firstLine, lastLine)
let theLine = getline(i) let theLine = getline(i)
" if have one line no comment(not include blank/whitespace-only lines), then comment all lines " if have one line no comment(not include blank/whitespace-only lines), then comment all lines
if theLine =~ '[^ \t]\+' && !s:IsInSexyComment(firstLine) && !s:IsCommentedFromStartOfLine(s:Left(), theLine) && !s:IsCommentedFromStartOfLine(s:Left({'alt': 1}), theLine) if theLine =~# '[^ \t]\+' && !s:IsInSexyComment(firstLine) && !s:IsCommentedFromStartOfLine(s:Left(), theLine) && !s:IsCommentedFromStartOfLine(s:Left({'alt': 1}), theLine)
let l:commentAllLines = 1 let l:commentAllLines = 1
break break
else else
@@ -1365,7 +1365,7 @@ function s:PlaceDelimitersAndInsBetween()
let right = s:Right({'space': 1}) let right = s:Right({'space': 1})
let theLine = getline('.') let theLine = getline('.')
let lineHasLeadTabs = s:HasLeadingTabs(theLine) || (theLine =~ '^ *$' && !&expandtab) let lineHasLeadTabs = s:HasLeadingTabs(theLine) || (theLine =~# '^ *$' && !&expandtab)
"convert tabs to spaces and adjust the cursors column to take this into "convert tabs to spaces and adjust the cursors column to take this into
"account "account
@@ -1400,7 +1400,7 @@ function s:PlaceDelimitersAndInsBetween()
call cursor(line('.'), tabbedCol) call cursor(line('.'), tabbedCol)
endif endif
if isDelimOnEOL && lenRight == 0 if isDelimOnEOL && lenRight ==# 0
startinsert! startinsert!
else else
startinsert startinsert
@@ -1431,24 +1431,24 @@ function s:RemoveDelimiters(left, right, line)
"look for the left delimiter, if we find it, remove it. "look for the left delimiter, if we find it, remove it.
let leftIndx = s:FindDelimiterIndex(a:left, line) let leftIndx = s:FindDelimiterIndex(a:left, line)
if leftIndx != -1 if leftIndx !=# -1
let line = strpart(line, 0, leftIndx) . strpart(line, leftIndx+lenLeft) let line = strpart(line, 0, leftIndx) . strpart(line, leftIndx+lenLeft)
"if the user has specified that there is a space after the left delimiter "if the user has specified that there is a space after the left delimiter
"then check for the space and remove it if it is there "then check for the space and remove it if it is there
if delimsSpaced && strpart(line, leftIndx, s:lenSpaceStr) == s:spaceStr if delimsSpaced && strpart(line, leftIndx, s:lenSpaceStr) ==# s:spaceStr
let line = strpart(line, 0, leftIndx) . strpart(line, leftIndx+s:lenSpaceStr) let line = strpart(line, 0, leftIndx) . strpart(line, leftIndx+s:lenSpaceStr)
endif endif
endif endif
"look for the right delimiter, if we find it, remove it "look for the right delimiter, if we find it, remove it
let rightIndx = s:LastIndexOfDelim(a:right, line) let rightIndx = s:LastIndexOfDelim(a:right, line)
if rightIndx != -1 if rightIndx !=# -1
let line = strpart(line, 0, rightIndx) . strpart(line, rightIndx+lenRight) let line = strpart(line, 0, rightIndx) . strpart(line, rightIndx+lenRight)
"if the user has specified that there is a space before the right delimiter "if the user has specified that there is a space before the right delimiter
"then check for the space and remove it if it is there "then check for the space and remove it if it is there
if delimsSpaced && strpart(line, rightIndx-s:lenSpaceStr, s:lenSpaceStr) == s:spaceStr && (s:Multipart() || s:AltMultipart()) if delimsSpaced && strpart(line, rightIndx-s:lenSpaceStr, s:lenSpaceStr) ==# s:spaceStr && (s:Multipart() || s:AltMultipart())
let line = strpart(line, 0, rightIndx-s:lenSpaceStr) . strpart(line, rightIndx) let line = strpart(line, 0, rightIndx-s:lenSpaceStr) . strpart(line, rightIndx)
endif endif
endif endif
@@ -1475,7 +1475,7 @@ function s:SetupStateBeforeLineComment(topLine, bottomLine)
" manual, do the commenting stuff and recover it later. To avoid slowing " manual, do the commenting stuff and recover it later. To avoid slowing
" down commenting few lines, we avoid doing this for ranges smaller than " down commenting few lines, we avoid doing this for ranges smaller than
" 10 lines " 10 lines
if a:bottomLine - a:topLine >= 10 && &foldmethod != 'manual' if a:bottomLine - a:topLine >= 10 && &foldmethod !=# 'manual'
set foldmethod=manual set foldmethod=manual
endif endif
@@ -1493,10 +1493,10 @@ endfunction
" state: the top line of the visual selection to uncomment " state: the top line of the visual selection to uncomment
" bottomLine: the bottom line of the visual selection to uncomment " bottomLine: the bottom line of the visual selection to uncomment
function s:RecoverStateAfterLineComment(state) function s:RecoverStateAfterLineComment(state)
if a:state['foldmethod'] != &foldmethod if a:state['foldmethod'] !=# &foldmethod
let &foldmethod = a:state['foldmethod'] let &foldmethod = a:state['foldmethod']
endif endif
if a:state['ignorecase'] != &ignorecase if a:state['ignorecase'] !=# &ignorecase
let &ignorecase = a:state['ignorecase'] let &ignorecase = a:state['ignorecase']
endif endif
endfunction endfunction
@@ -1568,7 +1568,7 @@ function s:UncommentLinesSexy(topline, bottomline)
"check if it is even possible for sexy comments to exist with the "check if it is even possible for sexy comments to exist with the
"available delimiters "available delimiters
if left == -1 || right == -1 if left ==# -1 || right ==# -1
throw 'NERDCommenter.Delimiters exception: cannot uncomment sexy comments with available delimiters.' throw 'NERDCommenter.Delimiters exception: cannot uncomment sexy comments with available delimiters.'
endif endif
@@ -1592,7 +1592,7 @@ function s:UncommentLinesSexy(topline, bottomline)
" remove the sexy comment marker from the line. We also remove the " remove the sexy comment marker from the line. We also remove the
" space after it if there is one and if appropriate options are set " space after it if there is one and if appropriate options are set
let sexyComMarkerIndx = stridx(theLine, sexyComMarkerUnEsc) let sexyComMarkerIndx = stridx(theLine, sexyComMarkerUnEsc)
if strpart(theLine, sexyComMarkerIndx+strlen(sexyComMarkerUnEsc), s:lenSpaceStr) == s:spaceStr && g:NERDSpaceDelims if strpart(theLine, sexyComMarkerIndx+strlen(sexyComMarkerUnEsc), s:lenSpaceStr) ==# s:spaceStr && g:NERDSpaceDelims
let theLine = strpart(theLine, 0, sexyComMarkerIndx - markerOffset) . strpart(theLine, sexyComMarkerIndx+strlen(sexyComMarkerUnEsc)+s:lenSpaceStr) let theLine = strpart(theLine, 0, sexyComMarkerIndx - markerOffset) . strpart(theLine, sexyComMarkerIndx+strlen(sexyComMarkerUnEsc)+s:lenSpaceStr)
else else
let theLine = strpart(theLine, 0, sexyComMarkerIndx - markerOffset) . strpart(theLine, sexyComMarkerIndx+strlen(sexyComMarkerUnEsc)) let theLine = strpart(theLine, 0, sexyComMarkerIndx - markerOffset) . strpart(theLine, sexyComMarkerIndx+strlen(sexyComMarkerUnEsc))
@@ -1602,7 +1602,7 @@ function s:UncommentLinesSexy(topline, bottomline)
let theLine = s:ConvertLeadingWhiteSpace(theLine) let theLine = s:ConvertLeadingWhiteSpace(theLine)
if g:NERDTrimTrailingWhitespace == 1 if g:NERDTrimTrailingWhitespace ==# 1
let theLine = s:TrimTrailingWhitespace(theLine) let theLine = s:TrimTrailingWhitespace(theLine)
endif endif
@@ -1619,7 +1619,7 @@ function s:UncommentLinesSexy(topline, bottomline)
let theLine = getline(a:topline) let theLine = getline(a:topline)
" if the first line contains only the left delimiter then just delete it " if the first line contains only the left delimiter then just delete it
if theLine =~ '^[ \t]*' . left . '[ \t]*$' && !g:NERDCompactSexyComs if theLine =~# '^[ \t]*' . left . '[ \t]*$' && !g:NERDCompactSexyComs
call cursor(a:topline, 1) call cursor(a:topline, 1)
normal! dd normal! dd
let bottomline = bottomline - 1 let bottomline = bottomline - 1
@@ -1630,7 +1630,7 @@ function s:UncommentLinesSexy(topline, bottomline)
" remove the delimiter. If there is a space after it " remove the delimiter. If there is a space after it
" then remove this too if appropriate " then remove this too if appropriate
let delimIndx = stridx(theLine, leftUnEsc) let delimIndx = stridx(theLine, leftUnEsc)
if strpart(theLine, delimIndx+strlen(leftUnEsc), s:lenSpaceStr) == s:spaceStr && g:NERDSpaceDelims if strpart(theLine, delimIndx+strlen(leftUnEsc), s:lenSpaceStr) ==# s:spaceStr && g:NERDSpaceDelims
let theLine = strpart(theLine, 0, delimIndx) . strpart(theLine, delimIndx+strlen(leftUnEsc)+s:lenSpaceStr) let theLine = strpart(theLine, 0, delimIndx) . strpart(theLine, delimIndx+strlen(leftUnEsc)+s:lenSpaceStr)
else else
let theLine = strpart(theLine, 0, delimIndx) . strpart(theLine, delimIndx+strlen(leftUnEsc)) let theLine = strpart(theLine, 0, delimIndx) . strpart(theLine, delimIndx+strlen(leftUnEsc))
@@ -1643,7 +1643,7 @@ function s:UncommentLinesSexy(topline, bottomline)
let theLine = getline(bottomline) let theLine = getline(bottomline)
" if the bottomline contains only the right delimiter then just delete it " if the bottomline contains only the right delimiter then just delete it
if theLine =~ '^[ \t]*' . right . '[ \t]*$' if theLine =~# '^[ \t]*' . right . '[ \t]*$'
call cursor(bottomline, 1) call cursor(bottomline, 1)
normal! dd normal! dd
@@ -1652,7 +1652,7 @@ function s:UncommentLinesSexy(topline, bottomline)
" remove the right delimiter. If there is a space after it and " remove the right delimiter. If there is a space after it and
" if the appropriate options are set then remove this too. " if the appropriate options are set then remove this too.
let delimIndx = s:LastIndexOfDelim(rightUnEsc, theLine) let delimIndx = s:LastIndexOfDelim(rightUnEsc, theLine)
if strpart(theLine, delimIndx+strlen(leftUnEsc), s:lenSpaceStr) == s:spaceStr && g:NERDSpaceDelims if strpart(theLine, delimIndx+strlen(leftUnEsc), s:lenSpaceStr) ==# s:spaceStr && g:NERDSpaceDelims
let theLine = strpart(theLine, 0, delimIndx) . strpart(theLine, delimIndx+strlen(rightUnEsc)+s:lenSpaceStr) let theLine = strpart(theLine, 0, delimIndx) . strpart(theLine, delimIndx+strlen(rightUnEsc)+s:lenSpaceStr)
else else
let theLine = strpart(theLine, 0, delimIndx) . strpart(theLine, delimIndx+strlen(rightUnEsc)) let theLine = strpart(theLine, 0, delimIndx) . strpart(theLine, delimIndx+strlen(rightUnEsc))
@@ -1660,12 +1660,12 @@ function s:UncommentLinesSexy(topline, bottomline)
" if the last line also starts with a sexy comment marker then we " if the last line also starts with a sexy comment marker then we
" remove this as well " remove this as well
if theLine =~ '^[ \t]*' . sexyComMarker if theLine =~# '^[ \t]*' . sexyComMarker
" remove the sexyComMarker. If there is a space after it then " remove the sexyComMarker. If there is a space after it then
" remove that too " remove that too
let sexyComMarkerIndx = stridx(theLine, sexyComMarkerUnEsc) let sexyComMarkerIndx = stridx(theLine, sexyComMarkerUnEsc)
if strpart(theLine, sexyComMarkerIndx+strlen(sexyComMarkerUnEsc), s:lenSpaceStr) == s:spaceStr && g:NERDSpaceDelims if strpart(theLine, sexyComMarkerIndx+strlen(sexyComMarkerUnEsc), s:lenSpaceStr) ==# s:spaceStr && g:NERDSpaceDelims
let theLine = strpart(theLine, 0, sexyComMarkerIndx - markerOffset ) . strpart(theLine, sexyComMarkerIndx+strlen(sexyComMarkerUnEsc)+s:lenSpaceStr) let theLine = strpart(theLine, 0, sexyComMarkerIndx - markerOffset ) . strpart(theLine, sexyComMarkerIndx+strlen(sexyComMarkerUnEsc)+s:lenSpaceStr)
else else
let theLine = strpart(theLine, 0, sexyComMarkerIndx - markerOffset ) . strpart(theLine, sexyComMarkerIndx+strlen(sexyComMarkerUnEsc)) let theLine = strpart(theLine, 0, sexyComMarkerIndx - markerOffset ) . strpart(theLine, sexyComMarkerIndx+strlen(sexyComMarkerUnEsc))
@@ -1677,7 +1677,7 @@ function s:UncommentLinesSexy(topline, bottomline)
endif endif
" remove trailing whitespaces for first and last line " remove trailing whitespaces for first and last line
if g:NERDTrimTrailingWhitespace == 1 if g:NERDTrimTrailingWhitespace ==# 1
let theLine = getline(a:bottomline) let theLine = getline(a:bottomline)
let theLine = s:TrimTrailingWhitespace(theLine) let theLine = s:TrimTrailingWhitespace(theLine)
call setline(a:bottomline, theLine) call setline(a:bottomline, theLine)
@@ -1704,27 +1704,27 @@ function s:UncommentLineNormal(line)
let lineCommentStatus = s:IsCommentedOutermost(s:Left(), s:Right(), s:Left({'alt': 1}), s:Right({'alt': 1}), line) let lineCommentStatus = s:IsCommentedOutermost(s:Left(), s:Right(), s:Left({'alt': 1}), s:Right({'alt': 1}), line)
"it is commented with s:Left() and s:Right() so remove these delimiters "it is commented with s:Left() and s:Right() so remove these delimiters
if lineCommentStatus == 1 if lineCommentStatus ==# 1
let line = s:RemoveDelimiters(s:Left(), s:Right(), line) let line = s:RemoveDelimiters(s:Left(), s:Right(), line)
"it is commented with s:Left({'alt': 1}) and s:Right({'alt': 1}) so remove these delimiters "it is commented with s:Left({'alt': 1}) and s:Right({'alt': 1}) so remove these delimiters
elseif lineCommentStatus == 2 && g:NERDRemoveAltComs elseif lineCommentStatus ==# 2 && g:NERDRemoveAltComs
let line = s:RemoveDelimiters(s:Left({'alt': 1}), s:Right({'alt': 1}), line) let line = s:RemoveDelimiters(s:Left({'alt': 1}), s:Right({'alt': 1}), line)
"it is not properly commented with any delimiters so we check if it has "it is not properly commented with any delimiters so we check if it has
"any random left or right delimiters on it and remove the outermost ones "any random left or right delimiters on it and remove the outermost ones
else else
"remove the outer most left comment delimiter "remove the outer most left comment delimiter
if indxLeft != -1 && (indxLeft < indxLeftAlt || indxLeftAlt == -1) if indxLeft !=# -1 && (indxLeft < indxLeftAlt || indxLeftAlt ==# -1)
let line = s:RemoveDelimiters(s:Left(), '', line) let line = s:RemoveDelimiters(s:Left(), '', line)
elseif indxLeftAlt != -1 && g:NERDRemoveAltComs elseif indxLeftAlt !=# -1 && g:NERDRemoveAltComs
let line = s:RemoveDelimiters(s:Left({'alt': 1}), '', line) let line = s:RemoveDelimiters(s:Left({'alt': 1}), '', line)
endif endif
"remove the outer most right comment delimiter "remove the outer most right comment delimiter
if indxRight != -1 && (indxRight < indxRightAlt || indxRightAlt == -1) if indxRight !=# -1 && (indxRight < indxRightAlt || indxRightAlt ==# -1)
let line = s:RemoveDelimiters('', s:Right(), line) let line = s:RemoveDelimiters('', s:Right(), line)
elseif indxRightAlt != -1 && g:NERDRemoveAltComs elseif indxRightAlt !=# -1 && g:NERDRemoveAltComs
let line = s:RemoveDelimiters('', s:Right({'alt': 1}), line) let line = s:RemoveDelimiters('', s:Right({'alt': 1}), line)
endif endif
endif endif
@@ -1744,11 +1744,11 @@ function s:UncommentLineNormal(line)
"if there are place-holders on the line then we check to see if they are "if there are place-holders on the line then we check to see if they are
"the outermost delimiters on the line. If so then we replace them with "the outermost delimiters on the line. If so then we replace them with
"real delimiters "real delimiters
if indxLeftPlace != -1 if indxLeftPlace !=# -1
if (indxLeftPlace < indxLeft || indxLeft==-1) && (indxLeftPlace < indxLeftAlt || indxLeftAlt==-1) if (indxLeftPlace < indxLeft || indxLeft==-1) && (indxLeftPlace < indxLeftAlt || indxLeftAlt==-1)
let line = s:ReplaceDelims(g:NERDLPlace, g:NERDRPlace, left, right, line) let line = s:ReplaceDelims(g:NERDLPlace, g:NERDRPlace, left, right, line)
endif endif
elseif indxRightPlace != -1 elseif indxRightPlace !=# -1
if (indxRightPlace < indxLeft || indxLeft==-1) && (indxLeftPlace < indxLeftAlt || indxLeftAlt==-1) if (indxRightPlace < indxLeft || indxLeft==-1) && (indxLeftPlace < indxLeftAlt || indxLeftAlt==-1)
let line = s:ReplaceDelims(g:NERDLPlace, g:NERDRPlace, left, right, line) let line = s:ReplaceDelims(g:NERDLPlace, g:NERDRPlace, left, right, line)
endif endif
@@ -1757,7 +1757,7 @@ function s:UncommentLineNormal(line)
let line = s:ConvertLeadingWhiteSpace(line) let line = s:ConvertLeadingWhiteSpace(line)
if g:NERDTrimTrailingWhitespace == 1 if g:NERDTrimTrailingWhitespace ==# 1
let line = s:TrimTrailingWhitespace(line) let line = s:TrimTrailingWhitespace(line)
endif endif
@@ -1804,7 +1804,7 @@ endfunction
" Function: s:AddRightDelim(delim, theLine) {{{2 " Function: s:AddRightDelim(delim, theLine) {{{2
" Args: " Args:
function s:AddRightDelim(delim, theLine) function s:AddRightDelim(delim, theLine)
if a:delim == '' if a:delim ==# ''
return a:theLine return a:theLine
else else
return substitute(a:theLine, '$', a:delim, '') return substitute(a:theLine, '$', a:delim, '')
@@ -1814,7 +1814,7 @@ endfunction
" Function: s:AddRightDelimAligned(delim, theLine, alignIndx) {{{2 " Function: s:AddRightDelimAligned(delim, theLine, alignIndx) {{{2
" Args: " Args:
function s:AddRightDelimAligned(delim, theLine, alignIndx) function s:AddRightDelimAligned(delim, theLine, alignIndx)
if a:delim == '' if a:delim ==# ''
return a:theLine return a:theLine
else else
@@ -1832,7 +1832,7 @@ endfunction
" Function: s:AltMultipart() {{{2 " Function: s:AltMultipart() {{{2
" returns 1 if the alternative delimiters are multipart " returns 1 if the alternative delimiters are multipart
function s:AltMultipart() function s:AltMultipart()
return b:NERDCommenterDelims['rightAlt'] != '' return b:NERDCommenterDelims['rightAlt'] !=# ''
endfunction endfunction
" Function: s:AltNested() {{{2 " Function: s:AltNested() {{{2
@@ -1854,7 +1854,7 @@ function s:CanCommentLine(forceNested, lineNum)
" make sure we don't comment lines that are just spaces or tabs or empty, " make sure we don't comment lines that are just spaces or tabs or empty,
" unless configured otherwise " unless configured otherwise
if g:NERDCommentEmptyLines == 0 && theLine =~ "^[ \t]*$" if g:NERDCommentEmptyLines ==# 0 && theLine =~# "^[ \t]*$"
return 0 return 0
endif endif
@@ -1884,7 +1884,7 @@ function s:CanPlaceCursor(line, col)
let c = col('.') let c = col('.')
let l = line('.') let l = line('.')
call cursor(a:line, a:col) call cursor(a:line, a:col)
let success = (line('.') == a:line && col('.') == a:col) let success = (line('.') ==# a:line && col('.') ==# a:col)
call cursor(l,c) call cursor(l,c)
return success return success
endfunction endfunction
@@ -1921,7 +1921,7 @@ function s:CanToggleCommentLine(forceNested, lineNum)
" make sure we don't comment lines that are just spaces or tabs or empty, " make sure we don't comment lines that are just spaces or tabs or empty,
" unless configured otherwise " unless configured otherwise
if g:NERDCommentEmptyLines == 0 && theLine =~ "^[ \t]*$" if g:NERDCommentEmptyLines ==# 0 && theLine =~# "^[ \t]*$"
return 0 return 0
endif endif
@@ -1941,7 +1941,7 @@ endfunction
" -line: the line whose leading tabs will be converted " -line: the line whose leading tabs will be converted
function s:ConvertLeadingSpacesToTabs(line) function s:ConvertLeadingSpacesToTabs(line)
let toReturn = a:line let toReturn = a:line
while toReturn =~ '^\t*' . s:TabSpace() . '\(.*\)$' while toReturn =~# '^\t*' . s:TabSpace() . '\(.*\)$'
let toReturn = substitute(toReturn, '^\(\t*\)' . s:TabSpace() . '\(.*\)$' , '\1\t\2' , '') let toReturn = substitute(toReturn, '^\(\t*\)' . s:TabSpace() . '\(.*\)$' , '\1\t\2' , '')
endwhile endwhile
@@ -1957,7 +1957,7 @@ endfunction
" -line: the line whose leading spaces will be converted " -line: the line whose leading spaces will be converted
function s:ConvertLeadingTabsToSpaces(line) function s:ConvertLeadingTabsToSpaces(line)
let toReturn = a:line let toReturn = a:line
while toReturn =~ '^\( *\)\t' while toReturn =~# '^\( *\)\t'
let toReturn = substitute(toReturn, '^\( *\)\t', '\1' . s:TabSpace() , '') let toReturn = substitute(toReturn, '^\( *\)\t', '\1' . s:TabSpace() , '')
endwhile endwhile
@@ -1971,7 +1971,7 @@ endfunction
" -line: the line to convert " -line: the line to convert
function s:ConvertLeadingWhiteSpace(line) function s:ConvertLeadingWhiteSpace(line)
let toReturn = a:line let toReturn = a:line
while toReturn =~ '^ *\t' while toReturn =~# '^ *\t'
let toReturn = substitute(toReturn, '^ *\zs\t\ze', s:TabSpace(), 'g') let toReturn = substitute(toReturn, '^ *\zs\t\ze', s:TabSpace(), 'g')
endwhile endwhile
@@ -1996,7 +1996,7 @@ function s:CountNonESCedOccurances(str, searchstr, escChar)
let indx = stridx(a:str, a:searchstr) let indx = stridx(a:str, a:searchstr)
"if there is an instance of searchstr in str process it "if there is an instance of searchstr in str process it
if indx != -1 if indx !=# -1
"get the remainder of str after this instance of searchstr is removed "get the remainder of str after this instance of searchstr is removed
let lensearchstr = strlen(a:searchstr) let lensearchstr = strlen(a:searchstr)
let strLeft = strpart(a:str, indx+lensearchstr) let strLeft = strpart(a:str, indx+lensearchstr)
@@ -2020,7 +2020,7 @@ function s:DoesBlockHaveDelim(delim, top, bottom)
let currentLine = a:top let currentLine = a:top
while currentLine < a:bottom while currentLine < a:bottom
let theline = getline(currentLine) let theline = getline(currentLine)
if s:FindDelimiterIndex(a:delim, theline) != -1 if s:FindDelimiterIndex(a:delim, theline) !=# -1
return 1 return 1
endif endif
let currentLine = currentLine + 1 let currentLine = currentLine + 1
@@ -2062,7 +2062,7 @@ endfunction
function s:FindDelimiterIndex(delimiter, line) function s:FindDelimiterIndex(delimiter, line)
"make sure the delimiter isn't empty otherwise we go into an infinite loop. "make sure the delimiter isn't empty otherwise we go into an infinite loop.
if a:delimiter == '' if a:delimiter ==# ''
return -1 return -1
endif endif
@@ -2075,12 +2075,12 @@ function s:FindDelimiterIndex(delimiter, line)
"keep looping thru the line till we either find a real comment delimiter "keep looping thru the line till we either find a real comment delimiter
"or run off the EOL "or run off the EOL
while delIndx != -1 while delIndx !=# -1
"if we are not off the EOL get the str before the possible delimiter "if we are not off the EOL get the str before the possible delimiter
"in question and check if it really is a delimiter. If it is, return "in question and check if it really is a delimiter. If it is, return
"its position "its position
if delIndx != -1 if delIndx !=# -1
if s:IsDelimValid(l:delimiter, delIndx, a:line) if s:IsDelimValid(l:delimiter, delIndx, a:line)
return delIndx return delIndx
endif endif
@@ -2094,7 +2094,7 @@ function s:FindDelimiterIndex(delimiter, line)
"if distToNextDelim is -1 then there is no more potential delimiters "if distToNextDelim is -1 then there is no more potential delimiters
"on the line so set delIndx to -1. Otherwise, move along the line by "on the line so set delIndx to -1. Otherwise, move along the line by
"distToNextDelim "distToNextDelim
if distToNextDelim == -1 if distToNextDelim ==# -1
let delIndx = -1 let delIndx = -1
else else
let delIndx = delIndx + lenDel + distToNextDelim let delIndx = delIndx + lenDel + distToNextDelim
@@ -2138,20 +2138,20 @@ function s:FindBoundingLinesOfSexyCom(lineNum)
let bottom = -1 let bottom = -1
let currentLine = a:lineNum let currentLine = a:lineNum
while top == -1 || bottom == -1 while top ==# -1 || bottom ==# -1
let theLine = getline(currentLine) let theLine = getline(currentLine)
"check if the current line is the top of the sexy comment "check if the current line is the top of the sexy comment
if currentLine <= a:lineNum && theLine =~ '^[ \t]*' . left && theLine !~ '.*' . right && currentLine < s:NumLinesInBuf() if currentLine <= a:lineNum && theLine =~# '^[ \t]*' . left && theLine !~# '.*' . right && currentLine < s:NumLinesInBuf()
let top = currentLine let top = currentLine
let currentLine = a:lineNum let currentLine = a:lineNum
"check if the current line is the bottom of the sexy comment "check if the current line is the bottom of the sexy comment
elseif theLine =~ '^[ \t]*' . right && theLine !~ '.*' . left && currentLine > 1 elseif theLine =~# '^[ \t]*' . right && theLine !~# '.*' . left && currentLine > 1
let bottom = currentLine let bottom = currentLine
"the right delimiter is on the same line as the last sexyComMarker "the right delimiter is on the same line as the last sexyComMarker
elseif theLine =~ '^[ \t]*' . sexyComMarker . '.*' . right elseif theLine =~# '^[ \t]*' . sexyComMarker . '.*' . right
let bottom = currentLine let bottom = currentLine
"we have not found the top or bottom line so we assume currentLine is an "we have not found the top or bottom line so we assume currentLine is an
@@ -2160,14 +2160,14 @@ function s:FindBoundingLinesOfSexyCom(lineNum)
"if the line doesn't start with a sexyComMarker then it is not a sexy "if the line doesn't start with a sexyComMarker then it is not a sexy
"comment "comment
if theLine !~ '^[ \t]*' . sexyComMarker if theLine !~# '^[ \t]*' . sexyComMarker
return [] return []
endif endif
endif endif
"if top is -1 then we haven't found the top yet so keep looking up "if top is -1 then we haven't found the top yet so keep looking up
if top == -1 if top ==# -1
let currentLine = currentLine - 1 let currentLine = currentLine - 1
"if we have found the top line then go down looking for the bottom "if we have found the top line then go down looking for the bottom
else else
@@ -2195,7 +2195,7 @@ function s:GetSexyComMarker(space, esc)
let sexyComMarker = b:NERDSexyComMarker let sexyComMarker = b:NERDSexyComMarker
"if there is no hardcoded marker then we find one "if there is no hardcoded marker then we find one
if sexyComMarker == '' if sexyComMarker ==# ''
"if the filetype has c style comments then use standard c sexy "if the filetype has c style comments then use standard c sexy
"comments "comments
@@ -2242,7 +2242,7 @@ function s:SexyNested()
"assume c style sexy comments if possible "assume c style sexy comments if possible
if s:HasCStyleComments() if s:HasCStyleComments()
return (s:Left() == '/*' && s:Nested()) || (s:Left({'alt': 1}) == '/*' && s:AltNested()) return (s:Left() ==# '/*' && s:Nested()) || (s:Left({'alt': 1}) ==# '/*' && s:AltNested())
else else
"grab the longest left delim that has a right "grab the longest left delim that has a right
if s:Multipart() && lenLeft >= lenLeftAlt if s:Multipart() && lenLeft >= lenLeftAlt
@@ -2340,7 +2340,7 @@ endfunction
" Returns 1 if any of the given strings have leading tabs " Returns 1 if any of the given strings have leading tabs
function s:HasLeadingTabs(...) function s:HasLeadingTabs(...)
for s in a:000 for s in a:000
if s =~ '^\t.*' if s =~# '^\t.*'
return 1 return 1
end end
endfor endfor
@@ -2349,7 +2349,7 @@ endfunction
" Function: s:HasCStyleComments() {{{2 " Function: s:HasCStyleComments() {{{2
" Returns 1 if the current filetype has c style comment delimiters " Returns 1 if the current filetype has c style comment delimiters
function s:HasCStyleComments() function s:HasCStyleComments()
return (s:Left() == '/*' && s:Right() == '*/') || (s:Left({'alt': 1}) == '/*' && s:Right({'alt': 1}) == '*/') return (s:Left() ==# '/*' && s:Right() ==# '*/') || (s:Left({'alt': 1}) ==# '/*' && s:Right({'alt': 1}) ==# '*/')
endfunction endfunction
" Function: s:IsCommentedNormOrSexy(lineNum) {{{2 " Function: s:IsCommentedNormOrSexy(lineNum) {{{2
@@ -2382,7 +2382,7 @@ endfunction
" -left/right: the left and right delimiters to check for " -left/right: the left and right delimiters to check for
function s:IsCommented(left, right, line) function s:IsCommented(left, right, line)
"if the line isn't commented return true "if the line isn't commented return true
if s:FindDelimiterIndex(a:left, a:line) != -1 && (s:LastIndexOfDelim(a:right, a:line) != -1 || !s:Multipart()) if s:FindDelimiterIndex(a:left, a:line) !=# -1 && (s:LastIndexOfDelim(a:right, a:line) !=# -1 || !s:Multipart())
return 1 return 1
endif endif
return 0 return 0
@@ -2400,7 +2400,7 @@ function s:IsCommentedFromStartOfLine(left, line)
let theLine = s:ConvertLeadingTabsToSpaces(a:line) let theLine = s:ConvertLeadingTabsToSpaces(a:line)
let numSpaces = strlen(substitute(theLine, '^\( *\).*$', '\1', '')) let numSpaces = strlen(substitute(theLine, '^\( *\).*$', '\1', ''))
let delimIndx = s:FindDelimiterIndex(a:left, theLine) let delimIndx = s:FindDelimiterIndex(a:left, theLine)
return delimIndx == numSpaces return delimIndx ==# numSpaces
endfunction endfunction
" Function: s:IsCommentedOutermost(left, right, leftAlt, rightAlt, line) {{{2 " Function: s:IsCommentedOutermost(left, right, leftAlt, rightAlt, line) {{{2
@@ -2425,14 +2425,14 @@ function s:IsCommentedOutermost(left, right, leftAlt, rightAlt, line)
let indxRightAlt = s:LastIndexOfDelim(a:rightAlt, a:line) let indxRightAlt = s:LastIndexOfDelim(a:rightAlt, a:line)
"check if the line has a left delimiter before a leftAlt delimiter "check if the line has a left delimiter before a leftAlt delimiter
if (indxLeft <= indxLeftAlt || indxLeftAlt == -1) && indxLeft != -1 if (indxLeft <= indxLeftAlt || indxLeftAlt ==# -1) && indxLeft !=# -1
"check if the line has a right delimiter after any rightAlt delimiter "check if the line has a right delimiter after any rightAlt delimiter
if (indxRight > indxRightAlt && indxRight > indxLeft) || !s:Multipart() if (indxRight > indxRightAlt && indxRight > indxLeft) || !s:Multipart()
return 1 return 1
endif endif
"check if the line has a leftAlt delimiter before a left delimiter "check if the line has a leftAlt delimiter before a left delimiter
elseif (indxLeftAlt <= indxLeft || indxLeft == -1) && indxLeftAlt != -1 elseif (indxLeftAlt <= indxLeft || indxLeft ==# -1) && indxLeftAlt !=# -1
"check if the line has a rightAlt delimiter after any right delimiter "check if the line has a rightAlt delimiter after any right delimiter
if (indxRightAlt > indxRight && indxRightAlt > indxLeftAlt) || !s:AltMultipart() if (indxRightAlt > indxRight && indxRightAlt > indxLeftAlt) || !s:AltMultipart()
return 2 return 2
@@ -2493,14 +2493,14 @@ function s:IsDelimValid(delimiter, delIndx, line)
"vim comments are so fucking stupid!! Why the hell do they have comment "vim comments are so fucking stupid!! Why the hell do they have comment
"delimiters that are used elsewhere in the syntax?!?! We need to check "delimiters that are used elsewhere in the syntax?!?! We need to check
"some conditions especially for vim "some conditions especially for vim
if &filetype == 'vim' if &filetype ==# 'vim'
if !s:IsNumEven(s:CountNonESCedOccurances(preComStr, '"', "\\")) if !s:IsNumEven(s:CountNonESCedOccurances(preComStr, '"', "\\"))
return 0 return 0
endif endif
"if the delimiter is on the very first char of the line or is the "if the delimiter is on the very first char of the line or is the
"first non-tab/space char on the line then it is a valid comment delimiter "first non-tab/space char on the line then it is a valid comment delimiter
if a:delIndx == 0 || a:line =~ "^[ \t]\\{" . a:delIndx . "\\}\".*$" if a:delIndx ==# 0 || a:line =~# "^[ \t]\\{" . a:delIndx . "\\}\".*$"
return 1 return 1
endif endif
@@ -2528,7 +2528,7 @@ endfunction
" Args: " Args:
" -num: the number to check " -num: the number to check
function s:IsNumEven(num) function s:IsNumEven(num)
return (a:num % 2) == 0 return (a:num % 2) ==# 0
endfunction endfunction
" Function: s:IsEscaped(str, indx, escChar) {{{2 " Function: s:IsEscaped(str, indx, escChar) {{{2
@@ -2546,7 +2546,7 @@ function s:IsEscaped(str, indx, escChar)
"keep going back thru str until we either reach the start of the str or "keep going back thru str until we either reach the start of the str or
"run out of esc chars "run out of esc chars
while curIndx >= 0 && strpart(a:str, curIndx, 1) == a:escChar while curIndx >= 0 && strpart(a:str, curIndx, 1) ==# a:escChar
"we have found another esc char so add one to the count and move left "we have found another esc char so add one to the count and move left
"one char "one char
@@ -2601,23 +2601,23 @@ function s:IsSexyComment(topline, bottomline)
endif endif
"if the top line doesn't begin with a left delimiter then the comment isn't sexy "if the top line doesn't begin with a left delimiter then the comment isn't sexy
if getline(a:topline) !~ '^[ \t]*' . left if getline(a:topline) !~# '^[ \t]*' . left
return 0 return 0
endif endif
"if there is a right delimiter on the top line then this isn't a sexy comment "if there is a right delimiter on the top line then this isn't a sexy comment
if s:LastIndexOfDelim(right, getline(a:topline)) != -1 if s:LastIndexOfDelim(right, getline(a:topline)) !=# -1
return 0 return 0
endif endif
"if there is a left delimiter on the bottom line then this isn't a sexy comment "if there is a left delimiter on the bottom line then this isn't a sexy comment
if s:FindDelimiterIndex(left, getline(a:bottomline)) != -1 if s:FindDelimiterIndex(left, getline(a:bottomline)) !=# -1
return 0 return 0
endif endif
"if the bottom line doesn't begin with a right delimiter then the comment isn't "if the bottom line doesn't begin with a right delimiter then the comment isn't
"sexy "sexy
if getline(a:bottomline) !~ '^.*' . right . '$' if getline(a:bottomline) !~# '^.*' . right . '$'
return 0 return 0
endif endif
@@ -2629,13 +2629,13 @@ function s:IsSexyComment(topline, bottomline)
while currentLine < a:bottomline while currentLine < a:bottomline
let theLine = getline(currentLine) let theLine = getline(currentLine)
if theLine !~ '^[ \t]*' . sexyComMarker if theLine !~# '^[ \t]*' . sexyComMarker
return 0 return 0
endif endif
"if there is a right delimiter in an intermediate line then the block isn't "if there is a right delimiter in an intermediate line then the block isn't
"a sexy comment "a sexy comment
if s:LastIndexOfDelim(right, theLine) != -1 if s:LastIndexOfDelim(right, theLine) !=# -1
return 0 return 0
endif endif
@@ -2660,7 +2660,7 @@ function s:LastIndexOfDelim(delim, str)
"set index to the first occurrence of delimiter. If there is no occurrence then "set index to the first occurrence of delimiter. If there is no occurrence then
"bail "bail
let indx = s:FindDelimiterIndex(delim, a:str) let indx = s:FindDelimiterIndex(delim, a:str)
if indx == -1 if indx ==# -1
return -1 return -1
endif endif
@@ -2674,7 +2674,7 @@ function s:LastIndexOfDelim(delim, str)
"if we find a delimiter update indx to record the position of it, if we "if we find a delimiter update indx to record the position of it, if we
"don't find another delimiter then indx is the last one so break out of "don't find another delimiter then indx is the last one so break out of
"this loop "this loop
if indx2 != -1 if indx2 !=# -1
let indx = indx + indx2 + lenDelim let indx = indx + indx2 + lenDelim
else else
break break
@@ -2692,7 +2692,7 @@ function s:Left(...)
let delim = has_key(params, 'alt') ? b:NERDCommenterDelims['leftAlt'] : b:NERDCommenterDelims['left'] let delim = has_key(params, 'alt') ? b:NERDCommenterDelims['leftAlt'] : b:NERDCommenterDelims['left']
if delim == '' if delim ==# ''
return '' return ''
endif endif
@@ -2728,7 +2728,7 @@ function s:LeftMostIndx(countCommentedLines, countEmptyLines, topline, bottomlin
" get the next line and if it is allowed to be commented, or is not " get the next line and if it is allowed to be commented, or is not
" commented, check it " commented, check it
let theLine = getline(currentLine) let theLine = getline(currentLine)
if a:countEmptyLines || theLine !~ '^[ \t]*$' if a:countEmptyLines || theLine !~# '^[ \t]*$'
if a:countCommentedLines || (!s:IsCommented(s:Left(), s:Right(), theLine) && !s:IsCommented(s:Left({'alt': 1}), s:Right({'alt': 1}), theLine)) if a:countCommentedLines || (!s:IsCommented(s:Left(), s:Right(), theLine) && !s:IsCommented(s:Left({'alt': 1}), s:Right({'alt': 1}), theLine))
" convert spaces to tabs and get the number of leading spaces for " convert spaces to tabs and get the number of leading spaces for
" this line and update leftMostIndx if need be " this line and update leftMostIndx if need be
@@ -2744,7 +2744,7 @@ function s:LeftMostIndx(countCommentedLines, countEmptyLines, topline, bottomlin
let currentLine = currentLine + 1 let currentLine = currentLine + 1
endwhile endwhile
if leftMostIndx == 1000 if leftMostIndx ==# 1000
return 0 return 0
else else
return leftMostIndx return leftMostIndx
@@ -2754,7 +2754,7 @@ endfunction
" Function: s:Multipart() {{{2 " Function: s:Multipart() {{{2
" returns 1 if the current delimiters are multipart " returns 1 if the current delimiters are multipart
function s:Multipart() function s:Multipart()
return s:Right() != '' return s:Right() !=# ''
endfunction endfunction
" Function: s:NerdEcho(msg, typeOfMsg) {{{2 " Function: s:NerdEcho(msg, typeOfMsg) {{{2
@@ -2763,11 +2763,11 @@ endfunction
" -typeOfMsg: 0 = warning message " -typeOfMsg: 0 = warning message
" 1 = normal message " 1 = normal message
function s:NerdEcho(msg, typeOfMsg) function s:NerdEcho(msg, typeOfMsg)
if a:typeOfMsg == 0 if a:typeOfMsg ==# 0
echohl WarningMsg echohl WarningMsg
echom 'NERDCommenter:' . a:msg echom 'NERDCommenter:' . a:msg
echohl None echohl None
elseif a:typeOfMsg == 1 elseif a:typeOfMsg ==# 1
echom 'NERDCommenter:' . a:msg echom 'NERDCommenter:' . a:msg
endif endif
endfunction endfunction
@@ -2822,7 +2822,7 @@ function s:ReplaceLeftMostDelim(toReplace, replacor, str)
"if there IS an occurrence of toReplace in str then replace it and return "if there IS an occurrence of toReplace in str then replace it and return
"the resulting string "the resulting string
if indxToReplace != -1 if indxToReplace !=# -1
let line = strpart(a:str, 0, indxToReplace) . replacor . strpart(a:str, indxToReplace+strlen(toReplace)) let line = strpart(a:str, 0, indxToReplace) . replacor . strpart(a:str, indxToReplace+strlen(toReplace))
return line return line
endif endif
@@ -2849,7 +2849,7 @@ function s:ReplaceRightMostDelim(toReplace, replacor, str)
"if there IS a delimiter in str, replace it and return the result "if there IS a delimiter in str, replace it and return the result
let line = a:str let line = a:str
if indxToReplace != -1 if indxToReplace !=# -1
let line = strpart(a:str, 0, indxToReplace) . replacor . strpart(a:str, indxToReplace+strlen(toReplace)) let line = strpart(a:str, 0, indxToReplace) . replacor . strpart(a:str, indxToReplace+strlen(toReplace))
endif endif
return line return line
@@ -2877,7 +2877,7 @@ function s:Right(...)
let delim = has_key(params, 'alt') ? b:NERDCommenterDelims['rightAlt'] : b:NERDCommenterDelims['right'] let delim = has_key(params, 'alt') ? b:NERDCommenterDelims['rightAlt'] : b:NERDCommenterDelims['right']
if delim == '' if delim ==# ''
return '' return ''
endif endif
@@ -2911,7 +2911,7 @@ function s:RightMostIndx(countCommentedLines, countEmptyLines, topline, bottomli
" get the next line and see if it is commentable, otherwise it doesn't " get the next line and see if it is commentable, otherwise it doesn't
" count " count
let theLine = getline(currentLine) let theLine = getline(currentLine)
if a:countEmptyLines || theLine !~ '^[ \t]*$' if a:countEmptyLines || theLine !~# '^[ \t]*$'
if a:countCommentedLines || (!s:IsCommented(s:Left(), s:Right(), theLine) && !s:IsCommented(s:Left({'alt': 1}), s:Right({'alt': 1}), theLine)) if a:countCommentedLines || (!s:IsCommented(s:Left(), s:Right(), theLine) && !s:IsCommented(s:Left({'alt': 1}), s:Right({'alt': 1}), theLine))
@@ -3052,7 +3052,7 @@ function! s:CreateMaps(modes, target, desc, combo)
endif endif
let menu_command .= ' ' . (strlen(a:combo) ? plug : a:target) let menu_command .= ' ' . (strlen(a:combo) ? plug : a:target)
" Execute the commands built above for each requested mode. " Execute the commands built above for each requested mode.
for mode in (a:modes == '') ? [''] : split(a:modes, '\zs') for mode in (a:modes ==# '') ? [''] : split(a:modes, '\zs')
if strlen(a:combo) if strlen(a:combo)
execute mode . plug_start . mode . plug_end execute mode . plug_start . mode . plug_end
if g:NERDCreateDefaultMappings && !hasmapto(plug, mode) if g:NERDCreateDefaultMappings && !hasmapto(plug, mode)
@@ -3060,7 +3060,7 @@ function! s:CreateMaps(modes, target, desc, combo)
endif endif
endif endif
" Check if the user wants the menu to be displayed. " Check if the user wants the menu to be displayed.
if g:NERDMenuMode != 0 if g:NERDMenuMode !=# 0
execute mode . menu_command execute mode . menu_command
endif endif
endfor endfor