@@ -51,6 +51,20 @@ function! s:IsSyntaxNameExcludedFromIndent(name)
5151 return a: name == # " swiftComment" || a: name == # " swiftString" || a: name == # " swiftInterpolatedWrapper" || a: name == # " swiftMultilineInterpolatedWrapper" || a: name == # " swiftMultilineString"
5252endfunction
5353
54+ " Description: Search for the position of the opening parenthesis '(' starting from the specified position.
55+ " Parameters:
56+ " startingPosition - A list [line_number, column_number] representing the position to start the search.
57+ " Returns: A list [line_number, column_number] representing the position of the opening parenthesis.
58+ function ! s: SearchOpeningParenPos (startingPosition)
59+ let currentLine = line (" ." )
60+ let currentColumn = col (" ." )
61+ call cursor (a: startingPosition [0 ], a: startingPosition [1 ])
62+ let openingParen = searchpairpos (" (" , " " , " )" , " bWn" , " s:IsExcludedFromIndent()" )
63+ call cursor (currentLine, currentColumn)
64+ return openingParen
65+ endfunction
66+
67+
5468function ! s: IsCommentLine (lnum)
5569 return synIDattr (synID (a: lnum ,
5670 \ match (getline (a: lnum ), " \\ S" ) + 1 , 0 ), " name" )
@@ -164,19 +178,11 @@ function! SwiftIndent(...)
164178 let numOpenParensBracketLine = s: NumberOfMatches (" (" , bracketLine, openingBracket)
165179 let numCloseParensBracketLine = s: NumberOfMatches (" )" , bracketLine, openingBracket)
166180 if numCloseParensBracketLine > numOpenParensBracketLine
167- let line = line (" ." )
168- let column = col (" ." )
169- call cursor (openingParen, column)
170- let openingParen = searchpair (" (" , " " , " )" , " bWn" , " s:IsExcludedFromIndent()" )
171- call cursor (line , column)
172- return indent (openingParen)
181+ let openingParenPos = s: SearchOpeningParenPos ([openingBracket, 1 ])
182+ return indent (openingParenPos[0 ])
173183 elseif numOpenParensBracketLine > numCloseParensBracketLine
174- let line = line (" ." )
175- let column = col (" ." )
176- call cursor (openingParen, column)
177- let openingParenCol = searchpairpos (" (" , " " , " )" , " bWn" , " s:IsExcludedFromIndent()" )[1 ]
178- call cursor (line , column)
179- return openingParenCol
184+ let openingParenPos = s: SearchOpeningParenPos ([line (" ." ), col (" ." )])
185+ return openingParenPos[1 ]
180186 endif
181187
182188 return indent (openingBracket)
0 commit comments