KDevelop API Documentation

editors/qeditor/python_indent.cpp

Go to the documentation of this file.
00001 /* 00002 * Copyright (C) 2002 Roberto Raggi (roberto@kdevelop.org) 00003 * 00004 * This program is free software; you can redistribute it and/or 00005 * modify it under the terms of the GNU General Public 00006 * License as published by the Free Software Foundation; either 00007 * version 2 of the License, or (at your option) any later version. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 * Library General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; see the file COPYING.LIB. If not, write to 00016 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 00017 * Boston, MA 02111-1307, USA. 00018 * 00019 */ 00020 00021 #include "python_indent.h" 00022 #include "qeditor.h" 00023 #include "paragdata.h" 00024 #include <kdebug.h> 00025 00026 PythonIndent::PythonIndent( QEditor* ed ) 00027 : QEditorIndenter( ed ), 00028 rxLineEndedWithAColon( "^[^#]*:\\s*(#.*)?$" ), 00029 rxStopExecutionStmt( "^\\s*(break|continue|raise|return|pass)\\b.*" ), 00030 rxHeaderKeyword( "^\\s*(elif|else|except|finaly)\\b.*" ), 00031 rxOneLinerStmt( "^\\s*(for|if|try)\\b.*" ) 00032 { 00033 } 00034 00035 PythonIndent::~PythonIndent() 00036 { 00037 } 00038 00039 int PythonIndent::indentForLine( int line ) 00040 { 00041 if( line == 0 ) 00042 return 0; 00043 00044 int prevLine = QMAX( 0, previousNonBlankLine( line ) ); 00045 int sw = 4; 00046 00047 QString lineText = editor()->text( line ); 00048 QString prevLineText = editor()->text( prevLine ); 00049 00050 int lineInd = indentation( lineText ); 00051 int prevLineInd = indentation( prevLineText ); 00052 00053 int extraInd = 0; 00054 00055 ParagData* data = (ParagData*) editor()->document()->paragAt( prevLine )->extraData(); 00056 if( data ){ 00057 QValueList<Symbol> symbolList = data->symbolList(); 00058 QValueList<Symbol>::Iterator it = symbolList.begin(); 00059 while( it != symbolList.end() ){ 00060 const Symbol& sym = *it; 00061 ++it; 00062 00063 if ( sym.type() == Symbol::Left ) 00064 extraInd += 4; 00065 else if( sym.type() == Symbol::Right ) 00066 extraInd -= 4; 00067 } 00068 } 00069 00070 if( rxLineEndedWithAColon.exactMatch(prevLineText) ){ 00071 return QMAX( prevLineInd + sw + extraInd, 0 ); 00072 00073 } else if( rxStopExecutionStmt.exactMatch(prevLineText) ){ 00074 return QMAX( prevLineInd + sw + extraInd, 0 ); 00075 00076 } else if( rxHeaderKeyword.exactMatch(lineText) ){ 00077 00078 if( rxOneLinerStmt.exactMatch(prevLineText) ) 00079 return QMAX( prevLineInd + extraInd, 0 ); 00080 00081 return QMAX( prevLineInd - sw + extraInd, 0 ); 00082 00083 } else 00084 return QMAX( prevLineInd + extraInd, 0 ); 00085 } 00086
KDE Logo
This file is part of the documentation for KDevelop Version 3.0.4.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Tue Oct 19 08:01:38 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003