KDevelop API Documentation

editors/qeditor/pascal_indent.cpp

Go to the documentation of this file.
00001 /*************************************************************************** 00002 * Copyright (C) 2003 Alexander Dymo * 00003 * cloudtemple@mksat.net * 00004 * * 00005 * This program is free software; you can redistribute it and/or modify * 00006 * it under the terms of the GNU General Public License as published by * 00007 * the Free Software Foundation; either version 2 of the License, or * 00008 * (at your option) any later version. * 00009 * * 00010 ***************************************************************************/ 00011 #include "pascal_indent.h" 00012 #include "qeditor.h" 00013 #include "paragdata.h" 00014 #include <kdebug.h> 00015 00016 PascalIndent::PascalIndent( QEditor* ed ) 00017 : QEditorIndenter( ed ), 00018 rxCompoundStmt("^\\s*(begin|for|try|while|case|repeat|if|else|var|const|type)\\b.*") 00019 { 00020 } 00021 00022 PascalIndent::~PascalIndent() 00023 { 00024 } 00025 00026 int PascalIndent::indentForLine( int line ) 00027 { 00028 if( line == 0 ) 00029 return 0; 00030 00031 int prevLine = QMAX( 0, previousNonBlankLine( line ) ); 00032 const int sw = 4; 00033 00034 QString lineText = editor()->text( line ); 00035 QString prevLineText = editor()->text( prevLine ); 00036 00037 int lineInd = indentation( lineText ); 00038 int prevLineInd = indentation( prevLineText ); 00039 00040 int extraInd = 0; 00041 00042 ParagData* data = (ParagData*) editor()->document()->paragAt( prevLine )->extraData(); 00043 if( data ){ 00044 QValueList<Symbol> symbolList = data->symbolList(); 00045 QValueList<Symbol>::Iterator it = symbolList.begin(); 00046 while( it != symbolList.end() ){ 00047 const Symbol& sym = *it; 00048 ++it; 00049 00050 if ( sym.type() == Symbol::Left ) 00051 extraInd += 4; 00052 else if( sym.type() == Symbol::Right ) 00053 extraInd -= 4; 00054 } 00055 } 00056 00057 kdDebug() << "lineText=" << lineText << " prevLineText=" << prevLineText << " indent prev=" << lineInd << endl; 00058 kdDebug() << "extraInd is " << extraInd << endl; 00059 00060 if (rxCompoundStmt.exactMatch(prevLineText)) 00061 { 00062 kdDebug() << "exact match for compound statement match" << endl; 00063 return QMAX( prevLineInd + sw + extraInd, 0 ); 00064 } 00065 else 00066 return QMAX( prevLineInd + extraInd, 0 ); 00067 } 00068
KDE Logo
This file is part of the documentation for KDevelop Version 3.0.4.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Oct 6 17:38:56 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003