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 
00027 class KateAutoIndent
00028 {
00029   //
00030   // static methodes to create and list them
00031   //
00032   public:
00033     static KateAutoIndent *createIndenter (KateDocument *doc, uint mode);
00034 
00035     static QStringList listModes ();
00036 
00037     static QString modeName (uint mode);
00038 
00039     static QString modeDescription (uint mode);
00040 
00041     static uint modeNumber (const QString &name);
00042 
00043   public:
00044     KateAutoIndent (KateDocument *doc);
00045     virtual ~KateAutoIndent ();
00046 
00047     // Update indenter's configuration (indention width etc.)
00048     void updateConfig ();
00049 
00050     // Called every time a newline character is inserted in the document.
00051     // cur should contain the new cursor position afterwords
00052     // needContinue is used to determine whether to calculate a continue indent or not
00053     virtual void processNewline (KateDocCursor &cur, bool needContinue);
00054 
00055     // Called every time a character is inserted into the document
00056     virtual void processChar (QChar /*c*/) { }
00057 
00058     virtual uint modeNumber () const { return KateDocumentConfig::imNormal; };
00059 
00060   protected:
00061     // Determines if the characters open and close are balanced between begin and end
00062     bool isBalanced (KateDocCursor &begin, const KateDocCursor &end, QChar open, QChar close) const;
00063 
00064     // Skip all whitespace starting at cur and ending at max   spanning lines if newline is set
00065     // cur is set to the current position afterwards
00066     bool skipBlanks (KateDocCursor &cur, KateDocCursor &max, bool newline) const;
00067 
00068     // Measures the indention of the current textline marked by cur
00069     uint measureIndent (KateDocCursor &cur) const;
00070 
00071     // Produces a string with the proper indentation characters for its length
00072     QString tabString (uint length) const;
00073 
00074 
00075     KateDocument *doc;
00076 
00077     uint tabWidth;
00078     uint indentWidth;
00079     uint commentAttrib;
00080     bool useSpaces;
00081 };
00082 
00083 class KateCSmartIndent : public KateAutoIndent
00084 {
00085   public:
00086     KateCSmartIndent (KateDocument *doc);
00087     ~KateCSmartIndent ();
00088 
00089     virtual void processNewline (KateDocCursor &begin, bool needContinue);
00090     virtual void processChar (QChar c);
00091 
00092     virtual uint modeNumber () const { return KateDocumentConfig::imCStyle; };
00093 
00094   private:
00095     uint calcIndent (KateDocCursor &begin, bool needContinue);
00096     uint calcContinue (KateDocCursor &begin, KateDocCursor &end);
00097 
00098     bool allowSemi;
00099 };
00100 
00101 class KatePythonIndent : public KateAutoIndent
00102 {
00103   public:
00104     KatePythonIndent (KateDocument *doc);
00105     ~KatePythonIndent ();
00106 
00107     virtual void processNewline (KateDocCursor &begin, bool needContinue);
00108 
00109     virtual uint modeNumber () const { return KateDocumentConfig::imPythonStyle; };
00110 
00111   private:
00112     int calcExtra (int &prevBlock, int &pos, KateDocCursor &end);
00113 
00114     static QRegExp endWithColon;
00115     static QRegExp stopStmt;
00116     static QRegExp blockBegin;
00117 };
00118 
00119 #endif
00120 
00121 // kate: space-indent on; indent-width 2; replace-tabs on; indent-mode cstyle;
KDE Logo
This file is part of the documentation for kate Library Version 3.2.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Thu Apr 22 14:26:24 2004 by doxygen 1.2.18 written by Dimitri van Heesch, © 1997-2003