dont use b: vars to store the comment delim data, use a hash

This commit is contained in:
marty
2010-08-01 20:51:47 +12:00
parent cea72da179
commit e0191f2ce9

View File

@@ -402,41 +402,27 @@ augroup END
" set for this buffer. " set for this buffer.
" "
function s:SetUpForNewFiletype(filetype, forceReset) function s:SetUpForNewFiletype(filetype, forceReset)
"if we have already set the delimiters for this buffer then dont go thru
"it again
if !a:forceReset && exists("b:NERDLeft") && b:NERDLeft != ''
return
endif
let b:NERDSexyComMarker = '' let b:NERDSexyComMarker = ''
if has_key(s:delimiterMap, a:filetype) if has_key(s:delimiterMap, a:filetype)
let data = s:delimiterMap[a:filetype] let b:NERDCommenterDelims = s:delimiterMap[a:filetype]
for i in ['left', 'leftAlt', 'right', 'rightAlt']
let left = has_key(data, 'left') ? data['left'] : '' if !has_key(b:NERDCommenterDelims, i)
let right = has_key(data, 'right') ? data['right'] : '' let b:NERDCommenterDelims[i] = ''
let leftAlt = has_key(data, 'leftAlt') ? data['leftAlt'] : '' endif
let rightAlt = has_key(data, 'rightAlt') ? data['rightAlt'] : '' endfor
else else
let b:NERDCommenterDelims = s:CreateDelimMapFromCms()
"extract the delims from &commentstring
let left= substitute(&commentstring, '\([^ \t]*\)\s*%s.*', '\1', '')
let right= substitute(&commentstring, '.*%s\s*\(.*\)', '\1', 'g')
let leftAlt = ''
let rightAlt = ''
endif endif
if !exists('g:NERD_' . &filetype . '_alt_style') endfunction
let b:NERDLeft = left
let b:NERDRight = right function s:CreateDelimMapFromCms()
let b:NERDLeftAlt = leftAlt return {
let b:NERDRightAlt = rightAlt \ 'left': substitute(&commentstring, '\([^ \t]*\)\s*%s.*', '\1', ''),
else \ 'right': substitute(&commentstring, '.*%s\s*\(.*\)', '\1', 'g'),
let b:NERDLeft = leftAlt \ 'leftAlt': '',
let b:NERDRight = rightAlt \ 'rightAlt': '' }
let b:NERDLeftAlt = left
let b:NERDRightAlt = right
endif
endfunction endfunction
" Function: s:SwitchToAlternativeDelimiters(printMsgs) function {{{2 " Function: s:SwitchToAlternativeDelimiters(printMsgs) function {{{2
@@ -451,7 +437,7 @@ endfunction
function s:SwitchToAlternativeDelimiters(printMsgs) function s:SwitchToAlternativeDelimiters(printMsgs)
"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:NERDLeftAlt == "" && b:NERDRightAlt == "" 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
@@ -459,22 +445,20 @@ function s:SwitchToAlternativeDelimiters(printMsgs)
endif endif
"save the current delimiters "save the current delimiters
let tempLeft = b:NERDLeft let tempLeft = s:GetLeft(0,0,0)
let tempRight = b:NERDRight let tempRight = s:GetRight(0,0,0)
"swap current delimiters for alternative "swap current delimiters for alternative
let b:NERDLeft = b:NERDLeftAlt let b:NERDCommenterDelims['left'] = b:NERDCommenterDelims['leftAlt']
let b:NERDRight = b:NERDRightAlt let b:NERDCommenterDelims['right'] = b:NERDCommenterDelims['rightAlt']
"set the previously current delimiters to be the new alternative ones "set the previously current delimiters to be the new alternative ones
let b:NERDLeftAlt = tempLeft let b:NERDCommenterDelims['leftAlt'] = tempLeft
let b:NERDRightAlt = tempRight let b:NERDCommenterDelims['rightAlt'] = tempRight
"tell the user what comment delimiters they are now using "tell the user what comment delimiters they are now using
if a:printMsgs if a:printMsgs
let leftNoEsc = b:NERDLeft call s:NerdEcho("Now using " . s:GetLeft(0,0,0) . " " . s:GetRight(0,0,0) . " to delimit comments", 1)
let rightNoEsc = b:NERDRight
call s:NerdEcho("Now using " . leftNoEsc . " " . rightNoEsc . " to delimit comments", 1)
endif endif
return 1 return 1
@@ -603,19 +587,19 @@ function s:CommentBlock(top, bottom, lSide, rSide, forceNested )
"stick the right delimiter down "stick the right delimiter down
let theLine = strpart(theLine, 0, rSide+strlen(leftSpaced)) . rightSpaced . strpart(theLine, rSide+strlen(leftSpaced)) let theLine = strpart(theLine, 0, rSide+strlen(leftSpaced)) . rightSpaced . strpart(theLine, rSide+strlen(leftSpaced))
let firstLeftDelim = s:FindDelimiterIndex(b:NERDLeft, theLine) let firstLeftDelim = s:FindDelimiterIndex(s:GetLeft(0,0,0), theLine)
let lastRightDelim = s:LastIndexOfDelim(b:NERDRight, theLine) let lastRightDelim = s:LastIndexOfDelim(s:GetRight(0,0,0), 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(b:NERDLeft)) let searchStr = strpart(searchStr, firstLeftDelim+strlen(s:GetLeft(0,0,0)))
"replace the outter most delims in searchStr with "replace the outter most delims in searchStr with
"place-holders "place-holders
let theLineWithPlaceHolders = s:ReplaceDelims(b:NERDLeft, b:NERDRight, g:NERDLPlace, g:NERDRPlace, searchStr) let theLineWithPlaceHolders = s:ReplaceDelims(s:GetLeft(0,0,0), s:GetRight(0,0,0), g:NERDLPlace, g:NERDRPlace, searchStr)
"add the right delimiter onto the line "add the right delimiter onto the line
let theLine = strpart(theLine, 0, firstLeftDelim+strlen(b:NERDLeft)) . theLineWithPlaceHolders . strpart(theLine, lastRightDelim) let theLine = strpart(theLine, 0, firstLeftDelim+strlen(s:GetLeft(0,0,0))) . theLineWithPlaceHolders . strpart(theLine, lastRightDelim)
endif endif
endif endif
endif endif
@@ -674,7 +658,7 @@ function s:CommentLines(forceNested, align, firstLine, lastLine)
" find out if the line is commented using normal delims and/or " find out if the line is commented using normal delims and/or
" alternate ones " alternate ones
let isCommented = s:IsCommented(b:NERDLeft, b:NERDRight, theLine) || s:IsCommented(b:NERDLeftAlt, b:NERDRightAlt, theLine) let isCommented = s:IsCommented(s:GetLeft(0,0,0), s:GetRight(0,0,0), theLine) || s:IsCommented(s:GetLeft(1,0,0), s:GetRight(1,0,0), theLine)
" 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()
@@ -955,7 +939,7 @@ function s:CommentRegion(topLine, topCol, bottomLine, bottomCol, forceNested)
endif endif
"stick the cursor back on the char it was on before the comment "stick the cursor back on the char it was on before the comment
call cursor(a:topLine, a:topCol + strlen(b:NERDLeft) + g:NERDSpaceDelims) call cursor(a:topLine, a:topCol + strlen(s:GetLeft(0,0,0)) + g:NERDSpaceDelims)
"if we switched delims then we gotta go back to what they were before "if we switched delims then we gotta go back to what they were before
if switchedDelims == 1 if switchedDelims == 1
@@ -980,7 +964,7 @@ function s:InvertComment(firstLine, lastLine)
let sexyComBounds = s:FindBoundingLinesOfSexyCom(currentLine) let sexyComBounds = s:FindBoundingLinesOfSexyCom(currentLine)
" if the line is commented normally, uncomment it " if the line is commented normally, uncomment it
if s:IsCommentedFromStartOfLine(b:NERDLeft, theLine) || s:IsCommentedFromStartOfLine(b:NERDLeftAlt, theLine) if s:IsCommentedFromStartOfLine(s:GetLeft(0,0,0), theLine) || s:IsCommentedFromStartOfLine(s:GetLeft(1,0,0), theLine)
call s:UncommentLines(currentLine, currentLine) call s:UncommentLines(currentLine, currentLine)
let currentLine = currentLine + 1 let currentLine = currentLine + 1
@@ -1063,7 +1047,7 @@ function! NERDComment(isVisual, type) range
elseif a:type == 'toggle' elseif a:type == 'toggle'
let theLine = getline(firstLine) let theLine = getline(firstLine)
if s:IsInSexyComment(firstLine) || s:IsCommentedFromStartOfLine(b:NERDLeft, theLine) || s:IsCommentedFromStartOfLine(b:NERDLeftAlt, theLine) if s:IsInSexyComment(firstLine) || s:IsCommentedFromStartOfLine(s:GetLeft(0,0,0), theLine) || s:IsCommentedFromStartOfLine(s:GetLeft(1,0,0), theLine)
call s:UncommentLines(firstLine, lastLine) call s:UncommentLines(firstLine, lastLine)
else else
call s:CommentLinesToggle(forceNested, firstLine, lastLine) call s:CommentLinesToggle(forceNested, firstLine, lastLine)
@@ -1380,54 +1364,54 @@ function s:UncommentLineNormal(line)
let line = a:line let line = a:line
"get the comment status on the line so we know how it is commented "get the comment status on the line so we know how it is commented
let lineCommentStatus = s:IsCommentedOuttermost(b:NERDLeft, b:NERDRight, b:NERDLeftAlt, b:NERDRightAlt, line) let lineCommentStatus = s:IsCommentedOuttermost(s:GetLeft(0,0,0), s:GetRight(0,0,0), s:GetLeft(1,0,0), s:GetRight(1,0,0), line)
"it is commented with b:NERDLeft and b:NERDRight so remove these delims "it is commented with s:GetLeft(0,0,0) and s:GetRight(0,0,0) so remove these delims
if lineCommentStatus == 1 if lineCommentStatus == 1
let line = s:RemoveDelimiters(b:NERDLeft, b:NERDRight, line) let line = s:RemoveDelimiters(s:GetLeft(0,0,0), s:GetRight(0,0,0), line)
"it is commented with b:NERDLeftAlt and b:NERDRightAlt so remove these delims "it is commented with s:GetLeft(1,0,0) and s:GetRight(1,0,0) so remove these delims
elseif lineCommentStatus == 2 && g:NERDRemoveAltComs elseif lineCommentStatus == 2 && g:NERDRemoveAltComs
let line = s:RemoveDelimiters(b:NERDLeftAlt, b:NERDRightAlt, line) let line = s:RemoveDelimiters(s:GetLeft(1,0,0), s:GetRight(1,0,0), line)
"it is not properly commented with any delims so we check if it has "it is not properly commented with any delims so we check if it has
"any random left or right delims on it and remove the outtermost ones "any random left or right delims on it and remove the outtermost ones
else else
"get the positions of all delim types on the line "get the positions of all delim types on the line
let indxLeft = s:FindDelimiterIndex(b:NERDLeft, line) let indxLeft = s:FindDelimiterIndex(s:GetLeft(0,0,0), line)
let indxLeftAlt = s:FindDelimiterIndex(b:NERDLeftAlt, line) let indxLeftAlt = s:FindDelimiterIndex(s:GetLeft(1,0,0), line)
let indxRight = s:FindDelimiterIndex(b:NERDRight, line) let indxRight = s:FindDelimiterIndex(s:GetRight(0,0,0), line)
let indxRightAlt = s:FindDelimiterIndex(b:NERDRightAlt, line) let indxRightAlt = s:FindDelimiterIndex(s:GetRight(1,0,0), line)
"remove the outter most left comment delim "remove the outter most left comment delim
if indxLeft != -1 && (indxLeft < indxLeftAlt || indxLeftAlt == -1) if indxLeft != -1 && (indxLeft < indxLeftAlt || indxLeftAlt == -1)
let line = s:RemoveDelimiters(b:NERDLeft, '', line) let line = s:RemoveDelimiters(s:GetLeft(0,0,0), '', line)
elseif indxLeftAlt != -1 elseif indxLeftAlt != -1
let line = s:RemoveDelimiters(b:NERDLeftAlt, '', line) let line = s:RemoveDelimiters(s:GetLeft(1,0,0), '', line)
endif endif
"remove the outter most right comment delim "remove the outter most right comment delim
if indxRight != -1 && (indxRight < indxRightAlt || indxRightAlt == -1) if indxRight != -1 && (indxRight < indxRightAlt || indxRightAlt == -1)
let line = s:RemoveDelimiters('', b:NERDRight, line) let line = s:RemoveDelimiters('', s:GetRight(0,0,0), line)
elseif indxRightAlt != -1 elseif indxRightAlt != -1
let line = s:RemoveDelimiters('', b:NERDRightAlt, line) let line = s:RemoveDelimiters('', s:GetRight(1,0,0), line)
endif endif
endif endif
let indxLeft = s:FindDelimiterIndex(b:NERDLeft, line) let indxLeft = s:FindDelimiterIndex(s:GetLeft(0,0,0), line)
let indxLeftAlt = s:FindDelimiterIndex(b:NERDLeftAlt, line) let indxLeftAlt = s:FindDelimiterIndex(s:GetLeft(1,0,0), line)
let indxLeftPlace = s:FindDelimiterIndex(g:NERDLPlace, line) let indxLeftPlace = s:FindDelimiterIndex(g:NERDLPlace, line)
let indxRightPlace = s:FindDelimiterIndex(g:NERDRPlace, line) let indxRightPlace = s:FindDelimiterIndex(g:NERDRPlace, line)
let indxRightAlt = s:FindDelimiterIndex(b:NERDRightAlt, line) let indxRightAlt = s:FindDelimiterIndex(s:GetRight(1,0,0), line)
let indxRightPlace = s:FindDelimiterIndex(g:NERDRPlace, line) let indxRightPlace = s:FindDelimiterIndex(g:NERDRPlace, line)
let right = b:NERDRight let right = s:GetRight(0,0,0)
let left = b:NERDLeft let left = s:GetLeft(0,0,0)
if !s:Multipart() if !s:Multipart()
let right = b:NERDRightAlt let right = s:GetRight(1,0,0)
let left = b:NERDLeftAlt let left = s:GetLeft(1,0,0)
endif endif
@@ -1518,7 +1502,7 @@ endfunction
" Function: s:AltMultipart() {{{2 " Function: s:AltMultipart() {{{2
" returns 1 if the alternative delims are multipart " returns 1 if the alternative delims are multipart
function s:AltMultipart() function s:AltMultipart()
return b:NERDRightAlt != '' return b:NERDCommenterDelims['rightAlt'] != ''
endfunction endfunction
" Function: s:CanCommentLine(forceNested, line) {{{2 " Function: s:CanCommentLine(forceNested, line) {{{2
@@ -1589,7 +1573,7 @@ endfunction
" -lineNum: the line num of the line to check for commentability " -lineNum: the line num of the line to check for commentability
function s:CanToggleCommentLine(forceNested, lineNum) function s:CanToggleCommentLine(forceNested, lineNum)
let theLine = getline(a:lineNum) let theLine = getline(a:lineNum)
if (s:IsCommentedFromStartOfLine(b:NERDLeft, theLine) || s:IsCommentedFromStartOfLine(b:NERDLeftAlt, theLine)) && !a:forceNested if (s:IsCommentedFromStartOfLine(s:GetLeft(0,0,0), theLine) || s:IsCommentedFromStartOfLine(s:GetLeft(1,0,0), theLine)) && !a:forceNested
return 0 return 0
endif endif
@@ -1709,9 +1693,9 @@ endfunction
function s:DoesBlockHaveMultipartDelim(top, bottom) function s:DoesBlockHaveMultipartDelim(top, bottom)
if s:HasMultipartDelims() if s:HasMultipartDelims()
if s:Multipart() if s:Multipart()
return s:DoesBlockHaveDelim(b:NERDLeft, a:top, a:bottom) || s:DoesBlockHaveDelim(b:NERDRight, a:top, a:bottom) return s:DoesBlockHaveDelim(s:GetLeft(0,0,0), a:top, a:bottom) || s:DoesBlockHaveDelim(s:GetRight(0,0,0), a:top, a:bottom)
else else
return s:DoesBlockHaveDelim(b:NERDLeftAlt, a:top, a:bottom) || s:DoesBlockHaveDelim(b:NERDRightAlt, a:top, a:bottom) return s:DoesBlockHaveDelim(s:GetLeft(1,0,0), a:top, a:bottom) || s:DoesBlockHaveDelim(s:GetRight(1,0,0), a:top, a:bottom)
endif endif
endif endif
return 0 return 0
@@ -1861,15 +1845,8 @@ endfunction
" (the space string will only be added if NERDSpaceDelims is set) " (the space string will only be added if NERDSpaceDelims is set)
" -esc: specifies whether the tricky chars in the delim should be ESCed " -esc: specifies whether the tricky chars in the delim should be ESCed
function s:GetLeft(alt, space, esc) function s:GetLeft(alt, space, esc)
let delim = b:NERDLeft let delim = a:alt ? b:NERDCommenterDelims['leftAlt'] : b:NERDCommenterDelims['left']
if a:alt
if b:NERDLeftAlt == ''
return ''
else
let delim = b:NERDLeftAlt
endif
endif
if delim == '' if delim == ''
return '' return ''
endif endif
@@ -1893,15 +1870,8 @@ endfunction
" (the space string will only be added if NERDSpaceDelims is set) " (the space string will only be added if NERDSpaceDelims is set)
" -esc: specifies whether the tricky chars in the delim should be ESCed " -esc: specifies whether the tricky chars in the delim should be ESCed
function s:GetRight(alt, space, esc) function s:GetRight(alt, space, esc)
let delim = b:NERDRight let delim = a:alt ? b:NERDCommenterDelims['rightAlt'] : b:NERDCommenterDelims['right']
if a:alt
if !s:AltMultipart()
return ''
else
let delim = b:NERDRightAlt
endif
endif
if delim == '' if delim == ''
return '' return ''
endif endif
@@ -1942,14 +1912,14 @@ function s:GetSexyComMarker(space, esc)
else else
"find a comment marker by getting the longest available left delim "find a comment marker by getting the longest available left delim
"(that has a corresponding right delim) and taking the last char "(that has a corresponding right delim) and taking the last char
let lenLeft = strlen(b:NERDLeft) let lenLeft = strlen(s:GetLeft(0,0,0))
let lenLeftAlt = strlen(b:NERDLeftAlt) let lenLeftAlt = strlen(s:GetLeft(1,0,0))
let left = '' let left = ''
let right = '' let right = ''
if s:Multipart() && lenLeft >= lenLeftAlt if s:Multipart() && lenLeft >= lenLeftAlt
let left = b:NERDLeft let left = s:GetLeft(0,0,0)
elseif s:AltMultipart() elseif s:AltMultipart()
let left = b:NERDLeftAlt let left = s:GetLeft(1,0,0)
else else
return -1 return -1
endif endif
@@ -1978,8 +1948,8 @@ endfunction
" (the space string will only be added if NERDSpaceDelims is set) " (the space string will only be added if NERDSpaceDelims is set)
" -esc: specifies whether the tricky chars in the string are ESCed " -esc: specifies whether the tricky chars in the string are ESCed
function s:GetSexyComLeft(space, esc) function s:GetSexyComLeft(space, esc)
let lenLeft = strlen(b:NERDLeft) let lenLeft = strlen(s:GetLeft(0,0,0))
let lenLeftAlt = strlen(b:NERDLeftAlt) let lenLeftAlt = strlen(s:GetLeft(1,0,0))
let left = '' let left = ''
"assume c style sexy comments if possible "assume c style sexy comments if possible
@@ -1988,9 +1958,9 @@ function s:GetSexyComLeft(space, esc)
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
let left = b:NERDLeft let left = s:GetLeft(0,0,0)
elseif s:AltMultipart() elseif s:AltMultipart()
let left = b:NERDLeftAlt let left = s:GetLeft(1,0,0)
else else
return -1 return -1
endif endif
@@ -2016,8 +1986,8 @@ endfunction
" is specified for the current filetype) " is specified for the current filetype)
" -esc: specifies whether the tricky chars in the string are ESCed " -esc: specifies whether the tricky chars in the string are ESCed
function s:GetSexyComRight(space, esc) function s:GetSexyComRight(space, esc)
let lenLeft = strlen(b:NERDLeft) let lenLeft = strlen(s:GetLeft(0,0,0))
let lenLeftAlt = strlen(b:NERDLeftAlt) let lenLeftAlt = strlen(s:GetLeft(1,0,0))
let right = '' let right = ''
"assume c style sexy comments if possible "assume c style sexy comments if possible
@@ -2026,9 +1996,9 @@ function s:GetSexyComRight(space, esc)
else else
"grab the right delim that pairs with the longest left delim "grab the right delim that pairs with the longest left delim
if s:Multipart() && lenLeft >= lenLeftAlt if s:Multipart() && lenLeft >= lenLeftAlt
let right = b:NERDRight let right = s:GetRight(0,0,0)
elseif s:AltMultipart() elseif s:AltMultipart()
let right = b:NERDRightAlt let right = s:GetRight(1,0,0)
else else
return -1 return -1
endif endif
@@ -2064,7 +2034,7 @@ endfunction
" Function: s:HasCStyleComments() {{{2 " Function: s:HasCStyleComments() {{{2
" Returns 1 iff the current filetype has c style comment delimiters " Returns 1 iff the current filetype has c style comment delimiters
function s:HasCStyleComments() function s:HasCStyleComments()
return (b:NERDLeft == '/*' && b:NERDRight == '*/') || (b:NERDLeftAlt == '/*' && b:NERDRightAlt == '*/') return (s:GetLeft(0,0,0) == '/*' && s:GetRight(0,0,0) == '*/') || (s:GetLeft(1,0,0) == '/*' && s:GetRight(1,0,0) == '*/')
endfunction endfunction
" Function: s:IsCommentedNormOrSexy(lineNum) {{{2 " Function: s:IsCommentedNormOrSexy(lineNum) {{{2
@@ -2077,7 +2047,7 @@ function s:IsCommentedNormOrSexy(lineNum)
let theLine = getline(a:lineNum) let theLine = getline(a:lineNum)
"if the line is commented normally return 1 "if the line is commented normally return 1
if s:IsCommented(b:NERDLeft, b:NERDRight, theLine) || s:IsCommented(b:NERDLeftAlt, b:NERDRightAlt, theLine) if s:IsCommented(s:GetLeft(0,0,0), s:GetRight(0,0,0), theLine) || s:IsCommented(s:GetLeft(1,0,0), s:GetRight(1,0,0), theLine)
return 1 return 1
endif endif
@@ -2293,11 +2263,11 @@ function s:IsSexyComment(topline, bottomline)
let left = '' let left = ''
let right = '' let right = ''
if s:Multipart() if s:Multipart()
let left = b:NERDLeft let left = s:GetLeft(0,0,0)
let right = b:NERDRight let right = s:GetRight(0,0,0)
elseif s:AltMultipart() elseif s:AltMultipart()
let left = b:NERDLeftAlt let left = s:GetLeft(1,0,0)
let right = b:NERDRightAlt let right = s:GetRight(1,0,0)
else else
return 0 return 0
endif endif
@@ -2422,7 +2392,7 @@ function s:LeftMostIndx(countCommentedLines, countEmptyLines, topline, bottomlin
" 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(b:NERDLeft, b:NERDRight, theLine) && !s:IsCommented(b:NERDLeftAlt, b:NERDRightAlt, theLine)) if a:countCommentedLines || (!s:IsCommented(s:GetLeft(0,0,0), s:GetRight(0,0,0), theLine) && !s:IsCommented(s:GetLeft(1,0,0), s:GetRight(1,0,0), 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
let theLine = s:ConvertLeadingTabsToSpaces(theLine) let theLine = s:ConvertLeadingTabsToSpaces(theLine)
@@ -2447,7 +2417,7 @@ endfunction
" Function: s:Multipart() {{{2 " Function: s:Multipart() {{{2
" returns 1 if the current delims are multipart " returns 1 if the current delims are multipart
function s:Multipart() function s:Multipart()
return b:NERDRight != '' return s:GetRight(0,0,0) != ''
endfunction endfunction
" Function: s:NerdEcho(msg, typeOfMsg) {{{2 " Function: s:NerdEcho(msg, typeOfMsg) {{{2
@@ -2578,7 +2548,7 @@ function s:RightMostIndx(countCommentedLines, countEmptyLines, topline, bottomli
let theLine = getline(currentLine) let theLine = getline(currentLine)
if a:countEmptyLines || theLine !~ '^[ \t]*$' if a:countEmptyLines || theLine !~ '^[ \t]*$'
if a:countCommentedLines || (!s:IsCommented(b:NERDLeft, b:NERDRight, theLine) && !s:IsCommented(b:NERDLeftAlt, b:NERDRightAlt, theLine)) if a:countCommentedLines || (!s:IsCommented(s:GetLeft(0,0,0), s:GetRight(0,0,0), theLine) && !s:IsCommented(s:GetLeft(1,0,0), s:GetRight(1,0,0), theLine))
" update rightMostIndx if need be " update rightMostIndx if need be
let theLine = s:ConvertLeadingTabsToSpaces(theLine) let theLine = s:ConvertLeadingTabsToSpaces(theLine)
@@ -2613,20 +2583,20 @@ endfunction
function s:SwapOutterMultiPartDelimsForPlaceHolders(line) function s:SwapOutterMultiPartDelimsForPlaceHolders(line)
" find out if the line is commented using normal delims and/or " find out if the line is commented using normal delims and/or
" alternate ones " alternate ones
let isCommented = s:IsCommented(b:NERDLeft, b:NERDRight, a:line) let isCommented = s:IsCommented(s:GetLeft(0,0,0), s:GetRight(0,0,0), a:line)
let isCommentedAlt = s:IsCommented(b:NERDLeftAlt, b:NERDRightAlt, a:line) let isCommentedAlt = s:IsCommented(s:GetLeft(1,0,0), s:GetRight(1,0,0), a:line)
let line2 = a:line let line2 = a:line
"if the line is commented and there is a right delimiter, replace "if the line is commented and there is a right delimiter, replace
"the delims with place-holders "the delims with place-holders
if isCommented && s:Multipart() if isCommented && s:Multipart()
let line2 = s:ReplaceDelims(b:NERDLeft, b:NERDRight, g:NERDLPlace, g:NERDRPlace, a:line) let line2 = s:ReplaceDelims(s:GetLeft(0,0,0), s:GetRight(0,0,0), g:NERDLPlace, g:NERDRPlace, a:line)
"similarly if the line is commented with the alternative "similarly if the line is commented with the alternative
"delimiters "delimiters
elseif isCommentedAlt && s:AltMultipart() elseif isCommentedAlt && s:AltMultipart()
let line2 = s:ReplaceDelims(b:NERDLeftAlt, b:NERDRightAlt, g:NERDLPlace, g:NERDRPlace, a:line) let line2 = s:ReplaceDelims(s:GetLeft(1,0,0), s:GetRight(1,0,0), g:NERDLPlace, g:NERDRPlace, a:line)
endif endif
return line2 return line2
@@ -2642,11 +2612,11 @@ function s:SwapOutterPlaceHoldersForMultiPartDelims(line)
let left = '' let left = ''
let right = '' let right = ''
if s:Multipart() if s:Multipart()
let left = b:NERDLeft let left = s:GetLeft(0,0,0)
let right = b:NERDRight let right = s:GetRight(0,0,0)
elseif s:AltMultipart() elseif s:AltMultipart()
let left = b:NERDLeftAlt let left = s:GetLeft(1,0,0)
let right = b:NERDRightAlt let right = s:GetRight(1,0,0)
endif endif
let line = s:ReplaceDelims(g:NERDLPlace, g:NERDRPlace, left, right, a:line) let line = s:ReplaceDelims(g:NERDLPlace, g:NERDRPlace, left, right, a:line)