From 277986725dbd4afd203ae81e3275a7f902463e73 Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Mon, 30 Dec 2019 11:02:22 +0300 Subject: [PATCH] Fix lint warning: use robust operators --- plugin/NERD_commenter.vim | 222 +++++++++++++++++++------------------- 1 file changed, 111 insertions(+), 111 deletions(-) diff --git a/plugin/NERD_commenter.vim b/plugin/NERD_commenter.vim index a916197..b55221c 100644 --- a/plugin/NERD_commenter.vim +++ b/plugin/NERD_commenter.vim @@ -528,7 +528,7 @@ function s:SetUpForNewFiletype(filetype, forceReset) "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 - if ft =~ '\.' && !has_key(s:delimiterMap, ft) + if ft =~# '\.' && !has_key(s:delimiterMap, ft) let filetypes = split(a:filetype, '\.') for i in filetypes if has_key(s:delimiterMap, i) @@ -565,7 +565,7 @@ function s:SetUpForNewFiletype(filetype, forceReset) endfunction function s:CreateDelimMapFromCms() - if &ft == '' && exists('g:NERDDefaultDelims') + if &ft ==# '' && exists('g:NERDDefaultDelims') let delims = g:NERDDefaultDelims for i in ['left', 'leftAlt', 'right', 'rightAlt'] if !has_key(delims, i) @@ -598,7 +598,7 @@ function s:SwitchToAlternativeDelimiters(printMsgs) endif "if both of the alternative delimiters are empty then there is no "alternative comment style so bail out - if b:NERDCommenterDelims['leftAlt'] == '' && b:NERDCommenterDelims['rightAlt'] == '' + if b:NERDCommenterDelims['leftAlt'] ==# '' && b:NERDCommenterDelims['rightAlt'] ==# '' if a:printMsgs call s:NerdEcho('Cannot use alternative delimiters, none are specified', 0) endif @@ -645,8 +645,8 @@ function s:AppendCommentToLine() " get the length of the right delimiter let lenRight = strlen(right) - let isLineEmpty = strlen(getline('.')) == 0 - let insOrApp = (isLineEmpty==1 ? 'i' : 'A') + let isLineEmpty = strlen(getline('.')) ==# 0 + let insOrApp = (isLineEmpty==#1 ? 'i' : 'A') "stick the delimiters down at the end of the line. We have to format the "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 "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, "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 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(searchStr, firstLeftDelim+strlen(s:Left())) @@ -781,7 +781,7 @@ function s:CommentBlock(top, bottom, lSide, rSide, forceNested ) let theLine = s:ConvertLeadingSpacesToTabs(theLine) endif - if g:NERDTrimTrailingWhitespace == 1 + if g:NERDTrimTrailingWhitespace ==# 1 let theLine = s:TrimTrailingWhitespace(theLine) endif @@ -792,7 +792,7 @@ function s:CommentBlock(top, bottom, lSide, rSide, forceNested ) endwhile "if we switched delimiterss then we gotta go back to what they were before - if switchedDelims == 1 + if switchedDelims ==# 1 call s:SwitchToAlternativeDelimiters(0) endif 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 " block of of lines and the right most char so that we can do alignment of " 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) " 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 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) else let theLine = s:AddLeftDelim(s:Left({'space': 1}), theLine) endif - if a:align == 'both' + if a:align ==# 'both' let theLine = s:AddRightDelimAligned(s:Right({'space': 1}), theLine, rightAlignIndx) else 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) endif - if g:NERDTrimTrailingWhitespace == 1 + if g:NERDTrimTrailingWhitespace ==# 1 let theLine = s:TrimTrailingWhitespace(theLine) endif @@ -920,7 +920,7 @@ function s:CommentLinesMinimal(firstLine, lastLine) let theLine = s:ConvertLeadingSpacesToTabs(theLine) endif - if g:NERDTrimTrailingWhitespace == 1 + if g:NERDTrimTrailingWhitespace ==# 1 let theLine = s:TrimTrailingWhitespace(theLine) endif @@ -940,7 +940,7 @@ function s:CommentLinesSexy(topline, bottomline) let right = s:GetSexyComRight(0, 0) "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.' endif @@ -979,7 +979,7 @@ function s:CommentLinesSexy(topline, bottomline) call setline(a:topline, theLine) "comment the bottom line - if a:bottomline != a:topline + if a:bottomline !=# a:topline let theLine = getline(a:bottomline) let lineHasTabs = s:HasLeadingTabs(theLine) if lineHasTabs @@ -1051,7 +1051,7 @@ function s:CommentLinesSexy(topline, bottomline) let theLine = s:ConvertLeadingSpacesToTabs(theLine) endif - if g:NERDTrimTrailingWhitespace == 1 + if g:NERDTrimTrailingWhitespace ==# 1 let theLine = s:TrimTrailingWhitespace(theLine) endif @@ -1073,7 +1073,7 @@ function s:CommentLinesToggle(forceNested, firstLine, lastLine) let currentLine = a:firstLine 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 = rightAlignIndx + strlen(s:Left({'space': 1})) @@ -1091,12 +1091,12 @@ function s:CommentLinesToggle(forceNested, firstLine, lastLine) let theLine = s:SwapOuterMultiPartDelimsForPlaceHolders(theLine) 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) else let theLine = s:AddLeftDelim(s:Left({'space': 1}), theLine) endif - if align == 'both' + if align ==# 'both' let theLine = s:AddRightDelimAligned(s:Right({'space': 1}), theLine, rightAlignIndx) else let theLine = s:AddRightDelim(s:Right({'space': 1}), theLine) @@ -1108,7 +1108,7 @@ function s:CommentLinesToggle(forceNested, firstLine, lastLine) let theLine = s:ConvertLeadingSpacesToTabs(theLine) endif - if g:NERDTrimTrailingWhitespace == 1 + if g:NERDTrimTrailingWhitespace ==# 1 let theLine = s:TrimTrailingWhitespace(theLine) endif @@ -1139,7 +1139,7 @@ function s:CommentRegion(topLine, topCol, bottomLine, bottomCol, forceNested) endif "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) "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) "if we switched delimiters then we gotta go back to what they were before - if switchedDelims == 1 + if switchedDelims ==# 1 call s:SwitchToAlternativeDelimiters(0) endif @@ -1228,9 +1228,9 @@ function! NERDComment(mode, type) range exe 'call NERDCommenter_before()' 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) endif @@ -1238,7 +1238,7 @@ function! NERDComment(mode, type) range let firstLine = line("'<") let lastLine = line("'>") let firstCol = col("'<") - let lastCol = col("'>") - (&selection == 'exclusive' ? 1 : 0) + let lastCol = col("'>") - (&selection ==# 'exclusive' ? 1 : 0) else let firstLine = a:firstline 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 let state = s:SetupStateBeforeLineComment(firstLine, lastLine) - let countWasGiven = (!isVisual && firstLine != lastLine) + let countWasGiven = (!isVisual && firstLine !=# lastLine) let forceNested = (a:type ==? 'Nested' || g:NERDDefaultNesting) if a:type ==? 'Comment' || a:type ==? 'Nested' - if isVisual && visualmode() == "\" + if isVisual && visualmode() ==# "\" 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) else call s:CommentLines(forceNested, g:NERDDefaultAlign, firstLine, lastLine) @@ -1294,7 +1294,7 @@ function! NERDComment(mode, type) range for i in range(firstLine, lastLine) let theLine = getline(i) " 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 break else @@ -1365,7 +1365,7 @@ function s:PlaceDelimitersAndInsBetween() let right = s:Right({'space': 1}) 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 "account @@ -1400,7 +1400,7 @@ function s:PlaceDelimitersAndInsBetween() call cursor(line('.'), tabbedCol) endif - if isDelimOnEOL && lenRight == 0 + if isDelimOnEOL && lenRight ==# 0 startinsert! else startinsert @@ -1431,24 +1431,24 @@ function s:RemoveDelimiters(left, right, line) "look for the left delimiter, if we find it, remove it. let leftIndx = s:FindDelimiterIndex(a:left, line) - if leftIndx != -1 + if leftIndx !=# -1 let line = strpart(line, 0, leftIndx) . strpart(line, leftIndx+lenLeft) "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 - 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) endif endif "look for the right delimiter, if we find it, remove it let rightIndx = s:LastIndexOfDelim(a:right, line) - if rightIndx != -1 + if rightIndx !=# -1 let line = strpart(line, 0, rightIndx) . strpart(line, rightIndx+lenRight) "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 - 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) endif endif @@ -1475,7 +1475,7 @@ function s:SetupStateBeforeLineComment(topLine, bottomLine) " manual, do the commenting stuff and recover it later. To avoid slowing " down commenting few lines, we avoid doing this for ranges smaller than " 10 lines - if a:bottomLine - a:topLine >= 10 && &foldmethod != 'manual' + if a:bottomLine - a:topLine >= 10 && &foldmethod !=# 'manual' set foldmethod=manual endif @@ -1493,10 +1493,10 @@ endfunction " state: the top line of the visual selection to uncomment " bottomLine: the bottom line of the visual selection to uncomment function s:RecoverStateAfterLineComment(state) - if a:state['foldmethod'] != &foldmethod + if a:state['foldmethod'] !=# &foldmethod let &foldmethod = a:state['foldmethod'] endif - if a:state['ignorecase'] != &ignorecase + if a:state['ignorecase'] !=# &ignorecase let &ignorecase = a:state['ignorecase'] endif endfunction @@ -1568,7 +1568,7 @@ function s:UncommentLinesSexy(topline, bottomline) "check if it is even possible for sexy comments to exist with the "available delimiters - if left == -1 || right == -1 + if left ==# -1 || right ==# -1 throw 'NERDCommenter.Delimiters exception: cannot uncomment sexy comments with available delimiters.' endif @@ -1592,7 +1592,7 @@ function s:UncommentLinesSexy(topline, bottomline) " 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 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) else 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) - if g:NERDTrimTrailingWhitespace == 1 + if g:NERDTrimTrailingWhitespace ==# 1 let theLine = s:TrimTrailingWhitespace(theLine) endif @@ -1619,7 +1619,7 @@ function s:UncommentLinesSexy(topline, bottomline) let theLine = getline(a:topline) " 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) normal! dd let bottomline = bottomline - 1 @@ -1630,7 +1630,7 @@ function s:UncommentLinesSexy(topline, bottomline) " remove the delimiter. If there is a space after it " then remove this too if appropriate 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) else let theLine = strpart(theLine, 0, delimIndx) . strpart(theLine, delimIndx+strlen(leftUnEsc)) @@ -1643,7 +1643,7 @@ function s:UncommentLinesSexy(topline, bottomline) let theLine = getline(bottomline) " 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) normal! dd @@ -1652,7 +1652,7 @@ function s:UncommentLinesSexy(topline, bottomline) " remove the right delimiter. If there is a space after it and " if the appropriate options are set then remove this too. 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) else 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 " remove this as well - if theLine =~ '^[ \t]*' . sexyComMarker + if theLine =~# '^[ \t]*' . sexyComMarker " remove the sexyComMarker. If there is a space after it then " remove that too 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) else let theLine = strpart(theLine, 0, sexyComMarkerIndx - markerOffset ) . strpart(theLine, sexyComMarkerIndx+strlen(sexyComMarkerUnEsc)) @@ -1677,7 +1677,7 @@ function s:UncommentLinesSexy(topline, bottomline) endif " remove trailing whitespaces for first and last line - if g:NERDTrimTrailingWhitespace == 1 + if g:NERDTrimTrailingWhitespace ==# 1 let theLine = getline(a:bottomline) let theLine = s:TrimTrailingWhitespace(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) "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) "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) "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 else "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) - elseif indxLeftAlt != -1 && g:NERDRemoveAltComs + elseif indxLeftAlt !=# -1 && g:NERDRemoveAltComs let line = s:RemoveDelimiters(s:Left({'alt': 1}), '', line) endif "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) - elseif indxRightAlt != -1 && g:NERDRemoveAltComs + elseif indxRightAlt !=# -1 && g:NERDRemoveAltComs let line = s:RemoveDelimiters('', s:Right({'alt': 1}), line) 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 "the outermost delimiters on the line. If so then we replace them with "real delimiters - if indxLeftPlace != -1 + if indxLeftPlace !=# -1 if (indxLeftPlace < indxLeft || indxLeft==-1) && (indxLeftPlace < indxLeftAlt || indxLeftAlt==-1) let line = s:ReplaceDelims(g:NERDLPlace, g:NERDRPlace, left, right, line) endif - elseif indxRightPlace != -1 + elseif indxRightPlace !=# -1 if (indxRightPlace < indxLeft || indxLeft==-1) && (indxLeftPlace < indxLeftAlt || indxLeftAlt==-1) let line = s:ReplaceDelims(g:NERDLPlace, g:NERDRPlace, left, right, line) endif @@ -1757,7 +1757,7 @@ function s:UncommentLineNormal(line) let line = s:ConvertLeadingWhiteSpace(line) - if g:NERDTrimTrailingWhitespace == 1 + if g:NERDTrimTrailingWhitespace ==# 1 let line = s:TrimTrailingWhitespace(line) endif @@ -1804,7 +1804,7 @@ endfunction " Function: s:AddRightDelim(delim, theLine) {{{2 " Args: function s:AddRightDelim(delim, theLine) - if a:delim == '' + if a:delim ==# '' return a:theLine else return substitute(a:theLine, '$', a:delim, '') @@ -1814,7 +1814,7 @@ endfunction " Function: s:AddRightDelimAligned(delim, theLine, alignIndx) {{{2 " Args: function s:AddRightDelimAligned(delim, theLine, alignIndx) - if a:delim == '' + if a:delim ==# '' return a:theLine else @@ -1832,7 +1832,7 @@ endfunction " Function: s:AltMultipart() {{{2 " returns 1 if the alternative delimiters are multipart function s:AltMultipart() - return b:NERDCommenterDelims['rightAlt'] != '' + return b:NERDCommenterDelims['rightAlt'] !=# '' endfunction " 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, " unless configured otherwise - if g:NERDCommentEmptyLines == 0 && theLine =~ "^[ \t]*$" + if g:NERDCommentEmptyLines ==# 0 && theLine =~# "^[ \t]*$" return 0 endif @@ -1884,7 +1884,7 @@ function s:CanPlaceCursor(line, col) let c = col('.') let l = line('.') 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) return success 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, " unless configured otherwise - if g:NERDCommentEmptyLines == 0 && theLine =~ "^[ \t]*$" + if g:NERDCommentEmptyLines ==# 0 && theLine =~# "^[ \t]*$" return 0 endif @@ -1941,7 +1941,7 @@ endfunction " -line: the line whose leading tabs will be converted function s:ConvertLeadingSpacesToTabs(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' , '') endwhile @@ -1957,7 +1957,7 @@ endfunction " -line: the line whose leading spaces will be converted function s:ConvertLeadingTabsToSpaces(line) let toReturn = a:line - while toReturn =~ '^\( *\)\t' + while toReturn =~# '^\( *\)\t' let toReturn = substitute(toReturn, '^\( *\)\t', '\1' . s:TabSpace() , '') endwhile @@ -1971,7 +1971,7 @@ endfunction " -line: the line to convert function s:ConvertLeadingWhiteSpace(line) let toReturn = a:line - while toReturn =~ '^ *\t' + while toReturn =~# '^ *\t' let toReturn = substitute(toReturn, '^ *\zs\t\ze', s:TabSpace(), 'g') endwhile @@ -1996,7 +1996,7 @@ function s:CountNonESCedOccurances(str, searchstr, escChar) let indx = stridx(a:str, a:searchstr) "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 let lensearchstr = strlen(a:searchstr) let strLeft = strpart(a:str, indx+lensearchstr) @@ -2020,7 +2020,7 @@ function s:DoesBlockHaveDelim(delim, top, bottom) let currentLine = a:top while currentLine < a:bottom let theline = getline(currentLine) - if s:FindDelimiterIndex(a:delim, theline) != -1 + if s:FindDelimiterIndex(a:delim, theline) !=# -1 return 1 endif let currentLine = currentLine + 1 @@ -2062,7 +2062,7 @@ endfunction function s:FindDelimiterIndex(delimiter, line) "make sure the delimiter isn't empty otherwise we go into an infinite loop. - if a:delimiter == '' + if a:delimiter ==# '' return -1 endif @@ -2075,12 +2075,12 @@ function s:FindDelimiterIndex(delimiter, line) "keep looping thru the line till we either find a real comment delimiter "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 "in question and check if it really is a delimiter. If it is, return "its position - if delIndx != -1 + if delIndx !=# -1 if s:IsDelimValid(l:delimiter, delIndx, a:line) return delIndx endif @@ -2094,7 +2094,7 @@ function s:FindDelimiterIndex(delimiter, line) "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 "distToNextDelim - if distToNextDelim == -1 + if distToNextDelim ==# -1 let delIndx = -1 else let delIndx = delIndx + lenDel + distToNextDelim @@ -2138,20 +2138,20 @@ function s:FindBoundingLinesOfSexyCom(lineNum) let bottom = -1 let currentLine = a:lineNum - while top == -1 || bottom == -1 + while top ==# -1 || bottom ==# -1 let theLine = getline(currentLine) "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 currentLine = a:lineNum "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 "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 "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 "comment - if theLine !~ '^[ \t]*' . sexyComMarker + if theLine !~# '^[ \t]*' . sexyComMarker return [] endif endif "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 "if we have found the top line then go down looking for the bottom else @@ -2195,7 +2195,7 @@ function s:GetSexyComMarker(space, esc) let sexyComMarker = b:NERDSexyComMarker "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 "comments @@ -2242,7 +2242,7 @@ function s:SexyNested() "assume c style sexy comments if possible 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 "grab the longest left delim that has a right if s:Multipart() && lenLeft >= lenLeftAlt @@ -2340,7 +2340,7 @@ endfunction " Returns 1 if any of the given strings have leading tabs function s:HasLeadingTabs(...) for s in a:000 - if s =~ '^\t.*' + if s =~# '^\t.*' return 1 end endfor @@ -2349,7 +2349,7 @@ endfunction " Function: s:HasCStyleComments() {{{2 " Returns 1 if the current filetype has c style comment delimiters 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 " Function: s:IsCommentedNormOrSexy(lineNum) {{{2 @@ -2382,7 +2382,7 @@ endfunction " -left/right: the left and right delimiters to check for function s:IsCommented(left, right, line) "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 endif return 0 @@ -2400,7 +2400,7 @@ function s:IsCommentedFromStartOfLine(left, line) let theLine = s:ConvertLeadingTabsToSpaces(a:line) let numSpaces = strlen(substitute(theLine, '^\( *\).*$', '\1', '')) let delimIndx = s:FindDelimiterIndex(a:left, theLine) - return delimIndx == numSpaces + return delimIndx ==# numSpaces endfunction " 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) "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 if (indxRight > indxRightAlt && indxRight > indxLeft) || !s:Multipart() return 1 endif "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 if (indxRightAlt > indxRight && indxRightAlt > indxLeftAlt) || !s:AltMultipart() 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 "delimiters that are used elsewhere in the syntax?!?! We need to check "some conditions especially for vim - if &filetype == 'vim' + if &filetype ==# 'vim' if !s:IsNumEven(s:CountNonESCedOccurances(preComStr, '"', "\\")) return 0 endif "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 - if a:delIndx == 0 || a:line =~ "^[ \t]\\{" . a:delIndx . "\\}\".*$" + if a:delIndx ==# 0 || a:line =~# "^[ \t]\\{" . a:delIndx . "\\}\".*$" return 1 endif @@ -2528,7 +2528,7 @@ endfunction " Args: " -num: the number to check function s:IsNumEven(num) - return (a:num % 2) == 0 + return (a:num % 2) ==# 0 endfunction " 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 "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 "one char @@ -2601,23 +2601,23 @@ function s:IsSexyComment(topline, bottomline) endif "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 endif "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 endif "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 endif "if the bottom line doesn't begin with a right delimiter then the comment isn't "sexy - if getline(a:bottomline) !~ '^.*' . right . '$' + if getline(a:bottomline) !~# '^.*' . right . '$' return 0 endif @@ -2629,13 +2629,13 @@ function s:IsSexyComment(topline, bottomline) while currentLine < a:bottomline let theLine = getline(currentLine) - if theLine !~ '^[ \t]*' . sexyComMarker + if theLine !~# '^[ \t]*' . sexyComMarker return 0 endif "if there is a right delimiter in an intermediate line then the block isn't "a sexy comment - if s:LastIndexOfDelim(right, theLine) != -1 + if s:LastIndexOfDelim(right, theLine) !=# -1 return 0 endif @@ -2660,7 +2660,7 @@ function s:LastIndexOfDelim(delim, str) "set index to the first occurrence of delimiter. If there is no occurrence then "bail let indx = s:FindDelimiterIndex(delim, a:str) - if indx == -1 + if indx ==# -1 return -1 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 "don't find another delimiter then indx is the last one so break out of "this loop - if indx2 != -1 + if indx2 !=# -1 let indx = indx + indx2 + lenDelim else break @@ -2692,7 +2692,7 @@ function s:Left(...) let delim = has_key(params, 'alt') ? b:NERDCommenterDelims['leftAlt'] : b:NERDCommenterDelims['left'] - if delim == '' + if delim ==# '' return '' 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 " commented, check it 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)) " convert spaces to tabs and get the number of leading spaces for " this line and update leftMostIndx if need be @@ -2744,7 +2744,7 @@ function s:LeftMostIndx(countCommentedLines, countEmptyLines, topline, bottomlin let currentLine = currentLine + 1 endwhile - if leftMostIndx == 1000 + if leftMostIndx ==# 1000 return 0 else return leftMostIndx @@ -2754,7 +2754,7 @@ endfunction " Function: s:Multipart() {{{2 " returns 1 if the current delimiters are multipart function s:Multipart() - return s:Right() != '' + return s:Right() !=# '' endfunction " Function: s:NerdEcho(msg, typeOfMsg) {{{2 @@ -2763,11 +2763,11 @@ endfunction " -typeOfMsg: 0 = warning message " 1 = normal message function s:NerdEcho(msg, typeOfMsg) - if a:typeOfMsg == 0 + if a:typeOfMsg ==# 0 echohl WarningMsg echom 'NERDCommenter:' . a:msg echohl None - elseif a:typeOfMsg == 1 + elseif a:typeOfMsg ==# 1 echom 'NERDCommenter:' . a:msg endif 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 "the resulting string - if indxToReplace != -1 + if indxToReplace !=# -1 let line = strpart(a:str, 0, indxToReplace) . replacor . strpart(a:str, indxToReplace+strlen(toReplace)) return line endif @@ -2849,7 +2849,7 @@ function s:ReplaceRightMostDelim(toReplace, replacor, str) "if there IS a delimiter in str, replace it and return the result let line = a:str - if indxToReplace != -1 + if indxToReplace !=# -1 let line = strpart(a:str, 0, indxToReplace) . replacor . strpart(a:str, indxToReplace+strlen(toReplace)) endif return line @@ -2877,7 +2877,7 @@ function s:Right(...) let delim = has_key(params, 'alt') ? b:NERDCommenterDelims['rightAlt'] : b:NERDCommenterDelims['right'] - if delim == '' + if delim ==# '' return '' 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 " count 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)) @@ -3052,7 +3052,7 @@ function! s:CreateMaps(modes, target, desc, combo) endif let menu_command .= ' ' . (strlen(a:combo) ? plug : a:target) " 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) execute mode . plug_start . mode . plug_end if g:NERDCreateDefaultMappings && !hasmapto(plug, mode) @@ -3060,7 +3060,7 @@ function! s:CreateMaps(modes, target, desc, combo) endif endif " Check if the user wants the menu to be displayed. - if g:NERDMenuMode != 0 + if g:NERDMenuMode !=# 0 execute mode . menu_command endif endfor