'If \'forward\' is True (resp. False), proceed forwards
(resp. backwards) through the line that contains \'position\' until an
unmatched closing (resp. opening) parenthesis is found. Returns a
tuple containing the position of this parenthesis (or -1 if it is
not found) and the number commas (at depth 0) found along the way.'

def _find_parenthesis(self, position, forward=True):

    commas = depth = 0
    document = self._text_edit.document()
    char = to_text_string(document.characterAt(position))
    while ((category(char) != 'Cc') and (position > 0)):
        if ((char == ',') and (depth == 0)):
            commas += 1
        elif (char == ')'):
            if (forward and (depth == 0)):
                break
            depth += 1
        elif (char == '('):
            if ((not forward) and (depth == 0)):
                break
            depth -= 1
        position += (1 if forward else (-1))
        char = to_text_string(document.characterAt(position))
    else:
        position = (-1)
    return (position, commas)
