[Pydev-cvs] org.python.pydev/src/org/python/pydev/editor/autoedit PyAutoIndentStrategy.java,1.16,1.1
Brought to you by:
fabioz
From: Fabio Z. <fa...@us...> - 2005-10-17 16:59:09
|
Update of /cvsroot/pydev/org.python.pydev/src/org/python/pydev/editor/autoedit In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26922/src/org/python/pydev/editor/autoedit Modified Files: PyAutoIndentStrategy.java Log Message: Index: PyAutoIndentStrategy.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src/org/python/pydev/editor/autoedit/PyAutoIndentStrategy.java,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** PyAutoIndentStrategy.java 12 Oct 2005 20:43:30 -0000 1.16 --- PyAutoIndentStrategy.java 17 Oct 2005 16:58:59 -0000 1.17 *************** *** 11,14 **** --- 11,16 ---- import org.eclipse.jface.text.DocumentCommand; import org.eclipse.jface.text.IDocument; + import org.eclipse.jface.text.IRegion; + import org.python.copiedfromeclipsesrc.PythonPairMatcher; import org.python.pydev.core.docutils.DocUtils; import org.python.pydev.editor.actions.PyAction; *************** *** 71,77 **** text = initial + prefs.getIndentationString(); - } else if (lastChar == ',') { - text = indentAfterCommaNewline(document, text, offset); - }else{ //ok, normal indent until now... --- 73,76 ---- *************** *** 81,84 **** --- 80,85 ---- if(startsWithDedentToken(trimmedLine)){ text = dedent(text); + }else{ + text = indentAfterCommaNewline(document, text, offset); } } *************** *** 143,151 **** ! if (command.text.equals("(") && prefs.getAutoParentesis()) { PySelection ps = new PySelection(document, command.offset); String line = ps.getLine(); ! if (shouldClose(ps)) { boolean hasClass = line.indexOf("class ") != -1; --- 144,161 ---- ! if (prefs.getAutoParentesis() && (command.text.equals("[") || command.text.equals("{")) ) { ! PySelection ps = new PySelection(document, command.offset); ! char c = command.text.charAt(0); ! if (shouldClose(ps, c)) { ! command.shiftsCaret = false; ! command.text = c+""+DocUtils.getPeer(c); ! command.caretOffset = command.offset+1; ! } ! ! }else if (prefs.getAutoParentesis() && command.text.equals("(")) { PySelection ps = new PySelection(document, command.offset); String line = ps.getLine(); ! if (shouldClose(ps, '(')) { boolean hasClass = line.indexOf("class ") != -1; *************** *** 177,181 **** } ! /* * The following code will auto-replace colons in function --- 187,191 ---- } ! /* * The following code will auto-replace colons in function *************** *** 368,375 **** /** * @param ps * @return * @throws BadLocationException */ ! private boolean shouldClose(PySelection ps) throws BadLocationException { String line = ps.getLine(); --- 378,386 ---- /** * @param ps + * @param c the char to close * @return * @throws BadLocationException */ ! private boolean shouldClose(PySelection ps, char c) throws BadLocationException { String line = ps.getLine(); *************** *** 382,387 **** } ! int i = PyAction.countChars('(', line); ! int j = PyAction.countChars(')', line); if (j > i) { --- 393,398 ---- } ! int i = PyAction.countChars(c, line); ! int j = PyAction.countChars(c, line); if (j > i) { *************** *** 425,441 **** break; if (theChar == '(' || theChar == '[' || theChar == '{') { ! //ok, it's not just returning the line now, we have to check for tabs and make each ! //tab count for the tabWidth. ! int smartIndent = i+1; ! String string = line.substring(0, smartIndent - 1); ! ! for (int j = 0; j < string.length(); j++) { ! char c = string.charAt(j); ! if (c == '\t') { ! smartIndent += prefs.getTabWidth() - 1; ! } } - return smartIndent; } } --- 436,470 ---- break; + if (theChar == ')' || theChar == ']' || theChar == '}') { + char peer = DocUtils.getPeer(theChar); + if(PyAction.countChars(theChar, line) > PyAction.countChars(peer, line)){ + //ok, we have to do a dedent here + PythonPairMatcher matcher = new PythonPairMatcher(DocUtils.BRACKETS); + int openingPeerPosition = matcher.searchForOpeningPeer(offset, peer, theChar, document); + if(openingPeerPosition > 0){ + IRegion lineInformationOfOffset = document.getLineInformationOfOffset(openingPeerPosition); + int j = openingPeerPosition - lineInformationOfOffset.getOffset(); + return j+1; + } + } + } + if (theChar == '(' || theChar == '[' || theChar == '{') { ! char peer = DocUtils.getPeer(theChar); ! if(PyAction.countChars(theChar, line) > PyAction.countChars(peer, line)){ ! ! //ok, it's not just returning the line now, we have to check for tabs and make each ! //tab count for the tabWidth. ! int smartIndent = i+1; ! String string = line.substring(0, smartIndent - 1); ! ! for (int j = 0; j < string.length(); j++) { ! char c = string.charAt(j); ! if (c == '\t') { ! smartIndent += prefs.getTabWidth() - 1; ! } ! } ! return smartIndent; } } } |