• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • kate
 

kate

  • kate
  • part
kateautoindent.h
1/* This file is part of the KDE libraries
2 Copyright (C) 2003 Jesse Yurkovich <yurkjes@iit.edu>
3 Copyright (C) 2004 >Anders Lund <anders@alweb.dk> (KateVarIndent class)
4 Copyright (C) 2005 Dominik Haumann <dhdev@gmx.de> (basic support for config page)
5
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public
8 License version 2 as published by the Free Software Foundation.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/
20
21#ifndef __KATE_AUTO_INDENT_H__
22#define __KATE_AUTO_INDENT_H__
23
24#include <tqobject.h>
25
26#include "katecursor.h"
27#include "kateconfig.h"
28#include "katejscript.h"
29class KateDocument;
30
44class IndenterConfigPage : public TQWidget
45{
46 TQ_OBJECT
47
48 public:
54 IndenterConfigPage ( TQWidget *parent=0, const char *name=0 ) : TQWidget(parent, name) {}
55 virtual ~IndenterConfigPage () {}
56
57 public slots:
62 virtual void apply () = 0;
63};
64
70class KateAutoIndent : public TQObject
71{
72 TQ_OBJECT
73
77 public:
84 static KateAutoIndent *createIndenter (KateDocument *doc, uint mode);
85
90 static TQStringList listModes ();
91
97 static TQString modeName (uint mode);
98
104 static TQString modeDescription (uint mode);
105
111 static uint modeNumber (const TQString &name);
112
118 static bool hasConfigPage (uint mode);
119
124 static IndenterConfigPage* configPage(TQWidget *parent, uint mode);
125
126 public:
131 KateAutoIndent (KateDocument *doc);
132
136 virtual ~KateAutoIndent ();
137
138 public slots:
142 virtual void updateConfig () {};
143
144 public:
149 virtual bool canProcessNewLine () const { return false; }
150
157 virtual void processNewline (KateDocCursor &cur, bool needContinue) { Q_UNUSED(cur); Q_UNUSED(needContinue); }
158
163 virtual void processChar (TQChar c) { Q_UNUSED(c); }
164
168 virtual void processLine (KateDocCursor &/*line*/) { }
169
173 virtual void processSection (const KateDocCursor &/*begin*/, const KateDocCursor &/*end*/) { }
174
179 virtual bool canProcessLine() const { return false; }
180
185 virtual uint modeNumber () const { return KateDocumentConfig::imNone; };
186
187 protected:
188 KateDocument *doc;
189};
190
195class KateViewIndentationAction : public TDEActionMenu
196{
197 TQ_OBJECT
198
199 public:
200 KateViewIndentationAction(KateDocument *_doc, const TQString& text, TQObject* parent = 0, const char* name = 0);
201
202 ~KateViewIndentationAction(){;};
203
204 private:
205 KateDocument* doc;
206
207 public slots:
208 void slotAboutToShow();
209
210 private slots:
211 void setMode (int mode);
212};
213
217class KateNormalIndent : public KateAutoIndent
218{
219 TQ_OBJECT
220
221public:
226 KateNormalIndent (KateDocument *doc);
227
231 virtual ~KateNormalIndent ();
232
233public slots:
237 virtual void updateConfig ();
238
239public:
244 virtual bool canProcessNewLine () const { return true; }
245
252 virtual void processNewline (KateDocCursor &cur, bool needContinue);
253
258 virtual void processChar (TQChar c) { Q_UNUSED(c); }
259
263 virtual void processLine (KateDocCursor &/*line*/) { }
264
268 virtual void processSection (const KateDocCursor &/*begin*/, const KateDocCursor &/*end*/) { }
269
274 virtual bool canProcessLine() const { return false; }
275
280 virtual uint modeNumber () const { return KateDocumentConfig::imNormal; };
281
282protected:
283
295 bool isBalanced (KateDocCursor &begin, const KateDocCursor &end, TQChar open, TQChar close, uint &pos) const;
296
306 bool skipBlanks (KateDocCursor &cur, KateDocCursor &max, bool newline) const;
307
313 uint measureIndent (KateDocCursor &cur) const;
314
321 TQString tabString(uint length) const;
322
323 uint tabWidth;
324 uint indentWidth;
325
326public:
327 // Attributes that we should skip over or otherwise know about
328 uchar commentAttrib;
329 uchar doxyCommentAttrib;
330 uchar regionAttrib;
331 uchar symbolAttrib;
332 uchar alertAttrib;
333 uchar tagAttrib;
334 uchar wordAttrib;
335 uchar keywordAttrib;
336 uchar normalAttrib;
337 uchar extensionAttrib;
338 uchar preprocessorAttrib;
339 uchar stringAttrib;
340 uchar charAttrib;
341
342protected:
343 bool useSpaces;
344 bool mixedIndent;
345 bool keepProfile;
346};
347
348class KateCSmartIndent : public KateNormalIndent
349{
350 TQ_OBJECT
351
352 public:
353 KateCSmartIndent (KateDocument *doc);
354 ~KateCSmartIndent ();
355
356 virtual void processNewline (KateDocCursor &cur, bool needContinue);
357 virtual void processChar (TQChar c);
358
359 virtual void processLine (KateDocCursor &line);
360 virtual void processSection (const KateDocCursor &begin, const KateDocCursor &end);
361
362 virtual bool canProcessLine() const { return true; }
363
364 virtual uint modeNumber () const { return KateDocumentConfig::imCStyle; };
365
366 private:
367 uint calcIndent (KateDocCursor &begin, bool needContinue);
368 uint calcContinue (KateDocCursor &begin, KateDocCursor &end);
369 uint findOpeningBrace (KateDocCursor &start);
370 uint findOpeningParen (KateDocCursor &start);
371 uint findOpeningComment (KateDocCursor &start);
372 bool firstOpeningBrace (KateDocCursor &start);
373 bool handleDoxygen (KateDocCursor &begin);
374
375 bool allowSemi;
376 bool processingBlock;
377};
378
379class KatePythonIndent : public KateNormalIndent
380{
381 TQ_OBJECT
382
383 public:
384 KatePythonIndent (KateDocument *doc);
385 ~KatePythonIndent ();
386
387 virtual void processNewline (KateDocCursor &cur, bool needContinue);
388
389 virtual uint modeNumber () const { return KateDocumentConfig::imPythonStyle; };
390
391 private:
392 int calcExtra (int &prevBlock, int &pos, KateDocCursor &end);
393 void traverseString( const TQChar &stringChar, KateDocCursor &cur, KateDocCursor &end );
394
395 static TQRegExp endWithColon;
396 static TQRegExp stopStmt;
397 static TQRegExp blockBegin;
398};
399
400class KateXmlIndent : public KateNormalIndent
401{
402 TQ_OBJECT
403
404 public:
405 KateXmlIndent (KateDocument *doc);
406 ~KateXmlIndent ();
407
408 virtual uint modeNumber () const { return KateDocumentConfig::imXmlStyle; }
409 virtual void processNewline (KateDocCursor &cur, bool needContinue);
410 virtual void processChar (TQChar c);
411 virtual void processLine (KateDocCursor &line);
412 virtual bool canProcessLine() const { return true; }
413 virtual void processSection (const KateDocCursor &begin, const KateDocCursor &end);
414
415 private:
416 // sets the indentation of a single line based on previous line
417 // (returns indentation width)
418 uint processLine (uint line);
419
420 // gets information about a line
421 void getLineInfo (uint line, uint &prevIndent, int &numTags,
422 uint &attrCol, bool &unclosedTag);
423
424 // useful regular expressions
425 static const TQRegExp startsWithCloseTag;
426 static const TQRegExp unclosedDoctype;
427};
428
429class KateCSAndSIndent : public KateNormalIndent
430{
431 TQ_OBJECT
432
433 public:
434 KateCSAndSIndent (KateDocument *doc);
435 ~KateCSAndSIndent ();
436
437 virtual void processNewline (KateDocCursor &begin, bool needContinue);
438 virtual void processChar (TQChar c);
439
440 virtual void processLine (KateDocCursor &line);
441 virtual void processSection (const KateDocCursor &begin, const KateDocCursor &end);
442
443 virtual bool canProcessLine() const { return true; }
444
445 virtual uint modeNumber () const { return KateDocumentConfig::imCSAndS; };
446
447 private:
448 void updateIndentString();
449
450 bool inForStatement( int line );
451 int lastNonCommentChar( const KateDocCursor &line );
452 bool startsWithLabel( int line );
453 bool inStatement( const KateDocCursor &begin );
454 TQString continuationIndent( const KateDocCursor &begin );
455
456 TQString calcIndent (const KateDocCursor &begin);
457 TQString calcIndentAfterKeyword(const KateDocCursor &indentCursor, const KateDocCursor &keywordCursor, int keywordPos, bool blockKeyword);
458 TQString calcIndentInBracket(const KateDocCursor &indentCursor, const KateDocCursor &bracketCursor, int bracketPos);
459 TQString calcIndentInBrace(const KateDocCursor &indentCursor, const KateDocCursor &braceCursor, int bracePos);
460
461 bool handleDoxygen (KateDocCursor &begin);
462 TQString findOpeningCommentIndentation (const KateDocCursor &start);
463
464 TQString indentString;
465};
466
492class KateVarIndent : public KateNormalIndent
493{
494 TQ_OBJECT
495
496 public:
500 enum pairs {
501 Parens=1,
502 Braces=2,
503 Brackets=4,
504 AngleBrackets=8
505 };
506
507 KateVarIndent( KateDocument *doc );
508 virtual ~KateVarIndent();
509
510 virtual void processNewline (KateDocCursor &cur, bool needContinue);
511 virtual void processChar (TQChar c);
512
513 virtual void processLine (KateDocCursor &line);
514 virtual void processSection (const KateDocCursor &begin, const KateDocCursor &end);
515
516 virtual bool canProcessLine() const { return true; }
517
518 virtual uint modeNumber () const { return KateDocumentConfig::imVarIndent; };
519
520 private slots:
521 void slotVariableChanged(const TQString&, const TQString&);
522
523 private:
532 int coupleBalance( int line, const TQChar &open, const TQChar &close ) const;
533
538 bool hasRelevantOpening( const KateDocCursor &end ) const;
539
540 class KateVarIndentPrivate *d;
541};
542
543class KateScriptIndent : public KateNormalIndent
544{
545 TQ_OBJECT
546
547 public:
548 KateScriptIndent( KateDocument *doc );
549 ~KateScriptIndent();
550
551 virtual void processNewline( KateDocCursor &cur, bool needContinue );
552 virtual void processChar( TQChar c );
553
554 virtual void processLine (KateDocCursor &line);
555// virtual void processSection (const KateDocCursor &begin, const KateDocCursor &end);
556
557 virtual bool canProcessLine() const { return true; }
558
559 virtual uint modeNumber () const { return KateDocumentConfig::imScriptIndent; };
560 private:
561 KateIndentScript m_script;
562};
563
564class ScriptIndentConfigPage : public IndenterConfigPage
565{
566 TQ_OBJECT
567
568 public:
569 ScriptIndentConfigPage ( TQWidget *parent=0, const char *name=0 );
570 virtual ~ScriptIndentConfigPage ();
571
572 public slots:
576 virtual void apply ();
577};
578
579#endif
IndenterConfigPage
This widget will be embedded into a modal dialog when clicking the "Configure..." button in the inden...
Definition: kateautoindent.h:45
IndenterConfigPage::IndenterConfigPage
IndenterConfigPage(TQWidget *parent=0, const char *name=0)
Standard constructor.
Definition: kateautoindent.h:54
IndenterConfigPage::apply
virtual void apply()=0
Apply the changes.
KateAutoIndent
Provides Auto-Indent functionality for katepart.
Definition: kateautoindent.h:71
KateAutoIndent::hasConfigPage
static bool hasConfigPage(uint mode)
Config page support.
Definition: kateautoindent.cpp:134
KateAutoIndent::canProcessNewLine
virtual bool canProcessNewLine() const
does this indenter support processNewLine
Definition: kateautoindent.h:149
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::processSection
virtual void processSection(const KateDocCursor &, const KateDocCursor &)
Processes a section of text, indenting each line in between.
Definition: kateautoindent.h:173
KateAutoIndent::updateConfig
virtual void updateConfig()
Update indenter's configuration (indention width, attributes etc.)
Definition: kateautoindent.h:142
KateAutoIndent::processChar
virtual void processChar(TQChar c)
Called every time a character is inserted into the document.
Definition: kateautoindent.h:163
KateAutoIndent::modeName
static TQString modeName(uint mode)
Return the mode name given the mode.
Definition: kateautoindent.cpp:74
KateAutoIndent::listModes
static TQStringList listModes()
List all possible modes by name.
Definition: kateautoindent.cpp:58
KateAutoIndent::~KateAutoIndent
virtual ~KateAutoIndent()
Virtual Destructor for the baseclass.
Definition: kateautoindent.cpp:154
KateAutoIndent::configPage
static IndenterConfigPage * configPage(TQWidget *parent, uint mode)
Support for a config page.
Definition: kateautoindent.cpp:142
KateAutoIndent::modeDescription
static TQString modeDescription(uint mode)
Return the mode description.
Definition: kateautoindent.cpp:94
KateAutoIndent::KateAutoIndent
KateAutoIndent(KateDocument *doc)
Constructor.
Definition: kateautoindent.cpp:150
KateAutoIndent::processLine
virtual void processLine(KateDocCursor &)
Aligns/indents the given line to the proper indent position.
Definition: kateautoindent.h:168
KateAutoIndent::modeNumber
virtual uint modeNumber() const
Mode index of this mode.
Definition: kateautoindent.h:185
KateAutoIndent::canProcessLine
virtual bool canProcessLine() const
Set to true if an actual implementation of 'processLine' is present.
Definition: kateautoindent.h:179
KateAutoIndent::createIndenter
static KateAutoIndent * createIndenter(KateDocument *doc, uint mode)
Static methods to create and list indention modes.
Definition: kateautoindent.cpp:38
KateDocCursor
Cursor class with a pointer to its document.
Definition: katecursor.h:93
KateNormalIndent
Provides Auto-Indent functionality for katepart.
Definition: kateautoindent.h:218
KateNormalIndent::measureIndent
uint measureIndent(KateDocCursor &cur) const
Measures the indention of the current textline marked by cur.
Definition: kateautoindent.cpp:370
KateNormalIndent::processLine
virtual void processLine(KateDocCursor &)
Aligns/indents the given line to the proper indent position.
Definition: kateautoindent.h:263
KateNormalIndent::keepProfile
bool keepProfile
Always try to honor the leading whitespace of lines already in the file.
Definition: kateautoindent.h:345
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
KateNormalIndent::processSection
virtual void processSection(const KateDocCursor &, const KateDocCursor &)
Processes a section of text, indenting each line in between.
Definition: kateautoindent.h:268
KateNormalIndent::updateConfig
virtual void updateConfig()
Update indenter's configuration (indention width, attributes etc.)
Definition: kateautoindent.cpp:197
KateNormalIndent::canProcessLine
virtual bool canProcessLine() const
Set to true if an actual implementation of 'processLine' is present.
Definition: kateautoindent.h:274
KateNormalIndent::indentWidth
uint indentWidth
The number of characters used when tabs are replaced by spaces.
Definition: kateautoindent.h:324
KateNormalIndent::modeNumber
virtual uint modeNumber() const
Mode index of this mode.
Definition: kateautoindent.h:280
KateNormalIndent::isBalanced
bool isBalanced(KateDocCursor &begin, const KateDocCursor &end, TQChar open, TQChar 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::processNewline
virtual void processNewline(KateDocCursor &cur, bool needContinue)
Called every time a newline character is inserted in the document.
Definition: kateautoindent.cpp:399
KateNormalIndent::canProcessNewLine
virtual bool canProcessNewLine() const
does this indenter support processNewLine
Definition: kateautoindent.h:244
KateNormalIndent::useSpaces
bool useSpaces
Should we use spaces or tabs to indent.
Definition: kateautoindent.h:343
KateNormalIndent::mixedIndent
bool mixedIndent
Optimize indent by mixing spaces and tabs, ala emacs.
Definition: kateautoindent.h:344
KateNormalIndent::processChar
virtual void processChar(TQChar 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
KateNormalIndent::tabWidth
uint tabWidth
The number of characters simulated for a tab.
Definition: kateautoindent.h:323
KateNormalIndent::tabString
TQString tabString(uint length) const
Produces a string with the proper indentation characters for its length.
Definition: kateautoindent.cpp:378
KateNormalIndent::~KateNormalIndent
virtual ~KateNormalIndent()
Virtual Destructor for the baseclass.
Definition: kateautoindent.cpp:193
KateVarIndent
This indenter uses document variables to determine when to add/remove indents.
Definition: kateautoindent.h:493
KateVarIndent::canProcessLine
virtual bool canProcessLine() const
Set to true if an actual implementation of 'processLine' is present.
Definition: kateautoindent.h:516
KateVarIndent::processSection
virtual void processSection(const KateDocCursor &begin, const KateDocCursor &end)
Processes a section of text, indenting each line in between.
Definition: kateautoindent.cpp:2341
KateVarIndent::processChar
virtual void processChar(TQChar c)
Called every time a character is inserted into the document.
Definition: kateautoindent.cpp:2188
KateVarIndent::modeNumber
virtual uint modeNumber() const
Mode index of this mode.
Definition: kateautoindent.h:518
KateVarIndent::pairs
pairs
Purely for readability, couples we know and love.
Definition: kateautoindent.h:500
KateVarIndent::processLine
virtual void processLine(KateDocCursor &line)
Aligns/indents the given line to the proper indent position.
Definition: kateautoindent.cpp:2204
KateVarIndent::processNewline
virtual void processNewline(KateDocCursor &cur, bool needContinue)
Called every time a newline character is inserted in the document.
Definition: kateautoindent.cpp:2180
KateViewIndentationAction
This action provides a list of available indenters and gets plugged into the KateView's TDEActionColl...
Definition: kateautoindent.h:196
TDEActionMenu
TDEAction::text
virtual TQString text() const

kate

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

kate

Skip menu "kate"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for kate by doxygen 1.9.4
This website is maintained by Timothy Pearson.