kate Library API Documentation

kateautoindent.h

00001 /* This file is part of the KDE libraries
00002    Copyright (C) 2003 Jesse Yurkovich <yurkjes@iit.edu>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License version 2 as published by the Free Software Foundation.
00007 
00008    This library is distributed in the hope that it will be useful,
00009    but WITHOUT ANY WARRANTY; without even the implied warranty of
00010    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011    Library General Public License for more details.
00012 
00013    You should have received a copy of the GNU Library General Public License
00014    along with this library; see the file COPYING.LIB.  If not, write to
00015    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00016    Boston, MA 02111-1307, USA.
00017 */
00018 
00019 #ifndef __KATE_AUTO_INDENT_H__
00020 #define __KATE_AUTO_INDENT_H__
00021 
00022 #include "katecursor.h"
00023 #include "kateconfig.h"
00024 
00025 class KateDocument;
00026 
00030 class KateAutoIndent
00031 {
00035   public:
00042     static KateAutoIndent *createIndenter (KateDocument *doc, uint mode);
00043 
00048     static QStringList listModes ();
00049 
00055     static QString modeName (uint mode);
00056 
00062     static QString modeDescription (uint mode);
00063 
00069     static uint modeNumber (const QString &name);
00070 
00071   public:
00076     KateAutoIndent (KateDocument *doc);
00077 
00081     virtual ~KateAutoIndent ();
00082 
00086     void updateConfig ();
00087 
00094     virtual void processNewline (KateDocCursor &cur, bool needContinue);
00095 
00100     virtual void processChar (QChar /*c*/) { }
00101 
00105     virtual void processLine (KateDocCursor &/*line*/) { }
00106 
00110     virtual void processSection (KateDocCursor &/*begin*/, KateDocCursor &/*end*/) { }
00111 
00116     virtual bool canProcessLine() { return false; }
00117 
00122     virtual uint modeNumber () const { return KateDocumentConfig::imNormal; };
00123 
00124   protected:
00125 
00137     bool isBalanced (KateDocCursor &begin, const KateDocCursor &end, QChar open, QChar close, uint &pos) const;
00138 
00148     bool skipBlanks (KateDocCursor &cur, KateDocCursor &max, bool newline) const;
00149 
00156     uint measureIndent (KateDocCursor &cur) const;
00157 
00164     QString tabString(uint length) const;
00165 
00166     KateDocument *doc;
00167 
00168     uint  tabWidth;     
00169     uint  indentWidth;  
00170 
00171     // Attributes that we should skip over or otherwise know about
00172     uchar commentAttrib;
00173     uchar doxyCommentAttrib;
00174     uchar regionAttrib;
00175     uchar symbolAttrib;
00176     uchar alertAttrib;
00177     uchar tagAttrib;
00178     uchar wordAttrib;
00179 
00180     bool  useSpaces;    
00181     bool  keepProfile;  
00182 };
00183 
00184 class KateCSmartIndent : public KateAutoIndent
00185 {
00186   public:
00187     KateCSmartIndent (KateDocument *doc);
00188     ~KateCSmartIndent ();
00189 
00190     virtual void processNewline (KateDocCursor &begin, bool needContinue);
00191     virtual void processChar (QChar c);
00192 
00193     virtual void processLine (KateDocCursor &line);
00194     virtual void processSection (KateDocCursor &begin, KateDocCursor &end);
00195 
00196     virtual bool canProcessLine() { return true; }
00197 
00198     virtual uint modeNumber () const { return KateDocumentConfig::imCStyle; };
00199 
00200   private:
00201     uint calcIndent (KateDocCursor &begin, bool needContinue);
00202     uint calcContinue (KateDocCursor &begin, KateDocCursor &end);
00203     uint findOpeningBrace (KateDocCursor &start);
00204     uint findOpeningParen (KateDocCursor &start);
00205     uint findOpeningComment (KateDocCursor &start);
00206     bool firstOpeningBrace (KateDocCursor &start);
00207     bool handleDoxygen (KateDocCursor &begin);
00208 
00209     bool allowSemi;
00210     bool processingBlock;
00211 };
00212 
00213 class KatePythonIndent : public KateAutoIndent
00214 {
00215   public:
00216     KatePythonIndent (KateDocument *doc);
00217     ~KatePythonIndent ();
00218 
00219     virtual void processNewline (KateDocCursor &begin, bool needContinue);
00220 
00221     virtual uint modeNumber () const { return KateDocumentConfig::imPythonStyle; };
00222 
00223   private:
00224     int calcExtra (int &prevBlock, int &pos, KateDocCursor &end);
00225 
00226     static QRegExp endWithColon;
00227     static QRegExp stopStmt;
00228     static QRegExp blockBegin;
00229 };
00230 
00231 #endif
00232 
00233 // kate: space-indent on; indent-width 2; replace-tabs on;
KDE Logo
This file is part of the documentation for kate Library Version 3.3.1.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat Jan 22 16:52:50 2005 by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2003