21 #include "kateautoindent.h"
22 #include "kateautoindent.moc"
24 #include "kateconfig.h"
25 #include "katehighlight.h"
26 #include "katefactory.h"
27 #include "katejscript.h"
32 #include <kpopupmenu.h>
40 if (mode == KateDocumentConfig::imNormal)
42 else if (mode == KateDocumentConfig::imCStyle)
43 return new KateCSmartIndent (doc);
44 else if (mode == KateDocumentConfig::imPythonStyle)
45 return new KatePythonIndent (doc);
46 else if (mode == KateDocumentConfig::imXmlStyle)
47 return new KateXmlIndent (doc);
48 else if (mode == KateDocumentConfig::imCSAndS)
49 return new KateCSAndSIndent (doc);
50 else if ( mode == KateDocumentConfig::imVarIndent )
76 if (mode == KateDocumentConfig::imNormal)
77 return TQString (
"normal");
78 else if (mode == KateDocumentConfig::imCStyle)
79 return TQString (
"cstyle");
80 else if (mode == KateDocumentConfig::imPythonStyle)
81 return TQString (
"python");
82 else if (mode == KateDocumentConfig::imXmlStyle)
83 return TQString (
"xml");
84 else if (mode == KateDocumentConfig::imCSAndS)
85 return TQString (
"csands");
86 else if ( mode == KateDocumentConfig::imVarIndent )
87 return TQString(
"varindent" );
91 return TQString (
"none");
96 if (mode == KateDocumentConfig::imNormal)
97 return i18n (
"Normal");
98 else if (mode == KateDocumentConfig::imCStyle)
99 return i18n (
"C Style");
100 else if (mode == KateDocumentConfig::imPythonStyle)
101 return i18n (
"Python Style");
102 else if (mode == KateDocumentConfig::imXmlStyle)
103 return i18n (
"XML Style");
104 else if (mode == KateDocumentConfig::imCSAndS)
105 return i18n (
"S&S C Style");
106 else if ( mode == KateDocumentConfig::imVarIndent )
107 return i18n(
"Variable Based Indenter");
111 return i18n (
"None");
116 if (
modeName(KateDocumentConfig::imNormal) == name)
117 return KateDocumentConfig::imNormal;
118 else if (
modeName(KateDocumentConfig::imCStyle) == name)
119 return KateDocumentConfig::imCStyle;
120 else if (
modeName(KateDocumentConfig::imPythonStyle) == name)
121 return KateDocumentConfig::imPythonStyle;
122 else if (
modeName(KateDocumentConfig::imXmlStyle) == name)
123 return KateDocumentConfig::imXmlStyle;
124 else if (
modeName(KateDocumentConfig::imCSAndS) == name)
125 return KateDocumentConfig::imCSAndS;
126 else if (
modeName( KateDocumentConfig::imVarIndent ) == name )
127 return KateDocumentConfig::imVarIndent;
131 return KateDocumentConfig::imNone;
151 : TQObject(), doc(_doc)
161 KateViewIndentationAction::KateViewIndentationAction(KateDocument *_doc,
const TQString& text, TQObject* parent,
const char* name)
164 connect(popupMenu(),TQT_SIGNAL(aboutToShow()),
this,TQT_SLOT(slotAboutToShow()));
167 void KateViewIndentationAction::slotAboutToShow()
171 popupMenu()->clear ();
172 for (uint z=0; z<modes.size(); ++z)
175 popupMenu()->setItemChecked (doc->config()->indentationMode(),
true);
178 void KateViewIndentationAction::setMode (
int mode)
180 doc->config()->setIndentationMode((uint)mode);
190 connect(_doc, TQT_SIGNAL(hlChanged()),
this, TQT_SLOT(
updateConfig()));
199 KateDocumentConfig *config = doc->config();
201 useSpaces = config->configFlags() & KateDocument::cfSpaceIndent || config->configFlags() & KateDocumentConfig::cfReplaceTabsDyn;
203 keepProfile = config->configFlags() & KateDocument::cfKeepIndentProfile;
208 doxyCommentAttrib = 255;
216 extensionAttrib = 255;
217 preprocessorAttrib = 255;
221 KateHlItemDataList items;
222 doc->highlight()->getKateHlItemDataListCopy (0, items);
224 for (uint i=0; i<items.count(); i++)
226 TQString name = items.at(i)->name;
227 if (name.find(
"Comment") != -1 && commentAttrib == 255)
231 else if (name.find(
"Region Marker") != -1 && regionAttrib == 255)
235 else if (name.find(
"Symbol") != -1 && symbolAttrib == 255)
239 else if (name.find(
"Alert") != -1)
243 else if (name.find(
"Comment") != -1 && commentAttrib != 255 && doxyCommentAttrib == 255)
245 doxyCommentAttrib = i;
247 else if (name.find(
"Tags") != -1 && tagAttrib == 255)
251 else if (name.find(
"Word") != -1 && wordAttrib == 255)
255 else if (name.find(
"Keyword") != -1 && keywordAttrib == 255)
259 else if (name.find(
"Normal") != -1 && normalAttrib == 255)
263 else if (name.find(
"Extensions") != -1 && extensionAttrib == 255)
267 else if (name.find(
"Preprocessor") != -1 && preprocessorAttrib == 255)
269 preprocessorAttrib = i;
271 else if (name.find(
"String") != -1 && stringAttrib == 255)
275 else if (name.find(
"Char") != -1 && charAttrib == 255)
285 bool atLeastOne =
false;
286 bool getNext =
false;
288 pos = doc->plainKateTextLine(begin.line())->firstChar();
294 TQChar c = begin.currentChar();
295 if (begin.currentAttrib() == symbolAttrib)
312 else if (getNext && !c.isSpace())
318 if (atLeastOne && parenOpen <= 0)
321 if (!begin.moveForward(1))
325 return (atLeastOne) ? false :
true;
330 int curLine = cur.line();
339 uchar attrib = cur.currentAttrib();
340 const TQString hlFile = doc->highlight()->hlKeyForAttrib( attrib );
342 if (attrib != commentAttrib && attrib != regionAttrib && attrib != alertAttrib && attrib != preprocessorAttrib && !hlFile.endsWith(
"doxygen.xml"))
344 TQChar c = cur.currentChar();
345 if (!c.isNull() && !c.isSpace())
349 if (!cur.moveForward(1))
356 if (curLine != cur.line())
360 curLine = cur.line();
375 return doc->plainKateTextLine(cur.line())->cursorX(cur.col(),
tabWidth);
381 pos = kMin (pos, 80U);
401 int line = begin.line() - 1;
402 int pos = begin.col();
404 while ((line > 0) && (pos < 0))
405 pos = doc->plainKateTextLine(--line)->firstChar();
409 TQString filler = doc->text(line, 0, line, pos);
410 doc->insertText(begin.line(), 0, filler);
411 begin.setCol(filler.length());
421 KateCSmartIndent::KateCSmartIndent (KateDocument *doc)
424 processingBlock (false)
426 kdDebug(13030)<<
"CREATING KATECSMART INTDETER"<<
endl;
429 KateCSmartIndent::~KateCSmartIndent ()
436 kdDebug(13030)<<
"PROCESSING LINE "<<line.line()<<
endl;
439 int firstChar = textLine->firstChar();
441 if (firstChar == -1 && processingBlock)
447 TQChar first = textLine->getChar(firstChar);
448 TQChar last = textLine->getChar(textLine->lastChar());
452 indent = findOpeningBrace(line);
454 else if (first ==
')')
456 indent = findOpeningParen(line);
458 else if (first ==
'{')
462 if (!firstOpeningBrace(temp))
463 indent = calcIndent(temp,
false);
465 else if (first ==
':')
468 int pos = findOpeningBrace(line);
470 indent = indentWidth;
472 indent = pos + (indentWidth * 2);
474 else if (last ==
':')
476 if (textLine->stringAtPos (firstChar,
"case") ||
477 textLine->stringAtPos (firstChar,
"default") ||
478 textLine->stringAtPos (firstChar,
"public") ||
479 textLine->stringAtPos (firstChar,
"private") ||
480 textLine->stringAtPos (firstChar,
"protected") ||
481 textLine->stringAtPos (firstChar,
"signals") ||
482 textLine->stringAtPos (firstChar,
"Q_SIGNALS") ||
483 textLine->stringAtPos (firstChar,
"Q_SLOTS") ||
484 textLine->stringAtPos (firstChar,
"slots"))
486 indent = findOpeningBrace(line) + indentWidth;
489 else if (first ==
'*')
493 int lineEnd = textLine->lastChar();
494 if (lineEnd > 0 && textLine->getChar(lineEnd - 1) ==
'*')
496 indent = findOpeningComment(line);
497 if (textLine->attribute(firstChar) == doxyCommentAttrib)
506 if (textLine->attribute(firstChar) == doxyCommentAttrib)
507 indent = calcIndent(temp,
false) + 1;
509 indent = calcIndent(temp,
true);
512 else if (first ==
'#')
515 if (textLine->stringAtPos (firstChar,
"#region") ||
516 textLine->stringAtPos (firstChar,
"#endregion"))
519 indent = calcIndent(temp,
true);
525 if (first ==
'/' && last !=
'/')
529 indent = calcIndent(temp,
true);
538 if (indent != measureIndent(line) || first ==
'}' || first ==
'{' || first ==
'#')
540 doc->removeText(line.line(), 0, line.line(), firstChar);
541 TQString filler = tabString(indent);
542 if (indent > 0) doc->insertText(line.line(), 0, filler);
543 if (!processingBlock) line.setCol(filler.length());
554 processingBlock = (
end.line() - cur.line() > 0) ?
true :
false;
556 while (cur.line() <=
end.line())
559 if (!cur.gotoNextLine())
563 processingBlock =
false;
564 kdDebug(13030) <<
"+++ total: " << t.elapsed() <<
endl;
570 int line = begin.line();
572 while ((line > 0) && (first < 0))
573 first = doc->plainKateTextLine(--line)->firstChar();
578 bool insideDoxygen =
false;
579 bool justAfterDoxygen =
false;
580 if (textLine->attribute(first) == doxyCommentAttrib || textLine->attribute(textLine->lastChar()) == doxyCommentAttrib)
582 const int last = textLine->lastChar();
583 if (last <= 0 || !(justAfterDoxygen = textLine->stringAtPos(last-1,
"*/")))
584 insideDoxygen =
true;
585 if (justAfterDoxygen)
586 justAfterDoxygen &= textLine->string().find(
"/**") < 0;
587 while (textLine->attribute(first) != doxyCommentAttrib && first <= textLine->lastChar())
589 if (textLine->stringAtPos(first,
"//"))
596 textLine = doc->plainKateTextLine(begin.line());
597 first = textLine->firstChar();
598 int indent = findOpeningComment(begin);
599 TQString filler = tabString (indent);
601 bool doxygenAutoInsert = doc->config()->configFlags() & KateDocumentConfig::cfDoxygenAutoTyping;
603 if ( doxygenAutoInsert &&
604 ((first < 0) || (!textLine->stringAtPos(first,
"*/") && !textLine->stringAtPos(first,
"*"))))
606 filler = filler +
" * ";
609 doc->removeText (begin.line(), 0, begin.line(), first);
610 doc->insertText (begin.line(), 0, filler);
611 begin.setCol(filler.length());
617 else if (justAfterDoxygen)
619 textLine = doc->plainKateTextLine(begin.line());
620 first = textLine->firstChar();
621 int indent = findOpeningComment(begin);
622 TQString filler = tabString (indent);
624 doc->removeText (begin.line(), 0, begin.line(), first);
625 doc->insertText (begin.line(), 0, filler);
626 begin.setCol(filler.length());
635 void KateCSmartIndent::processNewline (
KateDocCursor &begin,
bool needContinue)
637 if (!handleDoxygen (begin))
640 bool inMiddle = textLine->firstChar() > -1;
642 int indent = calcIndent (begin, needContinue);
644 if (indent > 0 || inMiddle)
646 TQString filler = tabString (indent);
647 doc->insertText (begin.line(), 0, filler);
648 begin.setCol(filler.length());
654 begin.setCol(textLine->firstChar());
677 uchar attr1, uchar attr2,
678 TQChar prev1, TQChar prev2)
680 return attr1 == indenter.preprocessorAttrib
683 || attr1 == indenter.commentAttrib
684 || attr1 == indenter.doxyCommentAttrib
685 || attr1 == indenter.stringAttrib && (attr2 != indenter.stringAttrib
686 || (prev1 !=
'"' || prev2 ==
'\\' && attr2 == indenter.charAttrib))
687 || prev1 ==
'\'' && attr1 != indenter.charAttrib;
701 const TQString txt = line->string(0,curCol);
703 for (
int pos = 0; (pos = txt.find(
':', pos)) >= 0; pos++) {
704 if (line->attribute(pos) == indenter.symbolAttrib)
712 return !isColonImmune(indenter, line->attribute(curCol - 1),
713 line->attribute(curCol - 2),
714 txt[curCol - 1], txt[curCol - 2]);
717 void KateCSmartIndent::processChar(TQChar c)
722 static const TQString triggers(
"}{)/:#n");
723 static const TQString firstTriggers(
"}{)/:#");
724 static const TQString lastTriggers(
":n");
725 if (triggers.find(c) < 0)
728 KateView *view = doc->activeView();
729 int curCol = view->cursorColumnReal() - 1;
733 const TQChar curChar = textLine->getChar(curCol);
734 const int first = textLine->firstChar();
735 const TQChar firstChar = textLine->getChar(first);
740 kdDebug() <<
"curChar " << curChar <<
" curCol " << curCol <<
" textlen " << textLine->length() <<
" a " << textLine->attribute( curCol ) <<
" sym " << symbolAttrib <<
" pp " << preprocessorAttrib <<
endl;
741 if (!(((curChar ==
'#' || curChar ==
'n')
742 && textLine->attribute( curCol ) == preprocessorAttrib)
743 || textLine->attribute( curCol ) == symbolAttrib)
751 if (firstChar !=
'#' || textLine->string(curCol-5, 5) != TQString::fromLatin1(
"regio"))
758 if ( textLine->attribute( begin.col() ) == doxyCommentAttrib )
764 && textLine->nextNonSpaceChar( first+1 ) == view->cursorColumnReal()-1 )
765 doc->removeText( view->cursorLine(), first+1, view->cursorLine(), view->cursorColumnReal()-1);
776 const TQChar lastChar = textLine->getChar(textLine->lastChar());
778 if (((c == firstChar && firstTriggers.find(firstChar) >= 0)
779 || (c == lastChar && lastTriggers.find(lastChar) >= 0))
780 && (c !=
':' || colonPermitsReindent(*
this, textLine, curCol)))
785 uint KateCSmartIndent::calcIndent(
KateDocCursor &begin,
bool needContinue)
790 uint anchorIndent = 0;
794 bool isSpecial =
false;
795 bool potentialAnchorSeen =
false;
797 bool parenthesizedArg =
false;
802 while (cur.gotoPreviousLine())
804 isSpecial = found =
false;
805 textLine = doc->plainKateTextLine(cur.line());
808 int pos = textLine->lastChar();
810 int otherAnchor = -1;
813 if (textLine->attribute(pos) == symbolAttrib)
815 TQChar tc = textLine->getChar (pos);
816 if ((tc ==
';' || tc ==
':' || tc ==
',') && otherAnchor == -1 && parenCount <= 0) {
817 otherAnchor = pos, potentialAnchorSeen =
true;
819 }
else if (tc ==
')')
822 parenCount--, parenthesizedArg = isArg, potentialAnchorSeen =
true;
827 openCount++, potentialAnchorSeen =
true;
832 }
while (--pos >= textLine->firstChar());
834 if (openCount != 0 || otherAnchor != -1)
840 else if (openCount < 0)
842 else if (otherAnchor >= 0)
843 c = textLine->getChar (otherAnchor);
845 int specialIndent = 0;
846 if (c ==
':' && needContinue)
849 specialIndent = textLine->firstChar();
850 if (textLine->stringAtPos(specialIndent,
"case"))
851 ch = textLine->getChar(specialIndent + 4);
852 else if (textLine->stringAtPos(specialIndent,
"default"))
853 ch = textLine->getChar(specialIndent + 7);
854 else if (textLine->stringAtPos(specialIndent,
"public"))
855 ch = textLine->getChar(specialIndent + 6);
856 else if (textLine->stringAtPos(specialIndent,
"private"))
857 ch = textLine->getChar(specialIndent + 7);
858 else if (textLine->stringAtPos(specialIndent,
"protected"))
859 ch = textLine->getChar(specialIndent + 9);
860 else if (textLine->stringAtPos(specialIndent,
"signals"))
861 ch = textLine->getChar(specialIndent + 7);
862 else if (textLine->stringAtPos(specialIndent,
"Q_SIGNALS"))
863 ch = textLine->getChar(specialIndent + 9);
864 else if (textLine->stringAtPos(specialIndent,
"slots"))
865 ch = textLine->getChar(specialIndent + 5);
866 else if (textLine->stringAtPos(specialIndent,
"Q_SLOTS"))
867 ch = textLine->getChar(specialIndent + 7);
869 if (ch.isNull() || (!ch.isSpace() && ch !=
'(' && ch !=
':'))
873 lineBegin.setCol(specialIndent);
874 specialIndent = measureIndent(lineBegin);
880 skip.setCol(textLine->lastChar());
881 bool result = skipBlanks(skip, begin,
true);
883 anchorPos = skip.col();
884 anchorIndent = measureIndent(skip);
889 if (result && skip < begin)
896 anchorIndent = specialIndent;
901 if ((c ==
'{' || c ==
'}') && textLine->getChar(textLine->firstChar()) == c)
903 cur.setCol(anchorPos = textLine->firstChar());
904 anchorIndent = measureIndent (cur);
911 if (cur.line() == 0 && cur.col() == 0 && potentialAnchorSeen)
917 uint continueIndent = (needContinue) ? calcContinue (cur, begin) : 0;
922 textLine = doc->plainKateTextLine(cur.line());
923 TQChar lastChar = textLine->getChar (anchorPos);
924 int lastLine = cur.line();
925 if (lastChar ==
'#' || lastChar ==
'[')
933 while (cur.validPosition() && cur < begin)
935 if (!skipBlanks(cur, begin,
true))
936 return isArg && !parenthesizedArg ? begin.col() : 0;
938 TQChar tc = cur.currentChar();
940 if (cur == begin || tc.isNull())
943 if (!tc.isSpace() && cur < begin)
945 uchar attrib = cur.currentAttrib();
946 if (tc ==
'{' && attrib == symbolAttrib)
948 else if (tc ==
'}' && attrib == symbolAttrib)
952 lastLine = cur.line();
961 if (lastChar ==
'{' || (lastChar ==
':' && isSpecial && needContinue))
963 indent = anchorIndent + indentWidth;
965 else if (lastChar ==
'}')
967 indent = anchorIndent;
969 else if (lastChar ==
';')
971 indent = anchorIndent + ((allowSemi && needContinue) ? continueIndent : 0);
973 else if (lastChar ==
',' || lastChar ==
'(')
975 textLine = doc->plainKateTextLine(lastLine);
977 KateDocCursor finish(lastLine, textLine->lastChar() + 1, doc);
980 if (isBalanced(start, finish, TQChar(
'('), TQChar(
')'), pos) &&
false)
981 indent = anchorIndent;
985 indent = ((pos < 48) ? pos : anchorIndent + (indentWidth * 2));
988 else if (!lastChar.isNull())
990 if (anchorIndent != 0)
991 indent = anchorIndent + continueIndent;
993 indent = continueIndent;
1003 bool needsBalanced =
true;
1010 if (textLine->attribute(cur.col()) == symbolAttrib)
1013 skipBlanks(cur, end,
false);
1016 if (textLine->getChar(cur.col()) ==
'}')
1018 skipBlanks(cur, end,
true);
1019 if (cur.line() != start.line())
1020 textLine = doc->plainKateTextLine(cur.line());
1022 if (textLine->stringAtPos(cur.col(),
"else"))
1023 cur.setCol(cur.col() + 4);
1025 return indentWidth * 2;
1027 needsBalanced =
false;
1029 else if (textLine->stringAtPos(cur.col(),
"else"))
1031 cur.setCol(cur.col() + 4);
1032 needsBalanced =
false;
1033 int next = textLine->nextNonSpaceChar(cur.col());
1034 if (next >= 0 && textLine->stringAtPos(next,
"if"))
1036 cur.setCol(next + 2);
1037 needsBalanced =
true;
1040 else if (textLine->stringAtPos(cur.col(),
"if"))
1042 cur.setCol(cur.col() + 2);
1044 else if (textLine->stringAtPos(cur.col(),
"do"))
1046 cur.setCol(cur.col() + 2);
1047 needsBalanced =
false;
1049 else if (textLine->stringAtPos(cur.col(),
"for"))
1051 cur.setCol(cur.col() + 3);
1054 else if (textLine->stringAtPos(cur.col(),
"while"))
1056 cur.setCol(cur.col() + 5);
1058 else if (textLine->stringAtPos(cur.col(),
"switch"))
1060 cur.setCol(cur.col() + 6);
1062 else if (textLine->stringAtPos(cur.col(),
"using"))
1064 cur.setCol(cur.col() + 5);
1068 return indentWidth * 2;
1072 if (needsBalanced && !isBalanced (cur, end, TQChar(
'('), TQChar(
')'), openPos))
1076 return (openPos - textLine->firstChar());
1078 return indentWidth * 2;
1082 skipBlanks(cur, end,
false);
1086 if (skipBlanks(cur, end,
true))
1091 return indentWidth + calcContinue(cur, end);
1097 uint KateCSmartIndent::findOpeningBrace(
KateDocCursor &start)
1104 while (cur.moveBackward(1))
1106 if (cur.currentAttrib() == symbolAttrib)
1108 TQChar ch = cur.currentChar();
1116 KateDocCursor temp(cur.line(), doc->plainKateTextLine(cur.line())->firstChar(), doc);
1117 return measureIndent(temp);
1125 bool KateCSmartIndent::firstOpeningBrace(
KateDocCursor &start)
1130 while(cur.moveBackward(1))
1132 if (cur.currentAttrib() == symbolAttrib)
1134 TQChar ch = cur.currentChar();
1137 else if (ch ==
'}' && cur.col() == 0)
1145 uint KateCSmartIndent::findOpeningParen(
KateDocCursor &start)
1152 while (cur.moveBackward(1))
1154 if (cur.currentAttrib() == symbolAttrib)
1156 TQChar ch = cur.currentChar();
1163 return measureIndent(cur);
1170 uint KateCSmartIndent::findOpeningComment(
KateDocCursor &start)
1179 int pos = textLine->string().find(
"/*",
false);
1183 return measureIndent(temp);
1186 }
while (cur.gotoPreviousLine());
1195 TQRegExp KatePythonIndent::endWithColon = TQRegExp(
"^[^#]*:\\s*(#.*)?$" );
1196 TQRegExp KatePythonIndent::stopStmt = TQRegExp(
"^\\s*(break|continue|raise|return|pass)\\b.*" );
1197 TQRegExp KatePythonIndent::blockBegin = TQRegExp(
"^\\s*(class|def|if|elif|else|for|while|try)\\b.*" );
1199 KatePythonIndent::KatePythonIndent (KateDocument *doc)
1203 KatePythonIndent::~KatePythonIndent ()
1207 void KatePythonIndent::processNewline (
KateDocCursor &begin,
bool )
1209 int prevLine = begin.line() - 1;
1210 int prevPos = begin.col();
1212 while ((prevLine > 0) && (prevPos < 0))
1213 prevPos = doc->plainKateTextLine(--prevLine)->firstChar();
1215 int prevBlock = prevLine;
1216 int prevBlockPos = prevPos;
1217 int extraIndent = calcExtra (prevBlock, prevBlockPos, begin);
1219 int indent = doc->plainKateTextLine(prevBlock)->cursorX(prevBlockPos, tabWidth);
1220 if (extraIndent == 0)
1222 if (!stopStmt.exactMatch(doc->plainKateTextLine(prevLine)->string()))
1224 if (endWithColon.exactMatch(doc->plainKateTextLine(prevLine)->string()))
1225 indent += indentWidth;
1227 indent = doc->plainKateTextLine(prevLine)->cursorX(prevPos, tabWidth);
1231 indent += extraIndent;
1235 TQString filler = tabString (indent);
1236 doc->insertText (begin.line(), 0, filler);
1237 begin.setCol(filler.length());
1243 int KatePythonIndent::calcExtra (
int &prevBlock,
int &pos,
KateDocCursor &end)
1246 bool levelFound =
false;
1247 while ((prevBlock > 0))
1249 if (blockBegin.exactMatch(doc->plainKateTextLine(prevBlock)->string()))
1251 if ((!levelFound && nestLevel == 0) || (levelFound && nestLevel - 1 <= 0))
1253 pos = doc->plainKateTextLine(prevBlock)->firstChar();
1259 else if (stopStmt.exactMatch(doc->plainKateTextLine(prevBlock)->string()))
1270 int extraIndent = 0;
1271 while (cur.line() <
end.line())
1273 c = cur.currentChar();
1276 extraIndent += indentWidth;
1278 extraIndent -= indentWidth;
1281 else if (c ==
'\'' || c ==
'"' )
1282 traverseString( c, cur, end );
1284 if (c.isNull() || c ==
'#')
1296 bool escape =
false;
1299 c = cur.currentChar();
1300 while ( ( c != stringChar || escape ) && cur.line() <
end.line() )
1304 else if ( c ==
'\\' )
1308 c = cur.currentChar();
1338 const TQRegExp KateXmlIndent::startsWithCloseTag(
"^[ \t]*</");
1339 const TQRegExp KateXmlIndent::unclosedDoctype(
"<!DOCTYPE[^>]*$");
1341 KateXmlIndent::KateXmlIndent (KateDocument *doc)
1346 KateXmlIndent::~KateXmlIndent ()
1350 void KateXmlIndent::processNewline (
KateDocCursor &begin,
bool )
1352 begin.setCol(processLine(begin.line()));
1355 void KateXmlIndent::processChar (TQChar c)
1357 if(c !=
'/')
return;
1360 KateView *view = doc->activeView();
1361 TQString text = doc->plainKateTextLine(view->cursorLine())->string();
1362 if(text.find(startsWithCloseTag) == -1)
return;
1365 processLine(view->cursorLine());
1370 processLine (line.line());
1376 int endLine =
end.line();
1379 processLine(cur.line());
1380 if(!cur.gotoNextLine())
break;
1381 }
while(cur.line() < endLine);
1384 void KateXmlIndent::getLineInfo (uint line, uint &prevIndent,
int &numTags,
1385 uint &attrCol,
bool &unclosedTag)
1393 prevLine = doc->plainKateTextLine(line);
1394 if( (firstChar = prevLine->firstChar()) < 0) {
1400 prevIndent = prevLine->cursorX(prevLine->firstChar(), tabWidth);
1401 TQString text = prevLine->string();
1407 if(text.find(startsWithCloseTag) != -1) ++numTags;
1411 uint pos, len = text.length();
1412 bool seenOpen =
false;
1413 for(pos = 0; pos < len; ++pos) {
1414 int ch = text.at(pos).unicode();
1425 if(lastCh ==
'<') --numTags;
1430 if(lastCh ==
'<') --numTags;
1445 for(uint backLine = line; backLine; ) {
1448 if(x->string().find(
'<') == -1)
continue;
1451 if(x->string().find(unclosedDoctype) != -1) --numTags;
1452 getLineInfo(backLine, prevIndent, numTags, attrCol, unclosedTag);
1456 if(lastCh ==
'/') --numTags;
1457 unclosedTag =
false;
1461 if(lastCh ==
'<') numTags -= 2;
1470 lastCh = text.at(++attrCol).unicode();
1471 }
while(lastCh && lastCh !=
' ' && lastCh !=
'\t');
1473 while(lastCh ==
' ' || lastCh ==
'\t') {
1474 lastCh = text.at(++attrCol).unicode();
1477 attrCol = prevLine->cursorX(attrCol, tabWidth);
1481 uint KateXmlIndent::processLine (uint line)
1484 if(!kateLine)
return 0;
1487 uint prevIndent = 0, attrCol = 0;
1489 bool unclosedTag =
false;
1492 getLineInfo(line - 1, prevIndent, numTags, attrCol, unclosedTag);
1497 if(unclosedTag) indent = attrCol;
1498 else indent = prevIndent + numTags * indentWidth;
1499 if(indent < 0) indent = 0;
1502 if(kateLine->string().find(startsWithCloseTag) != -1) {
1503 indent -= indentWidth;
1505 if(indent < 0) indent = 0;
1508 doc->removeText(line, 0, line, kateLine->firstChar());
1509 TQString filler = tabString(indent);
1510 doc->insertText(line, 0, filler);
1512 return filler.length();
1519 KateCSAndSIndent::KateCSAndSIndent (KateDocument *doc)
1524 void KateCSAndSIndent::updateIndentString()
1527 indentString.fill(
' ', indentWidth );
1529 indentString =
'\t';
1532 KateCSAndSIndent::~KateCSAndSIndent ()
1543 updateIndentString();
1545 const int oldCol = line.col();
1546 TQString whitespace = calcIndent(line);
1548 int oldIndent = textLine->firstChar();
1549 if ( oldIndent < 0 )
1550 oldIndent = doc->lineLength( line.line() );
1552 doc->removeText(line.line(), 0, line.line(), oldIndent);
1554 doc->insertText(line.line(), 0, whitespace);
1557 if (
int(oldCol + whitespace.length()) >= oldIndent )
1558 line.setCol( oldCol + whitespace.length() - oldIndent );
1565 TQTime t; t.start();
1569 if (!cur.gotoNextLine())
1572 kdDebug(13030) <<
"+++ total: " << t.elapsed() <<
endl;
1580 static TQString initialWhitespace(
const KateTextLine::Ptr &line,
int chars,
bool convert =
true)
1582 TQString text = line->string(0, chars);
1583 if( (
int)text.length() < chars )
1585 TQString filler; filler.fill(
' ',chars - text.length());
1588 for( uint n = 0; n < text.length(); ++n )
1590 if( text[n] !=
'\t' && text[n] !=
' ' )
1593 return text.left( n );
1600 TQString KateCSAndSIndent::findOpeningCommentIndentation(
const KateDocCursor &start)
1609 int pos = textLine->string().findRev(
"/*");
1612 return initialWhitespace(textLine, pos);
1613 }
while (cur.gotoPreviousLine());
1616 kdWarning( 13030 ) <<
" in a comment, but can't find the start of it" <<
endl;
1617 return TQString::null;
1623 int line = begin.line();
1625 while ((line > 0) && (first < 0))
1626 first = doc->plainKateTextLine(--line)->firstChar();
1638 if ( !(textLine->attribute(textLine->lastChar()) == doxyCommentAttrib && !textLine->endingWith(
"*/")) &&
1639 !(textLine->attribute(textLine->firstChar()) == doxyCommentAttrib && !textLine->string().contains(
"*/")) )
1643 textLine = doc->plainKateTextLine(begin.line());
1644 first = textLine->firstChar();
1645 TQString indent = findOpeningCommentIndentation(begin);
1647 bool doxygenAutoInsert = doc->config()->configFlags() & KateDocumentConfig::cfDoxygenAutoTyping;
1650 if ( first >= 0 && textLine->stringAtPos(first,
"*") )
1651 indent = indent +
" ";
1653 else if ( doxygenAutoInsert )
1654 indent = indent +
" * ";
1659 doc->removeText (begin.line(), 0, begin.line(), first);
1660 doc->insertText (begin.line(), 0, indent);
1661 begin.setCol(indent.length());
1672 void KateCSAndSIndent::processNewline (
KateDocCursor &begin,
bool )
1675 if( handleDoxygen(begin) )
1682 int cursorPos = doc->plainKateTextLine( begin.line() )->firstChar();
1683 if ( cursorPos < 0 )
1684 cursorPos = doc->lineLength( begin.line() );
1685 begin.setCol( cursorPos );
1687 processLine( begin );
1694 bool KateCSAndSIndent::startsWithLabel(
int line )
1698 const int indentFirst = indentLine->firstChar();
1701 int attrib = indentLine->attribute(indentFirst);
1702 if (attrib != 0 && attrib != keywordAttrib && attrib != normalAttrib && attrib != extensionAttrib)
1706 const TQString lineContents = indentLine->string();
1707 const int indentLast = indentLine->lastChar();
1708 bool whitespaceFound =
false;
1709 for (
int n = indentFirst; n <= indentLast; ++n )
1713 char c = lineContents[n].latin1();
1717 if ( n < lineContents.length() - 1 )
1719 if ( lineContents[n+1].latin1() ==
':' )
1726 if ( n == indentFirst)
1736 if (!whitespaceFound)
1738 if (lineContents.mid(indentFirst, n - indentFirst) ==
"case")
1740 else if (lineContents.mid(indentFirst, n - indentFirst) ==
"class")
1742 whitespaceFound =
true;
1746 else if ( !isalnum(c) && c !=
'_' )
1754 template<
class T> T min(T a, T b) {
return (a < b) ? a : b; }
1756 int KateCSAndSIndent::lastNonCommentChar(
const KateDocCursor &line )
1759 TQString str = textLine->string();
1763 do p = str.find(
"//", p + 2 );
1764 while ( p >= 0 && textLine->attribute(p) != commentAttrib && textLine->attribute(p) != doxyCommentAttrib );
1771 while( p > 0 && str[p-1].isSpace() ) --p;
1775 bool KateCSAndSIndent::inForStatement(
int line )
1779 int parens = 0, semicolons = 0;
1780 for ( ; line >= 0; --line )
1783 const int first = textLine->firstChar();
1784 const int last = textLine->lastChar();
1790 for (
int curr = last; curr >= first; --curr )
1792 if ( textLine->attribute(curr) != symbolAttrib )
1795 switch( textLine->getChar(curr) )
1798 if( ++semicolons > 2 )
1820 bool KateCSAndSIndent::inStatement(
const KateDocCursor &begin )
1825 const int first = textLine->firstChar();
1829 const int attrib = textLine->attribute(first);
1830 if( first >= 0 && (attrib == 0 || attrib == symbolAttrib) && textLine->getChar(first) ==
'{' )
1834 for ( line = begin.line() - 1; line >= 0; --line )
1836 textLine = doc->plainKateTextLine(line);
1837 const int first = textLine->firstChar();
1843 if ( textLine->getChar( first ) ==
'#' )
1846 currLine.setLine( line );
1847 const int last = lastNonCommentChar( currLine );
1856 const int attrib = textLine->attribute(last);
1857 if ( attrib == commentAttrib || attrib == doxyCommentAttrib )
1860 char c = textLine->getChar(last);
1863 if ( attrib == symbolAttrib && c ==
'{' || c ==
'}' )
1867 if ( attrib == symbolAttrib && c ==
';' )
1868 return inForStatement( line );
1871 if ( attrib == symbolAttrib && c ==
':' )
1877 if( startsWithLabel( line ) )
1894 TQString KateCSAndSIndent::continuationIndent(
const KateDocCursor &begin )
1896 if( !inStatement( begin ) )
1897 return TQString::null;
1898 return indentString;
1904 TQString KateCSAndSIndent::calcIndent (
const KateDocCursor &begin)
1907 int currLineFirst = currLine->firstChar();
1912 if ( currLineFirst >= 0 &&
1913 (currLine->attribute(currLineFirst) == commentAttrib ||
1914 currLine->attribute(currLineFirst) == doxyCommentAttrib) )
1915 return currLine->string( 0, currLineFirst );
1918 if( currLineFirst >= 0 && currLine->getChar(currLineFirst) ==
'#' )
1920 if( !currLine->stringAtPos( currLineFirst+1, TQString::fromLatin1(
"region") ) &&
1921 !currLine->stringAtPos( currLineFirst+1, TQString::fromLatin1(
"endregion") ) )
1922 return TQString::null;
1933 int pos, openBraceCount = 0, openParenCount = 0;
1934 bool lookingForScopeKeywords =
true;
1935 const char *
const scopeKeywords[] = {
"for",
"do",
"while",
"if",
"else" };
1936 const char *
const blockScopeKeywords[] = {
"try",
"catch",
"switch" };
1938 while (cur.gotoPreviousLine())
1941 const int lastChar = textLine->lastChar();
1942 const int firstChar = textLine->firstChar();
1945 for( pos = lastChar; pos >= firstChar; --pos )
1947 if (textLine->attribute(pos) == symbolAttrib)
1949 char tc = textLine->getChar (pos);
1953 if( ++openParenCount > 0 )
1954 return calcIndentInBracket( begin, cur, pos );
1956 case ')':
case ']': openParenCount--;
break;
1958 if( ++openBraceCount > 0 )
1959 return calcIndentInBrace( begin, cur, pos );
1961 case '}': openBraceCount--; lookingForScopeKeywords =
false;
break;
1963 if( openParenCount == 0 )
1964 lookingForScopeKeywords =
false;
1971 if ( lookingForScopeKeywords && openParenCount == 0 &&
1972 textLine->attribute(pos) == keywordAttrib &&
1973 (pos == 0 || textLine->attribute(pos-1) != keywordAttrib ) )
1975 #define ARRLEN( array ) ( sizeof(array)/sizeof(array[0]) )
1976 for( uint n = 0; n < ARRLEN(scopeKeywords); ++n )
1977 if( textLine->stringAtPos(pos, TQString::fromLatin1(scopeKeywords[n]) ) )
1978 return calcIndentAfterKeyword( begin, cur, pos,
false );
1979 for( uint n = 0; n < ARRLEN(blockScopeKeywords); ++n )
1980 if( textLine->stringAtPos(pos, TQString::fromLatin1(blockScopeKeywords[n]) ) )
1981 return calcIndentAfterKeyword( begin, cur, pos,
true );
1988 return TQString::null;
1991 TQString KateCSAndSIndent::calcIndentInBracket(
const KateDocCursor &indentCursor,
const KateDocCursor &bracketCursor,
int bracketPos)
1998 if ( bracketPos > 48 )
2010 return indentString + initialWhitespace( bracketLine, bracketLine->firstChar() );
2013 const int indentLineFirst = indentLine->firstChar();
2016 const int attrib = indentLine->attribute(indentLineFirst);
2017 if( indentLineFirst >= 0 && (attrib == 0 || attrib == symbolAttrib) &&
2018 ( indentLine->getChar(indentLineFirst) ==
')' || indentLine->getChar(indentLineFirst) ==
']' ) )
2021 indentTo = bracketPos;
2026 indentTo = bracketLine->nextNonSpaceChar( bracketPos + 1 );
2027 if( indentTo == -1 )
2028 indentTo = bracketPos + 2;
2030 return initialWhitespace( bracketLine, indentTo );
2033 TQString KateCSAndSIndent::calcIndentAfterKeyword(
const KateDocCursor &indentCursor,
const KateDocCursor &keywordCursor,
int keywordPos,
bool blockKeyword)
2038 TQString whitespaceToKeyword = initialWhitespace( keywordLine, keywordPos,
false );
2039 if( blockKeyword ) {
2044 int first = indentLine->firstChar();
2046 const int attrib = indentLine->attribute(first);
2047 if( first >= 0 && (attrib == 0 || attrib == symbolAttrib) && indentLine->getChar(first) ==
'{' )
2048 return whitespaceToKeyword;
2057 return indentString + whitespaceToKeyword;
2060 TQString KateCSAndSIndent::calcIndentInBrace(
const KateDocCursor &indentCursor,
const KateDocCursor &braceCursor,
int bracePos)
2063 const int braceFirst = braceLine->firstChar();
2065 TQString whitespaceToOpenBrace = initialWhitespace( braceLine, bracePos,
false );
2072 if( braceFirst >= 0 && braceLine->attribute(braceFirst) == keywordAttrib &&
2073 braceLine->stringAtPos( braceFirst, TQString::fromLatin1(
"namespace" ) ) )
2074 return continuationIndent(indentCursor) + whitespaceToOpenBrace;
2076 if( braceCursor.line() > 0 )
2079 int firstPrev = prevLine->firstChar();
2080 if( firstPrev >= 0 && prevLine->attribute(firstPrev) == keywordAttrib &&
2081 prevLine->stringAtPos( firstPrev, TQString::fromLatin1(
"namespace" ) ) )
2082 return continuationIndent(indentCursor) + whitespaceToOpenBrace;
2087 const int indentFirst = indentLine->firstChar();
2090 if( indentFirst >= 0 && indentLine->getChar(indentFirst) ==
'}' )
2091 return whitespaceToOpenBrace;
2095 if ( indentFirst >= 0 && indentLine->attribute(indentFirst) == symbolAttrib &&
2096 indentLine->getChar(indentFirst) ==
':' && indentLine->getChar(indentFirst+1) !=
':' )
2098 return indentString + indentString + whitespaceToOpenBrace;
2101 const bool continuation = inStatement(indentCursor);
2103 if( !continuation && startsWithLabel( indentCursor.line() ) )
2104 return whitespaceToOpenBrace;
2107 TQString continuationIndent = continuation ? indentString : TQString::null;
2108 return indentString + continuationIndent + whitespaceToOpenBrace;
2111 void KateCSAndSIndent::processChar(TQChar c)
2114 static const TQString triggers(
"}{)]/:;#n");
2115 if (triggers.find(c) == -1)
2120 KateView *view = doc->activeView();
2126 int first = textLine->firstChar();
2127 if( first < 0 || textLine->getChar(first) !=
'#' )
2131 if ( textLine->attribute( begin.col() ) == doxyCommentAttrib )
2136 int first = textLine->firstChar();
2140 && textLine->getChar( first ) ==
'*'
2141 && textLine->nextNonSpaceChar( first+1 ) == view->cursorColumnReal()-1 )
2142 doc->removeText( view->cursorLine(), first+1, view->cursorLine(), view->cursorColumnReal()-1);
2155 class KateVarIndentPrivate {
2157 TQRegExp reIndentAfter, reIndent, reUnindent;
2163 KateVarIndent::KateVarIndent( KateDocument *doc )
2166 d =
new KateVarIndentPrivate;
2167 d->reIndentAfter = TQRegExp( doc->variable(
"var-indent-indent-after" ) );
2168 d->reIndent = TQRegExp( doc->variable(
"var-indent-indent" ) );
2169 d->reUnindent = TQRegExp( doc->variable(
"var-indent-unindent" ) );
2170 d->triggers = doc->variable(
"var-indent-triggerchars" );
2171 d->coupleAttrib = 0;
2173 slotVariableChanged(
"var-indent-couple-attribute", doc->variable(
"var-indent-couple-attribute" ) );
2174 slotVariableChanged(
"var-indent-handle-couples", doc->variable(
"var-indent-handle-couples" ) );
2177 connect( doc, TQT_SIGNAL(variableChanged(
const TQString&,
const TQString&) ),
2178 this, TQT_SLOT(slotVariableChanged(
const TQString&,
const TQString& )) );
2181 KateVarIndent::~KateVarIndent()
2197 if ( d->triggers.contains( c ) )
2199 KateTextLine::Ptr ln = doc->plainKateTextLine( doc->activeView()->cursorLine() );
2200 if ( ln->attribute( doc->activeView()->cursorColumn()-1 ) == commentAttrib )
2203 KateView *view = doc->activeView();
2205 kdDebug(13030)<<
"variable indenter: process char '"<<c<<
", line "<<begin.line()<<
endl;
2216 int ln = line.line();
2219 if ( ! ktl )
return;
2222 KateView *v = doc->activeView();
2223 if ( (ktl->firstChar() < 0) && (!v || (
int)v->cursorLine() != ln ) )
2231 ktl = doc->plainKateTextLine( --ln );
2232 fc = ktl->firstChar();
2233 if ( ktl->attribute( fc ) != commentAttrib )
2236 while ( (ln > 0) && (pos < 0) );
2241 pos = ktl->cursorX( pos,
tabWidth );
2247 if ( d->couples & Parens && coupleBalance( ln,
'(',
')' ) > 0 )
2249 else if ( d->couples & Braces && coupleBalance( ln,
'{',
'}' ) > 0 )
2251 else if ( d->couples & Brackets && coupleBalance( ln,
'[',
']' ) > 0 )
2266 int i = tl->firstChar();
2269 TQChar ch = tl->getChar( i );
2270 uchar at = tl->attribute( i );
2272 if ( d->couples & Parens && ch ==
')'
2273 && ( at == d->coupleAttrib
2274 || (! at && hasRelevantOpening(
KateDocCursor( line.line(), i, doc ) ))
2278 else if ( d->couples & Braces && ch ==
'}'
2279 && ( at == d->coupleAttrib
2280 || (! at && hasRelevantOpening(
KateDocCursor( line.line(), i, doc ) ))
2284 else if ( d->couples & Brackets && ch ==
']'
2285 && ( at == d->coupleAttrib
2286 || (! at && hasRelevantOpening(
KateDocCursor( line.line(), i, doc ) ))
2292 #define ISCOMMENTATTR(attr) (attr==commentAttrib||attr==doxyCommentAttrib)
2293 #define ISCOMMENT (ISCOMMENTATTR(ktl->attribute(ktl->firstChar()))||ISCOMMENTATTR(ktl->attribute(matchpos)))
2296 kdDebug(13030)<<
"variable indenter: starting indent: "<<pos<<
endl;
2299 if ( ktl && ! d->reIndentAfter.isEmpty()
2300 && (matchpos = d->reIndentAfter.search( doc->textLine( ln ) )) > -1
2305 ktl = doc->plainKateTextLine( line.line() );
2306 if ( ! d->reIndent.isEmpty()
2307 && (matchpos = d->reIndent.search( doc->textLine( line.line() ) )) > -1
2312 if ( ! d->reUnindent.isEmpty()
2313 && (matchpos = d->reUnindent.search( doc->textLine( line.line() ) )) > -1
2317 kdDebug(13030)<<
"variable indenter: adjusting by "<<adjustment<<
" units"<<
endl;
2319 if ( adjustment > 0 )
2321 else if ( adjustment < 0 )
2325 fc = doc->plainKateTextLine( ln )->firstChar();
2335 doc->removeText (ln, 0, ln, fc );
2341 doc->insertText (ln, 0, indent);
2350 while (cur.line() <= end.line())
2353 if (!cur.gotoNextLine())
2358 void KateVarIndent::slotVariableChanged(
const TQString &var,
const TQString &val )
2360 if ( ! var.startsWith(
"var-indent") )
2363 if ( var ==
"var-indent-indent-after" )
2364 d->reIndentAfter.setPattern( val );
2365 else if ( var ==
"var-indent-indent" )
2366 d->reIndent.setPattern( val );
2367 else if ( var ==
"var-indent-unindent" )
2368 d->reUnindent.setPattern( val );
2369 else if ( var ==
"var-indent-triggerchars" )
2371 else if ( var ==
"var-indent-handle-couples" )
2374 TQStringList l = TQStringList::split(
" ", val );
2375 if ( l.contains(
"parens") ) d->couples |= Parens;
2376 if ( l.contains(
"braces") ) d->couples |= Braces;
2377 if ( l.contains(
"brackets") ) d->couples |= Brackets;
2379 else if ( var ==
"var-indent-couple-attribute" )
2382 KateHlItemDataList items;
2383 doc->highlight()->getKateHlItemDataListCopy (0, items);
2385 for (uint i=0; i<items.count(); i++)
2387 if ( items.at(i)->name.section(
':', 1 ) == val )
2389 d->coupleAttrib = i;
2396 int KateVarIndent::coupleBalance (
int line,
const TQChar &open,
const TQChar &close )
const
2401 if ( ! ln || ! ln->length() )
return 0;
2403 for ( uint z=0; z < ln->length(); z++ )
2405 TQChar c = ln->getChar( z );
2406 if ( ln->attribute(z) == d->coupleAttrib )
2411 else if (c == close)
2418 bool KateVarIndent::hasRelevantOpening(
const KateDocCursor &end )
const
2423 TQChar
close = cur.currentChar();
2425 if ( close ==
'}' ) opener =
'{';
2426 else if ( close =
')' ) opener =
'(';
2427 else if (close =
']' ) opener =
'[';
2431 while (cur.moveBackward(1))
2433 if (cur.currentAttrib() == d->coupleAttrib)
2435 TQChar ch = cur.currentChar();
2438 else if (ch == close)
2453 KateScriptIndent::KateScriptIndent( KateDocument *doc )
2456 m_script=KateFactory::self()->indentScript (
"script-indent-c1-test");
2459 KateScriptIndent::~KateScriptIndent()
2463 void KateScriptIndent::processNewline(
KateDocCursor &begin,
bool needContinue )
2466 KateView *view = doc->activeView();
2474 kdDebug(13030)<<
"calling m_script.processChar"<<
endl;
2475 if( !m_script.processNewline( view, begin, needContinue , errorMsg ) )
2477 kdDebug(13030) <<
"Error in script-indent: " << errorMsg <<
endl;
2479 kdDebug(13030) <<
"ScriptIndent::TIME in ms: " << t.elapsed() <<
endl;
2483 void KateScriptIndent::processChar( TQChar c )
2486 KateView *view = doc->activeView();
2494 kdDebug(13030)<<
"calling m_script.processChar"<<
endl;
2495 if( !m_script.processChar( view, c , errorMsg ) )
2497 kdDebug(13030) <<
"Error in script-indent: " << errorMsg <<
endl;
2499 kdDebug(13030) <<
"ScriptIndent::TIME in ms: " << t.elapsed() <<
endl;
2506 KateView *view = doc->activeView();
2514 kdDebug(13030)<<
"calling m_script.processLine"<<
endl;
2515 if( !m_script.processLine( view, line , errorMsg ) )
2517 kdDebug(13030) <<
"Error in script-indent: " << errorMsg <<
endl;
2519 kdDebug(13030) <<
"ScriptIndent::TIME in ms: " << t.elapsed() <<
endl;
2525 #include <tqlabel.h>
2526 ScriptIndentConfigPage::ScriptIndentConfigPage ( TQWidget *parent,
const char *name )
2529 TQLabel* hello =
new TQLabel(
"Hello world! Dummy for testing purpose.",
this);
2533 ScriptIndentConfigPage::~ScriptIndentConfigPage ()
2537 void ScriptIndentConfigPage::apply ()
2539 kdDebug(13030) <<
"ScriptIndentConfigPagE::apply() was called, save config options now!" <<
endl;
This widget will be embedded into a modal dialog when clicking the "Configure..." button in the inden...
Provides Auto-Indent functionality for katepart.
static bool hasConfigPage(uint mode)
Config page support.
static TQString modeName(uint mode)
Return the mode name given the mode.
static TQStringList listModes()
List all possible modes by name.
virtual ~KateAutoIndent()
Virtual Destructor for the baseclass.
static IndenterConfigPage * configPage(TQWidget *parent, uint mode)
Support for a config page.
static TQString modeDescription(uint mode)
Return the mode description.
KateAutoIndent(KateDocument *doc)
Constructor.
virtual uint modeNumber() const
Mode index of this mode.
static KateAutoIndent * createIndenter(KateDocument *doc, uint mode)
Static methods to create and list indention modes.
Cursor class with a pointer to its document.
Provides Auto-Indent functionality for katepart.
uint measureIndent(KateDocCursor &cur) const
Measures the indention of the current textline marked by cur.
bool keepProfile
Always try to honor the leading whitespace of lines already in the file.
bool skipBlanks(KateDocCursor &cur, KateDocCursor &max, bool newline) const
Skip all whitespace starting at cur and ending at max.
virtual void updateConfig()
Update indenter's configuration (indention width, attributes etc.)
uint indentWidth
The number of characters used when tabs are replaced by spaces.
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 ...
virtual void processNewline(KateDocCursor &cur, bool needContinue)
Called every time a newline character is inserted in the document.
bool useSpaces
Should we use spaces or tabs to indent.
bool mixedIndent
Optimize indent by mixing spaces and tabs, ala emacs.
KateNormalIndent(KateDocument *doc)
Constructor.
uint tabWidth
The number of characters simulated for a tab.
TQString tabString(uint length) const
Produces a string with the proper indentation characters for its length.
virtual ~KateNormalIndent()
Virtual Destructor for the baseclass.
This indenter uses document variables to determine when to add/remove indents.
virtual void processSection(const KateDocCursor &begin, const KateDocCursor &end)
Processes a section of text, indenting each line in between.
virtual void processChar(TQChar c)
Called every time a character is inserted into the document.
virtual void processLine(KateDocCursor &line)
Aligns/indents the given line to the proper indent position.
virtual void processNewline(KateDocCursor &cur, bool needContinue)
Called every time a newline character is inserted in the document.
kndbgstream & endl(kndbgstream &s)
kdbgstream kdWarning(int area=0)
kdbgstream kdDebug(int area=0)
TQString name(StdAccel id)
const KShortcut & close()
const KShortcut & replace()