#NEWLINE# def find_enclosing_bracket_left( self , left_ch , right_ch , start_pos = None ) : #NEWLINE# #INDENT# "\n        Find the left bracket enclosing current position. Return the relative\n        position to the cursor position.\n\n        When `start_pos` is given, don't look past the position.\n        " #NEWLINE# if ( self . current_char == left_ch ) : #NEWLINE# #INDENT# return 0 #NEWLINE# #UNINDENT# if ( start_pos is None ) : #NEWLINE# #INDENT# start_pos = 0 #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# start_pos = max ( 0 , start_pos ) #NEWLINE# #UNINDENT# stack = 1 #NEWLINE# for i in range ( ( self . cursor_position - 1 ) , ( start_pos - 1 ) , ( - 1 ) ) : #NEWLINE# #INDENT# c = self . text [ i ] #NEWLINE# if ( c == right_ch ) : #NEWLINE# #INDENT# stack += 1 #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( c == left_ch ) : #NEWLINE# #INDENT# stack -= 1 #NEWLINE# #UNINDENT# #UNINDENT# if ( stack == 0 ) : #NEWLINE# #INDENT# return ( i - self . cursor_position )