• Skip to content
  • Skip to link menu
KDE 3.5 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

Kate

kateautoindent.h

Go to the documentation of this file.
00001 /* This file is part of the KDE libraries
00002    Copyright (C) 2003 Jesse Yurkovich <yurkjes@iit.edu>
00003    Copyright (C) 2004 >Anders Lund <anders@alweb.dk> (KateVarIndent class)
00004    Copyright (C) 2005 Dominik Haumann <dhdev@gmx.de> (basic support for config page)
00005 
00006    This library is free software; you can redistribute it and/or
00007    modify it under the terms of the GNU Library General Public
00008    License version 2 as published by the Free Software Foundation.
00009 
00010    This library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Library General Public License for more details.
00014 
00015    You should have received a copy of the GNU Library General Public License
00016    along with this library; see the file COPYING.LIB.  If not, write to
00017    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018    Boston, MA 02110-1301, USA.
00019 */
00020 
00021 #ifndef __KATE_AUTO_INDENT_H__
00022 #define __KATE_AUTO_INDENT_H__
00023 
00024 #include <qobject.h>
00025 
00026 #include "katecursor.h"
00027 #include "kateconfig.h"
00028 #include "katejscript.h"
00029 class KateDocument;
00030 
00044 class IndenterConfigPage : public QWidget
00045 {
00046   Q_OBJECT
00047 
00048   public:
00054     IndenterConfigPage ( QWidget *parent=0, const char *name=0 ) : QWidget(parent, name) {}
00055     virtual ~IndenterConfigPage () {}
00056 
00057   public slots:
00062     virtual void apply () = 0;
00063 };
00064 
00070 class KateAutoIndent : public QObject
00071 {
00072   Q_OBJECT
00073 
00077   public:
00084     static KateAutoIndent *createIndenter (KateDocument *doc, uint mode);
00085 
00090     static QStringList listModes ();
00091 
00097     static QString modeName (uint mode);
00098 
00104     static QString modeDescription (uint mode);
00105 
00111     static uint modeNumber (const QString &name);
00112 
00118     static bool hasConfigPage (uint mode);
00119 
00124     static IndenterConfigPage* configPage(QWidget *parent, uint mode);
00125 
00126   public:
00131     KateAutoIndent (KateDocument *doc);
00132 
00136     virtual ~KateAutoIndent ();
00137 
00138   public slots:
00142     virtual void updateConfig () {};
00143 
00144   public:
00149     virtual bool canProcessNewLine () const { return false; }
00150 
00157     virtual void processNewline (KateDocCursor &cur, bool needContinue) { Q_UNUSED(cur); Q_UNUSED(needContinue); }
00158 
00163     virtual void processChar (QChar c) { Q_UNUSED(c); }
00164 
00168     virtual void processLine (KateDocCursor &/*line*/) { }
00169 
00173     virtual void processSection (const KateDocCursor &/*begin*/, const KateDocCursor &/*end*/) { }
00174 
00179     virtual bool canProcessLine() const { return false; }
00180 
00185     virtual uint modeNumber () const { return KateDocumentConfig::imNone; };
00186 
00187   protected:
00188     KateDocument *doc;
00189 };
00190 
00195 class KateViewIndentationAction : public KActionMenu
00196 {
00197   Q_OBJECT
00198 
00199   public:
00200     KateViewIndentationAction(KateDocument *_doc, const QString& text, QObject* parent = 0, const char* name = 0);
00201 
00202     ~KateViewIndentationAction(){;};
00203 
00204   private:
00205     KateDocument* doc;
00206 
00207   public  slots:
00208     void slotAboutToShow();
00209 
00210   private slots:
00211     void setMode (int mode);
00212 };
00213 
00217 class KateNormalIndent : public KateAutoIndent
00218 {
00219   Q_OBJECT
00220 
00221 public:
00226   KateNormalIndent (KateDocument *doc);
00227 
00231   virtual ~KateNormalIndent ();
00232 
00233 public slots:
00237   virtual void updateConfig ();
00238 
00239 public:
00244   virtual bool canProcessNewLine () const { return true; }
00245 
00252   virtual void processNewline (KateDocCursor &cur, bool needContinue);
00253 
00258   virtual void processChar (QChar c) { Q_UNUSED(c); }
00259 
00263   virtual void processLine (KateDocCursor &/*line*/) { }
00264 
00268   virtual void processSection (const KateDocCursor &/*begin*/, const KateDocCursor &/*end*/) { }
00269 
00274   virtual bool canProcessLine() const { return false; }
00275 
00280   virtual uint modeNumber () const { return KateDocumentConfig::imNormal; };
00281 
00282 protected:
00283 
00295   bool isBalanced (KateDocCursor &begin, const KateDocCursor &end, QChar open, QChar close, uint &pos) const;
00296 
00306   bool skipBlanks (KateDocCursor &cur, KateDocCursor &max, bool newline) const;
00307 
00313   uint measureIndent (KateDocCursor &cur) const;
00314 
00321   QString tabString(uint length) const;
00322 
00323   uint  tabWidth;     
00324   uint  indentWidth;  
00325 
00326 public:
00327     // Attributes that we should skip over or otherwise know about
00328   uchar commentAttrib;
00329   uchar doxyCommentAttrib;
00330   uchar regionAttrib;
00331   uchar symbolAttrib;
00332   uchar alertAttrib;
00333   uchar tagAttrib;
00334   uchar wordAttrib;
00335   uchar keywordAttrib;
00336   uchar normalAttrib;
00337   uchar extensionAttrib;
00338   uchar preprocessorAttrib;
00339   uchar stringAttrib;
00340   uchar charAttrib;
00341 
00342 protected:
00343   bool  useSpaces;    
00344   bool  mixedIndent;  
00345   bool  keepProfile;  
00346 };
00347 
00348 class KateCSmartIndent : public KateNormalIndent
00349 {
00350   Q_OBJECT
00351 
00352   public:
00353     KateCSmartIndent (KateDocument *doc);
00354     ~KateCSmartIndent ();
00355 
00356     virtual void processNewline (KateDocCursor &cur, bool needContinue);
00357     virtual void processChar (QChar c);
00358 
00359     virtual void processLine (KateDocCursor &line);
00360     virtual void processSection (const KateDocCursor &begin, const KateDocCursor &end);
00361 
00362     virtual bool canProcessLine() const { return true; }
00363 
00364     virtual uint modeNumber () const { return KateDocumentConfig::imCStyle; };
00365 
00366   private:
00367     uint calcIndent (KateDocCursor &begin, bool needContinue);
00368     uint calcContinue (KateDocCursor &begin, KateDocCursor &end);
00369     uint findOpeningBrace (KateDocCursor &start);
00370     uint findOpeningParen (KateDocCursor &start);
00371     uint findOpeningComment (KateDocCursor &start);
00372     bool firstOpeningBrace (KateDocCursor &start);
00373     bool handleDoxygen (KateDocCursor &begin);
00374 
00375     bool allowSemi;
00376     bool processingBlock;
00377 };
00378 
00379 class KatePythonIndent : public KateNormalIndent
00380 {
00381   Q_OBJECT
00382 
00383   public:
00384     KatePythonIndent (KateDocument *doc);
00385     ~KatePythonIndent ();
00386 
00387     virtual void processNewline (KateDocCursor &cur, bool needContinue);
00388 
00389     virtual uint modeNumber () const { return KateDocumentConfig::imPythonStyle; };
00390 
00391   private:
00392     int calcExtra (int &prevBlock, int &pos, KateDocCursor &end);
00393     void traverseString( const QChar &stringChar, KateDocCursor &cur, KateDocCursor &end );
00394 
00395     static QRegExp endWithColon;
00396     static QRegExp stopStmt;
00397     static QRegExp blockBegin;
00398 };
00399 
00400 class KateXmlIndent : public KateNormalIndent
00401 {
00402   Q_OBJECT
00403 
00404   public:
00405     KateXmlIndent (KateDocument *doc);
00406     ~KateXmlIndent ();
00407 
00408     virtual uint modeNumber () const { return KateDocumentConfig::imXmlStyle; }
00409     virtual void processNewline (KateDocCursor &cur, bool needContinue);
00410     virtual void processChar (QChar c);
00411     virtual void processLine (KateDocCursor &line);
00412     virtual bool canProcessLine() const { return true; }
00413     virtual void processSection (const KateDocCursor &begin, const KateDocCursor &end);
00414 
00415   private:
00416     // sets the indentation of a single line based on previous line
00417     //  (returns indentation width)
00418     uint processLine (uint line);
00419 
00420     // gets information about a line
00421     void getLineInfo (uint line, uint &prevIndent, int &numTags,
00422       uint &attrCol, bool &unclosedTag);
00423 
00424     // useful regular expressions
00425     static const QRegExp startsWithCloseTag;
00426     static const QRegExp unclosedDoctype;
00427 };
00428 
00429 class KateCSAndSIndent : public KateNormalIndent
00430 {
00431   Q_OBJECT
00432 
00433   public:
00434     KateCSAndSIndent (KateDocument *doc);
00435     ~KateCSAndSIndent ();
00436 
00437     virtual void processNewline (KateDocCursor &begin, bool needContinue);
00438     virtual void processChar (QChar c);
00439 
00440     virtual void processLine (KateDocCursor &line);
00441     virtual void processSection (const KateDocCursor &begin, const KateDocCursor &end);
00442 
00443     virtual bool canProcessLine() const { return true; }
00444 
00445     virtual uint modeNumber () const { return KateDocumentConfig::imCSAndS; };
00446 
00447   private:
00448     void updateIndentString();
00449 
00450     bool inForStatement( int line );
00451     int lastNonCommentChar( const KateDocCursor &line );
00452     bool startsWithLabel( int line );
00453     bool inStatement( const KateDocCursor &begin );
00454     QString continuationIndent( const KateDocCursor &begin );
00455 
00456     QString calcIndent (const KateDocCursor &begin);
00457     QString calcIndentAfterKeyword(const KateDocCursor &indentCursor, const KateDocCursor &keywordCursor, int keywordPos, bool blockKeyword);
00458     QString calcIndentInBracket(const KateDocCursor &indentCursor, const KateDocCursor &bracketCursor, int bracketPos);
00459     QString calcIndentInBrace(const KateDocCursor &indentCursor, const KateDocCursor &braceCursor, int bracePos);
00460 
00461     bool handleDoxygen (KateDocCursor &begin);
00462     QString findOpeningCommentIndentation (const KateDocCursor &start);
00463 
00464     QString indentString;
00465 };
00466 
00492 class KateVarIndent : public KateNormalIndent
00493 {
00494   Q_OBJECT
00495 
00496   public:
00500     enum pairs {
00501       Parens=1,
00502       Braces=2,
00503       Brackets=4,
00504       AngleBrackets=8
00505     };
00506 
00507     KateVarIndent( KateDocument *doc );
00508     virtual ~KateVarIndent();
00509 
00510     virtual void processNewline (KateDocCursor &cur, bool needContinue);
00511     virtual void processChar (QChar c);
00512 
00513     virtual void processLine (KateDocCursor &line);
00514     virtual void processSection (const KateDocCursor &begin, const KateDocCursor &end);
00515 
00516     virtual bool canProcessLine() const { return true; }
00517 
00518     virtual uint modeNumber () const { return KateDocumentConfig::imVarIndent; };
00519 
00520   private slots:
00521     void slotVariableChanged(const QString&, const QString&);
00522 
00523   private:
00532     int coupleBalance( int line, const QChar &open, const QChar &close ) const;
00533 
00538     bool hasRelevantOpening( const KateDocCursor &end ) const;
00539 
00540     class KateVarIndentPrivate *d;
00541 };
00542 
00543 class KateScriptIndent : public KateNormalIndent
00544 {
00545   Q_OBJECT
00546 
00547   public:
00548     KateScriptIndent( KateDocument *doc );
00549     ~KateScriptIndent();
00550 
00551     virtual void processNewline( KateDocCursor &cur, bool needContinue );
00552     virtual void processChar( QChar c );
00553 
00554     virtual void processLine (KateDocCursor &line);
00555 //     virtual void processSection (const KateDocCursor &begin, const KateDocCursor &end);
00556 
00557     virtual bool canProcessLine() const { return true; }
00558 
00559     virtual uint modeNumber () const { return KateDocumentConfig::imScriptIndent; };
00560   private:
00561     KateIndentScript m_script;
00562 };
00563 
00564 class ScriptIndentConfigPage : public IndenterConfigPage
00565 {
00566     Q_OBJECT
00567 
00568   public:
00569     ScriptIndentConfigPage ( QWidget *parent=0, const char *name=0 );
00570     virtual ~ScriptIndentConfigPage ();
00571 
00572   public slots:
00576     virtual void apply ();
00577 };
00578 
00579 #endif
00580 
00581 // kate: space-indent on; indent-width 2; replace-tabs on;

Kate

Skip menu "Kate"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

API Reference

Skip menu "API Reference"
  • dcop
  • DNSSD
  • interfaces
  • Kate
  • kconf_update
  • KDECore
  • KDED
  • kdefx
  • KDEsu
  • kdeui
  • KDocTools
  • KHTML
  • KImgIO
  • KInit
  • kio
  • kioslave
  • KJS
  • KNewStuff
  • KParts
  • KUtils
Generated for API Reference by doxygen 1.5.9
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal