kateautoindent.h
/* This file is part of the KDE libraries
Copyright (C) 2003 Jesse Yurkovich <yurkjes@iit.edu>
Copyright (C) 2004 >Anders Lund <anders@alweb.dk> (KateVarIndent class)
Copyright (C) 2005 Dominik Haumann <dhdev@gmx.de> (basic support for config page)
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License version 2 as published by the Free Software Foundation.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef __KATE_AUTO_INDENT_H__
#define __KATE_AUTO_INDENT_H__
#include <qobject.h>
#include "katecursor.h"
#include "kateconfig.h"
#include "katejscript.h"
class KateDocument;
class IndenterConfigPage : public QWidget
{
Q_OBJECT
public:
IndenterConfigPage ( QWidget *parent=0, const char *name=0 ) : QWidget(parent, name) {}
virtual ~IndenterConfigPage () {}
public slots:
virtual void apply () = 0;
};
class KateAutoIndent : public QObject
{
Q_OBJECT
public:
static KateAutoIndent *createIndenter (KateDocument *doc, uint mode);
static QStringList listModes ();
static QString modeName (uint mode);
static QString modeDescription (uint mode);
static uint modeNumber (const QString &name);
static bool hasConfigPage (uint mode);
static IndenterConfigPage* configPage(QWidget *parent, uint mode);
public:
KateAutoIndent (KateDocument *doc);
virtual ~KateAutoIndent ();
public slots:
virtual void updateConfig () {};
public:
virtual bool canProcessNewLine () const { return false; }
virtual void processNewline (KateDocCursor &cur, bool needContinue) { Q_UNUSED(cur); Q_UNUSED(needContinue); }
virtual void processChar (QChar c) { Q_UNUSED(c); }
virtual void processLine (KateDocCursor &/*line*/) { }
virtual void processSection (const KateDocCursor &/*begin*/, const KateDocCursor &/*end*/) { }
virtual bool canProcessLine() const { return false; }
virtual uint modeNumber () const { return KateDocumentConfig::imNone; };
protected:
KateDocument *doc;
};
class KateViewIndentationAction : public KActionMenu
{
Q_OBJECT
public:
KateViewIndentationAction(KateDocument *_doc, const QString& text, QObject* parent = 0, const char* name = 0);
~KateViewIndentationAction(){;};
private:
KateDocument* doc;
public slots:
void slotAboutToShow();
private slots:
void setMode (int mode);
};
class KateNormalIndent : public KateAutoIndent
{
Q_OBJECT
public:
KateNormalIndent (KateDocument *doc);
virtual ~KateNormalIndent ();
public slots:
virtual void updateConfig ();
public:
virtual bool canProcessNewLine () const { return true; }
virtual void processNewline (KateDocCursor &cur, bool needContinue);
virtual void processChar (QChar c) { Q_UNUSED(c); }
virtual void processLine (KateDocCursor &/*line*/) { }
virtual void processSection (const KateDocCursor &/*begin*/, const KateDocCursor &/*end*/) { }
virtual bool canProcessLine() const { return false; }
virtual uint modeNumber () const { return KateDocumentConfig::imNormal; };
protected:
bool isBalanced (KateDocCursor &begin, const KateDocCursor &end, QChar open, QChar close, uint &pos) const;
bool skipBlanks (KateDocCursor &cur, KateDocCursor &max, bool newline) const;
uint measureIndent (KateDocCursor &cur) const;
QString tabString(uint length) const;
uint tabWidth;
uint indentWidth;
public:
// Attributes that we should skip over or otherwise know about
uchar commentAttrib;
uchar doxyCommentAttrib;
uchar regionAttrib;
uchar symbolAttrib;
uchar alertAttrib;
uchar tagAttrib;
uchar wordAttrib;
uchar keywordAttrib;
uchar normalAttrib;
uchar extensionAttrib;
uchar preprocessorAttrib;
uchar stringAttrib;
uchar charAttrib;
protected:
bool useSpaces;
bool mixedIndent;
bool keepProfile;
};
class KateCSmartIndent : public KateNormalIndent
{
Q_OBJECT
public:
KateCSmartIndent (KateDocument *doc);
~KateCSmartIndent ();
virtual void processNewline (KateDocCursor &cur, bool needContinue);
virtual void processChar (QChar c);
virtual void processLine (KateDocCursor &line);
virtual void processSection (const KateDocCursor &begin, const KateDocCursor &end);
virtual bool canProcessLine() const { return true; }
virtual uint modeNumber () const { return KateDocumentConfig::imCStyle; };
private:
uint calcIndent (KateDocCursor &begin, bool needContinue);
uint calcContinue (KateDocCursor &begin, KateDocCursor &end);
uint findOpeningBrace (KateDocCursor &start);
uint findOpeningParen (KateDocCursor &start);
uint findOpeningComment (KateDocCursor &start);
bool firstOpeningBrace (KateDocCursor &start);
bool handleDoxygen (KateDocCursor &begin);
bool allowSemi;
bool processingBlock;
};
class KatePythonIndent : public KateNormalIndent
{
Q_OBJECT
public:
KatePythonIndent (KateDocument *doc);
~KatePythonIndent ();
virtual void processNewline (KateDocCursor &cur, bool needContinue);
virtual uint modeNumber () const { return KateDocumentConfig::imPythonStyle; };
private:
int calcExtra (int &prevBlock, int &pos, KateDocCursor &end);
void traverseString( const QChar &stringChar, KateDocCursor &cur, KateDocCursor &end );
static QRegExp endWithColon;
static QRegExp stopStmt;
static QRegExp blockBegin;
};
class KateXmlIndent : public KateNormalIndent
{
Q_OBJECT
public:
KateXmlIndent (KateDocument *doc);
~KateXmlIndent ();
virtual uint modeNumber () const { return KateDocumentConfig::imXmlStyle; }
virtual void processNewline (KateDocCursor &cur, bool needContinue);
virtual void processChar (QChar c);
virtual void processLine (KateDocCursor &line);
virtual bool canProcessLine() const { return true; }
virtual void processSection (const KateDocCursor &begin, const KateDocCursor &end);
private:
// sets the indentation of a single line based on previous line
// (returns indentation width)
uint processLine (uint line);
// gets information about a line
void getLineInfo (uint line, uint &prevIndent, int &numTags,
uint &attrCol, bool &unclosedTag);
// useful regular expressions
static const QRegExp startsWithCloseTag;
static const QRegExp unclosedDoctype;
};
class KateCSAndSIndent : public KateNormalIndent
{
Q_OBJECT
public:
KateCSAndSIndent (KateDocument *doc);
~KateCSAndSIndent ();
virtual void processNewline (KateDocCursor &begin, bool needContinue);
virtual void processChar (QChar c);
virtual void processLine (KateDocCursor &line);
virtual void processSection (const KateDocCursor &begin, const KateDocCursor &end);
virtual bool canProcessLine() const { return true; }
virtual uint modeNumber () const { return KateDocumentConfig::imCSAndS; };
private:
void updateIndentString();
bool inForStatement( int line );
int lastNonCommentChar( const KateDocCursor &line );
bool startsWithLabel( int line );
bool inStatement( const KateDocCursor &begin );
QString continuationIndent( const KateDocCursor &begin );
QString calcIndent (const KateDocCursor &begin);
QString calcIndentAfterKeyword(const KateDocCursor &indentCursor, const KateDocCursor &keywordCursor, int keywordPos, bool blockKeyword);
QString calcIndentInBracket(const KateDocCursor &indentCursor, const KateDocCursor &bracketCursor, int bracketPos);
QString calcIndentInBrace(const KateDocCursor &indentCursor, const KateDocCursor &braceCursor, int bracePos);
bool handleDoxygen (KateDocCursor &begin);
QString findOpeningCommentIndentation (const KateDocCursor &start);
QString indentString;
};
class KateVarIndent : public KateNormalIndent
{
Q_OBJECT
public:
enum pairs {
Parens=1,
Braces=2,
Brackets=4,
AngleBrackets=8
};
KateVarIndent( KateDocument *doc );
virtual ~KateVarIndent();
virtual void processNewline (KateDocCursor &cur, bool needContinue);
virtual void processChar (QChar c);
virtual void processLine (KateDocCursor &line);
virtual void processSection (const KateDocCursor &begin, const KateDocCursor &end);
virtual bool canProcessLine() const { return true; }
virtual uint modeNumber () const { return KateDocumentConfig::imVarIndent; };
private slots:
void slotVariableChanged(const QString&, const QString&);
private:
int coupleBalance( int line, const QChar &open, const QChar &close ) const;
bool hasRelevantOpening( const KateDocCursor &end ) const;
class KateVarIndentPrivate *d;
};
class KateScriptIndent : public KateNormalIndent
{
Q_OBJECT
public:
KateScriptIndent( KateDocument *doc );
~KateScriptIndent();
virtual void processNewline( KateDocCursor &cur, bool needContinue );
virtual void processChar( QChar c );
virtual void processLine (KateDocCursor &line);
// virtual void processSection (const KateDocCursor &begin, const KateDocCursor &end);
virtual bool canProcessLine() const { return true; }
virtual uint modeNumber () const { return KateDocumentConfig::imScriptIndent; };
private:
KateIndentScript m_script;
};
class ScriptIndentConfigPage : public IndenterConfigPage
{
Q_OBJECT
public:
ScriptIndentConfigPage ( QWidget *parent=0, const char *name=0 );
virtual ~ScriptIndentConfigPage ();
public slots:
virtual void apply ();
};
#endif
// kate: space-indent on; indent-width 2; replace-tabs on;
KateNormalIndent::skipBlanks
bool skipBlanks(KateDocCursor &cur, KateDocCursor &max, bool newline) const
Skip all whitespace starting at cur and ending at max.
Definition: kateautoindent.cpp:328
KateAutoIndent::modeName
static QString modeName(uint mode)
Return the mode name given the mode.
Definition: kateautoindent.cpp:74
KateNormalIndent
Provides Auto-Indent functionality for katepart.
Definition: kateautoindent.h:217
KateNormalIndent::updateConfig
virtual void updateConfig()
Update indenter's configuration (indention width, attributes etc.)
Definition: kateautoindent.cpp:197
KateDocCursor
Cursor class with a pointer to its document.
Definition: katecursor.h:92
KateNormalIndent::measureIndent
uint measureIndent(KateDocCursor &cur) const
Measures the indention of the current textline marked by cur.
Definition: kateautoindent.cpp:370
KateVarIndent::canProcessLine
virtual bool canProcessLine() const
Set to true if an actual implementation of 'processLine' is present.
Definition: kateautoindent.h:516
KateAutoIndent::processChar
virtual void processChar(QChar c)
Called every time a character is inserted into the document.
Definition: kateautoindent.h:163
KateVarIndent::processNewline
virtual void processNewline(KateDocCursor &cur, bool needContinue)
Called every time a newline character is inserted in the document.
Definition: kateautoindent.cpp:2186
KateAutoIndent::updateConfig
virtual void updateConfig()
Update indenter's configuration (indention width, attributes etc.)
Definition: kateautoindent.h:142
KateVarIndent::pairs
pairs
Purely for readability, couples we know and love.
Definition: kateautoindent.h:500
KateVarIndent
This indenter uses document variables to determine when to add/remove indents.
Definition: kateautoindent.h:492
KateNormalIndent::canProcessNewLine
virtual bool canProcessNewLine() const
does this indenter support processNewLine
Definition: kateautoindent.h:244
IndenterConfigPage
This widget will be embedded into a modal dialog when clicking the "Configure..." button in the inden...
Definition: kateautoindent.h:44
KateAutoIndent::hasConfigPage
static bool hasConfigPage(uint mode)
Config page support.
Definition: kateautoindent.cpp:134
KateVarIndent::processChar
virtual void processChar(QChar c)
Called every time a character is inserted into the document.
Definition: kateautoindent.cpp:2194
KateVarIndent::processLine
virtual void processLine(KateDocCursor &line)
Aligns/indents the given line to the proper indent position.
Definition: kateautoindent.cpp:2210
KateNormalIndent::modeNumber
virtual uint modeNumber() const
Mode index of this mode.
Definition: kateautoindent.h:280
KateNormalIndent::processSection
virtual void processSection(const KateDocCursor &, const KateDocCursor &)
Processes a section of text, indenting each line in between.
Definition: kateautoindent.h:268
KateVarIndent::processSection
virtual void processSection(const KateDocCursor &begin, const KateDocCursor &end)
Processes a section of text, indenting each line in between.
Definition: kateautoindent.cpp:2347
KateAutoIndent::configPage
static IndenterConfigPage * configPage(QWidget *parent, uint mode)
Support for a config page.
Definition: kateautoindent.cpp:142
KateAutoIndent::canProcessLine
virtual bool canProcessLine() const
Set to true if an actual implementation of 'processLine' is present.
Definition: kateautoindent.h:179
KateNormalIndent::tabWidth
uint tabWidth
The number of characters simulated for a tab.
Definition: kateautoindent.h:323
KateNormalIndent::useSpaces
bool useSpaces
Should we use spaces or tabs to indent.
Definition: kateautoindent.h:343
KateNormalIndent::processLine
virtual void processLine(KateDocCursor &)
Aligns/indents the given line to the proper indent position.
Definition: kateautoindent.h:263
KateAutoIndent::modeNumber
virtual uint modeNumber() const
Mode index of this mode.
Definition: kateautoindent.h:185
KateAutoIndent
Provides Auto-Indent functionality for katepart.
Definition: kateautoindent.h:70
KateNormalIndent::canProcessLine
virtual bool canProcessLine() const
Set to true if an actual implementation of 'processLine' is present.
Definition: kateautoindent.h:274
KateAutoIndent::processNewline
virtual void processNewline(KateDocCursor &cur, bool needContinue)
Called every time a newline character is inserted in the document.
Definition: kateautoindent.h:157
KateAutoIndent::canProcessNewLine
virtual bool canProcessNewLine() const
does this indenter support processNewLine
Definition: kateautoindent.h:149
KateAutoIndent::modeDescription
static QString modeDescription(uint mode)
Return the mode description.
Definition: kateautoindent.cpp:94
KateNormalIndent::~KateNormalIndent
virtual ~KateNormalIndent()
Virtual Destructor for the baseclass.
Definition: kateautoindent.cpp:193
IndenterConfigPage::apply
virtual void apply()=0
Apply the changes.
IndenterConfigPage::IndenterConfigPage
IndenterConfigPage(QWidget *parent=0, const char *name=0)
Standard constructor.
Definition: kateautoindent.h:54
KateAutoIndent::createIndenter
static KateAutoIndent * createIndenter(KateDocument *doc, uint mode)
Static methods to create and list indention modes.
Definition: kateautoindent.cpp:38
KateNormalIndent::processChar
virtual void processChar(QChar c)
Called every time a character is inserted into the document.
Definition: kateautoindent.h:258
KateNormalIndent::KateNormalIndent
KateNormalIndent(KateDocument *doc)
Constructor.
Definition: kateautoindent.cpp:186
KateViewIndentationAction
This action provides a list of available indenters and gets plugged into the KateView's KActionCollec...
Definition: kateautoindent.h:195
KateNormalIndent::tabString
QString tabString(uint length) const
Produces a string with the proper indentation characters for its length.
Definition: kateautoindent.cpp:378
KateAutoIndent::processLine
virtual void processLine(KateDocCursor &)
Aligns/indents the given line to the proper indent position.
Definition: kateautoindent.h:168
KateNormalIndent::keepProfile
bool keepProfile
Always try to honor the leading whitespace of lines already in the file.
Definition: kateautoindent.h:345
KAction::text
virtual QString text() const
KateNormalIndent::isBalanced
bool isBalanced(KateDocCursor &begin, const KateDocCursor &end, QChar open, QChar close, uint &pos) const
Determines if the characters open and close are balanced between begin and end Fills in pos with the ...
Definition: kateautoindent.cpp:282
KateNormalIndent::mixedIndent
bool mixedIndent
Optimize indent by mixing spaces and tabs, ala emacs.
Definition: kateautoindent.h:344
KateNormalIndent::processNewline
virtual void processNewline(KateDocCursor &cur, bool needContinue)
Called every time a newline character is inserted in the document.
Definition: kateautoindent.cpp:399
KateVarIndent::modeNumber
virtual uint modeNumber() const
Mode index of this mode.
Definition: kateautoindent.h:518
KateAutoIndent::KateAutoIndent
KateAutoIndent(KateDocument *doc)
Constructor.
Definition: kateautoindent.cpp:150
KateAutoIndent::~KateAutoIndent
virtual ~KateAutoIndent()
Virtual Destructor for the baseclass.
Definition: kateautoindent.cpp:154
KateAutoIndent::listModes
static QStringList listModes()
List all possible modes by name.
Definition: kateautoindent.cpp:58
KateNormalIndent::indentWidth
uint indentWidth
The number of characters used when tabs are replaced by spaces.
Definition: kateautoindent.h:324
KateAutoIndent::processSection
virtual void processSection(const KateDocCursor &, const KateDocCursor &)
Processes a section of text, indenting each line in between.
Definition: kateautoindent.h:173

KDE Home | KDE Accessibility Home | Description of Access Keys