00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
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 ) { }
00101
00105 virtual void processLine (
KateDocCursor &) { }
00106
00110 virtual void processSection (
KateDocCursor &,
KateDocCursor &) { }
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
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