* and a boolean indicating if we're inside a parenthesis
*/
public static Tuple<Integer, Boolean> determineSmartIndent(int offset, IDocument document, IIndentPrefs prefs)
throws BadLocationException {
PythonPairMatcher matcher = new PythonPairMatcher(StringUtils.BRACKETS);
int openingPeerOffset = matcher.searchForAnyOpeningPeer(offset, document);
if (openingPeerOffset == -1) {
return new Tuple<Integer, Boolean>(-1, false);
}
final IRegion lineInformationOfOffset = document.getLineInformationOfOffset(openingPeerOffset);
//ok, now, if the opening peer is not on the line we're currently, we do not want to make
//an 'auto-indent', but keep the current indentation level
boolean openingPeerIsInCurrentLine = PySelection.isInside(offset, lineInformationOfOffset);
int len = -1;
String contents = "";
if (prefs.getIndentToParLevel()) {
//now, a catch, if we didn't change the indent level, we've to indent in the same level
//as the previous line, as this means that the user 'customized' the indent level at this place.
PySelection ps = new PySelection(document, offset);
String lineContentsToCursor = ps.getLineContentsToCursor();
if (!openingPeerIsInCurrentLine && !StringUtils.hasUnbalancedClosingPeers(lineContentsToCursor)) {
try {
char openingChar = document.getChar(openingPeerOffset);
int closingPeerOffset = matcher.searchForClosingPeer(openingPeerOffset, openingChar,
StringUtils.getPeer(openingChar), document);
if (closingPeerOffset == -1 || offset <= closingPeerOffset) {
return new Tuple<Integer, Boolean>(-1, true); // True because we're inside a parens
}