24 #include "katehighlight.h"
25 #include "katehighlight.moc"
27 #include "katetextline.h"
28 #include "katedocument.h"
29 #include "katesyntaxdocument.h"
30 #include "katerenderer.h"
31 #include "katefactory.h"
32 #include "kateschema.h"
33 #include "kateconfig.h"
35 #include <tdeconfig.h>
36 #include <tdeglobal.h>
37 #include <kinstance.h>
38 #include <kmimetype.h>
41 #include <tdepopupmenu.h>
42 #include <tdeglobalsettings.h>
44 #include <kstandarddirs.h>
45 #include <tdemessagebox.h>
46 #include <kstaticdeleter.h>
47 #include <tdeapplication.h>
49 #include <tqstringlist.h>
50 #include <tqtextstream.h>
55 #define KATE_HL_HOWMANY 1024
58 static const int KATE_DYNAMIC_CONTEXTS_RESET_DELAY = 30 * 1000;
61 #define IS_TRUE(x) x.lower() == TQString("true") || x.toInt() == 1
66 inline bool kateInsideString (
const TQString &str, TQChar ch)
68 const TQChar *unicode = str.unicode();
69 const uint len = str.length();
70 for (uint i=0; i < len; i++)
80 KateHlItem(
int attribute,
int context,
signed char regionId,
signed char regionId2);
81 virtual ~KateHlItem();
87 virtual int checkHgl(
const TQString& text,
int offset,
int len) = 0;
89 virtual bool lineContinue(){
return false;}
91 virtual TQStringList *capturedTexts() {
return 0;}
92 virtual KateHlItem *clone(
const TQStringList *) {
return this;}
94 static void dynamicSubstitute(TQString& str,
const TQStringList *args);
96 TQMemArray<KateHlItem*> subItems;
112 bool alwaysStartEnable;
113 bool customStartEnable;
119 KateHlContext(
const TQString &_hlId,
int attribute,
int lineEndContext,
int _lineBeginContext,
120 bool _fallthrough,
int _fallthroughContext,
bool _dynamic,
bool _noIndentationBasedFolding);
121 virtual ~KateHlContext();
122 KateHlContext *clone(
const TQStringList *args);
124 TQValueVector<KateHlItem*> items;
128 int lineBeginContext;
139 bool noIndentationBasedFolding;
142 class KateEmbeddedHlInfo
145 KateEmbeddedHlInfo() {loaded=
false;context0=-1;}
146 KateEmbeddedHlInfo(
bool l,
int ctx0) {loaded=l;context0=ctx0;}
153 class KateHlIncludeRule
156 KateHlIncludeRule(
int ctx_=0, uint pos_=0,
const TQString &incCtxN_=
"",
bool incAttrib=
false)
159 , incCtxN( incCtxN_ )
160 , includeAttrib( incAttrib )
174 class KateHlCharDetect :
public KateHlItem
177 KateHlCharDetect(
int attribute,
int context,
signed char regionId,
signed char regionId2, TQChar);
179 virtual int checkHgl(
const TQString& text,
int offset,
int len);
180 virtual KateHlItem *clone(
const TQStringList *args);
186 class KateHl2CharDetect :
public KateHlItem
189 KateHl2CharDetect(
int attribute,
int context,
signed char regionId,
signed char regionId2, TQChar ch1, TQChar ch2);
190 KateHl2CharDetect(
int attribute,
int context,
signed char regionId,
signed char regionId2,
const TQChar *ch);
192 virtual int checkHgl(
const TQString& text,
int offset,
int len);
193 virtual KateHlItem *clone(
const TQStringList *args);
200 class KateHlStringDetect :
public KateHlItem
203 KateHlStringDetect(
int attribute,
int context,
signed char regionId,
signed char regionId2,
const TQString &,
bool inSensitive=
false);
205 virtual int checkHgl(
const TQString& text,
int offset,
int len);
206 virtual KateHlItem *clone(
const TQStringList *args);
211 const bool _inSensitive;
214 class KateHlRangeDetect :
public KateHlItem
217 KateHlRangeDetect(
int attribute,
int context,
signed char regionId,
signed char regionId2, TQChar ch1, TQChar ch2);
219 virtual int checkHgl(
const TQString& text,
int offset,
int len);
226 class KateHlKeyword :
public KateHlItem
229 KateHlKeyword(
int attribute,
int context,
signed char regionId,
signed char regionId2,
bool insensitive,
const TQString& delims);
230 virtual ~KateHlKeyword ();
232 void addList(
const TQStringList &);
233 virtual int checkHgl(
const TQString& text,
int offset,
int len);
236 TQMemArray< TQDict<bool>* > dict;
238 const TQString& deliminators;
243 class KateHlInt :
public KateHlItem
246 KateHlInt(
int attribute,
int context,
signed char regionId,
signed char regionId2);
248 virtual int checkHgl(
const TQString& text,
int offset,
int len);
251 class KateHlFloat :
public KateHlItem
254 KateHlFloat(
int attribute,
int context,
signed char regionId,
signed char regionId2);
255 virtual ~KateHlFloat () {}
257 virtual int checkHgl(
const TQString& text,
int offset,
int len);
260 class KateHlCFloat :
public KateHlFloat
263 KateHlCFloat(
int attribute,
int context,
signed char regionId,
signed char regionId2);
265 virtual int checkHgl(
const TQString& text,
int offset,
int len);
266 int checkIntHgl(
const TQString& text,
int offset,
int len);
269 class KateHlCOct :
public KateHlItem
272 KateHlCOct(
int attribute,
int context,
signed char regionId,
signed char regionId2);
274 virtual int checkHgl(
const TQString& text,
int offset,
int len);
277 class KateHlCHex :
public KateHlItem
280 KateHlCHex(
int attribute,
int context,
signed char regionId,
signed char regionId2);
282 virtual int checkHgl(
const TQString& text,
int offset,
int len);
285 class KateHlLineContinue :
public KateHlItem
288 KateHlLineContinue(
int attribute,
int context,
signed char regionId,
signed char regionId2);
290 virtual bool endEnable(TQChar c) {
return c ==
'\0';}
291 virtual int checkHgl(
const TQString& text,
int offset,
int len);
292 virtual bool lineContinue(){
return true;}
295 class KateHlCStringChar :
public KateHlItem
298 KateHlCStringChar(
int attribute,
int context,
signed char regionId,
signed char regionId2);
300 virtual int checkHgl(
const TQString& text,
int offset,
int len);
303 class KateHlCChar :
public KateHlItem
306 KateHlCChar(
int attribute,
int context,
signed char regionId,
signed char regionId2);
308 virtual int checkHgl(
const TQString& text,
int offset,
int len);
311 class KateHlAnyChar :
public KateHlItem
314 KateHlAnyChar(
int attribute,
int context,
signed char regionId,
signed char regionId2,
const TQString& charList);
316 virtual int checkHgl(
const TQString& text,
int offset,
int len);
319 const TQString _charList;
322 class KateHlRegExpr :
public KateHlItem
325 KateHlRegExpr(
int attribute,
int context,
signed char regionId,
signed char regionId2 ,TQString expr,
bool insensitive,
bool minimal);
326 ~KateHlRegExpr() {
delete Expr; };
328 virtual int checkHgl(
const TQString& text,
int offset,
int len);
329 virtual TQStringList *capturedTexts();
330 virtual KateHlItem *clone(
const TQStringList *args);
334 bool handlesLinestart;
340 class KateHlDetectSpaces :
public KateHlItem
343 KateHlDetectSpaces (
int attribute,
int context,
signed char regionId,
signed char regionId2)
344 : KateHlItem(attribute,context,regionId,regionId2) {}
346 virtual int checkHgl(
const TQString& text,
int offset,
int len)
348 int len2 = offset + len;
349 while ((offset < len2) && text[offset].isSpace()) offset++;
354 class KateHlDetectIdentifier :
public KateHlItem
357 KateHlDetectIdentifier (
int attribute,
int context,
signed char regionId,
signed char regionId2)
358 : KateHlItem(attribute,context,regionId,regionId2) { alwaysStartEnable =
false; }
360 virtual int checkHgl(
const TQString& text,
int offset,
int len)
363 if ( text[offset].isLetter() || text[offset] == TQChar (
'_') )
366 int len2 = offset+len;
374 && (text[offset].isLetterOrNumber() || (text[offset] == TQChar (
'_')))
388 KateHlManager *KateHlManager::s_self = 0;
390 static const bool trueBool =
true;
391 static const TQString stdDeliminator = TQString (
" \t.():!+,-<=>%&*/;?[]^{|}~\\");
395 static KateHlItemData::ItemStyles getDefStyleNum(TQString name)
397 if (name==
"dsNormal")
return KateHlItemData::dsNormal;
398 else if (name==
"dsKeyword")
return KateHlItemData::dsKeyword;
399 else if (name==
"dsDataType")
return KateHlItemData::dsDataType;
400 else if (name==
"dsDecVal")
return KateHlItemData::dsDecVal;
401 else if (name==
"dsBaseN")
return KateHlItemData::dsBaseN;
402 else if (name==
"dsFloat")
return KateHlItemData::dsFloat;
403 else if (name==
"dsChar")
return KateHlItemData::dsChar;
404 else if (name==
"dsString")
return KateHlItemData::dsString;
405 else if (name==
"dsComment")
return KateHlItemData::dsComment;
406 else if (name==
"dsOthers")
return KateHlItemData::dsOthers;
407 else if (name==
"dsAlert")
return KateHlItemData::dsAlert;
408 else if (name==
"dsFunction")
return KateHlItemData::dsFunction;
409 else if (name==
"dsRegionMarker")
return KateHlItemData::dsRegionMarker;
410 else if (name==
"dsError")
return KateHlItemData::dsError;
412 return KateHlItemData::dsNormal;
417 KateHlItem::KateHlItem(
int attribute,
int context,
signed char regionId,
signed char regionId2)
425 firstNonSpace(false),
428 alwaysStartEnable (true),
429 customStartEnable (false)
433 KateHlItem::~KateHlItem()
436 for (uint i=0; i < subItems.size(); i++)
440 void KateHlItem::dynamicSubstitute(TQString &str,
const TQStringList *args)
442 uint strLength = str.length();
444 for (uint i = 0; i < strLength - 1; ++i) {
446 char c = str[i + 1].latin1();
448 str.replace(i, 1,
"");
450 else if (c >=
'0' && c <=
'9') {
451 if ((uint)(c -
'0') < args->size()) {
452 str.replace(i, 2, (*args)[c -
'0']);
453 i += ((*args)[c -
'0']).length() - 1;
456 str.replace(i, 2,
"");
467 KateHlCharDetect::KateHlCharDetect(
int attribute,
int context,
signed char regionId,
signed char regionId2, TQChar c)
468 : KateHlItem(attribute,context,regionId,regionId2)
473 int KateHlCharDetect::checkHgl(
const TQString& text,
int offset,
int )
475 if (text[offset] == sChar)
481 KateHlItem *KateHlCharDetect::clone(
const TQStringList *args)
483 char c = sChar.latin1();
485 if (c < '0' || c >
'9' || (
unsigned)(c -
'0') >= args->size())
488 KateHlCharDetect *ret =
new KateHlCharDetect(attr, ctx, region, region2, (*args)[c -
'0'][0]);
489 ret->dynamicChild =
true;
495 KateHl2CharDetect::KateHl2CharDetect(
int attribute,
int context,
signed char regionId,
signed char regionId2, TQChar ch1, TQChar ch2)
496 : KateHlItem(attribute,context,regionId,regionId2)
502 int KateHl2CharDetect::checkHgl(
const TQString& text,
int offset,
int len)
504 if ((len >= 2) && text[offset++] == sChar1 && text[offset++] == sChar2)
510 KateHlItem *KateHl2CharDetect::clone(
const TQStringList *args)
512 char c1 = sChar1.latin1();
513 char c2 = sChar2.latin1();
515 if (c1 < '0' || c1 >
'9' || (
unsigned)(c1 -
'0') >= args->size())
518 if (c2 < '0' || c2 >
'9' || (
unsigned)(c2 -
'0') >= args->size())
521 KateHl2CharDetect *ret =
new KateHl2CharDetect(attr, ctx, region, region2, (*args)[c1 -
'0'][0], (*args)[c2 -
'0'][0]);
522 ret->dynamicChild =
true;
528 KateHlStringDetect::KateHlStringDetect(
int attribute,
int context,
signed char regionId,
signed char regionId2,
const TQString &s,
bool inSensitive)
529 : KateHlItem(attribute, context,regionId,regionId2)
530 , str(inSensitive ? s.upper() : s)
531 , strLen (str.length())
532 , _inSensitive(inSensitive)
536 int KateHlStringDetect::checkHgl(
const TQString& text,
int offset,
int len)
543 for (
int i=0; i < strLen; i++)
544 if (text[offset++].upper() != str[i])
551 for (
int i=0; i < strLen; i++)
552 if (text[offset++] != str[i])
561 KateHlItem *KateHlStringDetect::clone(
const TQStringList *args)
563 TQString newstr = str;
565 dynamicSubstitute(newstr, args);
570 KateHlStringDetect *ret =
new KateHlStringDetect(attr, ctx, region, region2, newstr, _inSensitive);
571 ret->dynamicChild =
true;
577 KateHlRangeDetect::KateHlRangeDetect(
int attribute,
int context,
signed char regionId,
signed char regionId2, TQChar ch1, TQChar ch2)
578 : KateHlItem(attribute,context,regionId,regionId2)
584 int KateHlRangeDetect::checkHgl(
const TQString& text,
int offset,
int len)
586 if (text[offset] == sChar1)
592 if (len < 1)
return 0;
594 while (text[offset] != sChar2);
603 KateHlKeyword::KateHlKeyword (
int attribute,
int context,
signed char regionId,
signed char regionId2,
bool insensitive,
const TQString& delims)
604 : KateHlItem(attribute,context,regionId,regionId2)
605 , _insensitive(insensitive)
606 , deliminators(delims)
610 alwaysStartEnable =
false;
611 customStartEnable =
true;
614 KateHlKeyword::~KateHlKeyword ()
616 for (uint i=0; i < dict.size(); ++i)
620 void KateHlKeyword::addList(
const TQStringList& list)
622 for(uint i=0; i < list.count(); ++i)
624 int len = list[i].length();
632 if ((uint)len >= dict.size())
634 uint oldSize = dict.size();
637 for (uint m=oldSize; m < dict.size(); ++m)
642 dict[len] =
new TQDict<bool> (17, !_insensitive);
644 dict[len]->insert(list[i], &trueBool);
648 int KateHlKeyword::checkHgl(
const TQString& text,
int offset,
int len)
650 int offset2 = offset;
653 while ((len > wordLen) && !kateInsideString (deliminators, text[offset2]))
658 if (wordLen > maxLen)
return 0;
661 if (wordLen < minLen)
return 0;
663 if ( dict[wordLen] && dict[wordLen]->
find(TQConstString(text.unicode() + offset, wordLen).
string()) )
671 KateHlInt::KateHlInt(
int attribute,
int context,
signed char regionId,
signed char regionId2)
672 : KateHlItem(attribute,context,regionId,regionId2)
674 alwaysStartEnable =
false;
677 int KateHlInt::checkHgl(
const TQString& text,
int offset,
int len)
679 int offset2 = offset;
681 while ((len > 0) && text[offset2].isDigit())
687 if (offset2 > offset)
691 for (uint i=0; i < subItems.size(); i++)
693 if ( (offset = subItems[i]->checkHgl(text, offset2, len)) )
706 KateHlFloat::KateHlFloat(
int attribute,
int context,
signed char regionId,
signed char regionId2)
707 : KateHlItem(attribute,context, regionId,regionId2)
709 alwaysStartEnable =
false;
712 int KateHlFloat::checkHgl(
const TQString& text,
int offset,
int len)
717 while ((len > 0) && text[offset].isDigit())
724 if ((len > 0) && (p = (text[offset] ==
'.')))
729 while ((len > 0) && text[offset].isDigit())
740 if ((len > 0) && ((text[offset] & 0xdf) ==
'E'))
753 for (uint i=0; i < subItems.size(); i++)
755 int offset2 = subItems[i]->checkHgl(text, offset, len);
766 if ((len > 0) && (text[offset] ==
'-' || text[offset] ==
'+'))
774 while ((len > 0) && text[offset].isDigit())
785 for (uint i=0; i < subItems.size(); i++)
787 int offset2 = subItems[i]->checkHgl(text, offset, len);
802 KateHlCOct::KateHlCOct(
int attribute,
int context,
signed char regionId,
signed char regionId2)
803 : KateHlItem(attribute,context,regionId,regionId2)
805 alwaysStartEnable =
false;
808 int KateHlCOct::checkHgl(
const TQString& text,
int offset,
int len)
810 if (text[offset] ==
'0')
815 int offset2 = offset;
817 while ((len > 0) && (text.at(offset2) >= TQChar(
'0') && text.at(offset2) <= TQChar(
'7')))
823 if (offset2 > offset)
825 if ((len > 0) && ((text[offset2] & 0xdf) ==
'L' || (text[offset] & 0xdf) ==
'U' ))
837 KateHlCHex::KateHlCHex(
int attribute,
int context,
signed char regionId,
signed char regionId2)
838 : KateHlItem(attribute,context,regionId,regionId2)
840 alwaysStartEnable =
false;
843 int KateHlCHex::checkHgl(
const TQString& text,
int offset,
int len)
845 if ((len > 1) && (text[offset++] ==
'0') && ((text[offset++] & 0xdf) ==
'X' ))
849 int offset2 = offset;
851 while ((len > 0) && (text[offset2].isDigit() || ((text[offset2] & 0xdf) >=
'A' && (text[offset2] & 0xdf) <=
'F')))
857 if (offset2 > offset)
859 if ((len > 0) && ((text[offset2] & 0xdf) ==
'L' || (text[offset2] & 0xdf) ==
'U' ))
871 KateHlCFloat::KateHlCFloat(
int attribute,
int context,
signed char regionId,
signed char regionId2)
872 : KateHlFloat(attribute,context,regionId,regionId2)
874 alwaysStartEnable =
false;
877 int KateHlCFloat::checkIntHgl(
const TQString& text,
int offset,
int len)
879 int offset2 = offset;
881 while ((len > 0) && text[offset].isDigit()) {
886 if (offset2 > offset)
892 int KateHlCFloat::checkHgl(
const TQString& text,
int offset,
int len)
894 int offset2 = KateHlFloat::checkHgl(text, offset, len);
898 if ((text[offset2] & 0xdf) ==
'F' )
905 offset2 = checkIntHgl(text, offset, len);
907 if (offset2 && ((text[offset2] & 0xdf) ==
'F' ))
916 KateHlAnyChar::KateHlAnyChar(
int attribute,
int context,
signed char regionId,
signed char regionId2,
const TQString& charList)
917 : KateHlItem(attribute, context,regionId,regionId2)
918 , _charList(charList)
922 int KateHlAnyChar::checkHgl(
const TQString& text,
int offset,
int)
924 if (kateInsideString (_charList, text[offset]))
932 KateHlRegExpr::KateHlRegExpr(
int attribute,
int context,
signed char regionId,
signed char regionId2, TQString regexp,
bool insensitive,
bool minimal)
933 : KateHlItem(attribute, context, regionId,regionId2)
934 , handlesLinestart (regexp.startsWith(
"^"))
936 , _insensitive(insensitive)
939 if (!handlesLinestart)
942 Expr =
new TQRegExp(regexp, !_insensitive);
943 Expr->setMinimal(_minimal);
946 int KateHlRegExpr::checkHgl(
const TQString& text,
int offset,
int )
948 if (offset && handlesLinestart)
951 int offset2 = Expr->search( text, offset, TQRegExp::CaretAtOffset );
953 if (offset2 == -1)
return 0;
955 return (offset + Expr->matchedLength());
958 TQStringList *KateHlRegExpr::capturedTexts()
960 return new TQStringList(Expr->capturedTexts());
963 KateHlItem *KateHlRegExpr::clone(
const TQStringList *args)
965 TQString regexp = _regexp;
966 TQStringList escArgs = *args;
968 for (TQStringList::Iterator it = escArgs.begin(); it != escArgs.end(); ++it)
970 (*it).replace(TQRegExp(
"(\\W)"),
"\\\\1");
973 dynamicSubstitute(regexp, &escArgs);
975 if (regexp == _regexp)
980 KateHlRegExpr *ret =
new KateHlRegExpr(attr, ctx, region, region2, regexp, _insensitive, _minimal);
981 ret->dynamicChild =
true;
987 KateHlLineContinue::KateHlLineContinue(
int attribute,
int context,
signed char regionId,
signed char regionId2)
988 : KateHlItem(attribute,context,regionId,regionId2) {
991 int KateHlLineContinue::checkHgl(
const TQString& text,
int offset,
int len)
993 if ((len == 1) && (text[offset] ==
'\\'))
1001 KateHlCStringChar::KateHlCStringChar(
int attribute,
int context,
signed char regionId,
signed char regionId2)
1002 : KateHlItem(attribute,context,regionId,regionId2) {
1006 static int checkEscapedChar(
const TQString& text,
int offset,
int& len)
1009 if (text[offset] ==
'\\' && len > 1)
1014 switch(text[offset])
1040 for (i = 0; (len > 0) && (i < 2) && (((
static_cast<const char>(text.at(offset)) >=
'0') && (
static_cast<const char>(text.at(offset)) <=
'9')) || ((text[offset] & 0xdf) >=
'A' && (text[offset] & 0xdf) <=
'F')); i++)
1051 case '0':
case '1':
case '2':
case '3' :
1052 case '4':
case '5':
case '6':
case '7' :
1053 for (i = 0; (len > 0) && (i < 3) && (
static_cast<const char>(text.at(offset)) >=
'0' && static_cast<const char>(text.at(offset)) <=
'7'); i++)
1070 int KateHlCStringChar::checkHgl(
const TQString& text,
int offset,
int len)
1072 return checkEscapedChar(text, offset, len);
1077 KateHlCChar::KateHlCChar(
int attribute,
int context,
signed char regionId,
signed char regionId2)
1078 : KateHlItem(attribute,context,regionId,regionId2) {
1081 int KateHlCChar::checkHgl(
const TQString& text,
int offset,
int len)
1083 if ((len > 1) && (text[offset] ==
'\'') && (text[offset+1] !=
'\''))
1090 int offset2 = checkEscapedChar(text, offset + 1, len);
1096 offset2 = offset + 2;
1105 if ((len > 0) && (text[offset2] ==
'\''))
1114 KateHl2CharDetect::KateHl2CharDetect(
int attribute,
int context,
signed char regionId,
signed char regionId2,
const TQChar *s)
1115 : KateHlItem(attribute,context,regionId,regionId2) {
1121 KateHlItemData::KateHlItemData(
const TQString name,
int defStyleNum)
1122 : name(name), defStyleNum(defStyleNum) {
1125 KateHlData::KateHlData(
const TQString &wildcards,
const TQString &mimetypes,
const TQString &identifier,
int priority)
1126 : wildcards(wildcards), mimetypes(mimetypes), identifier(identifier), priority(priority)
1131 KateHlContext::KateHlContext (
const TQString &_hlId,
int attribute,
int lineEndContext,
int _lineBeginContext,
bool _fallthrough,
1132 int _fallthroughContext,
bool _dynamic,
bool _noIndentationBasedFolding)
1136 ctx = lineEndContext;
1137 lineBeginContext = _lineBeginContext;
1138 fallthrough = _fallthrough;
1139 ftctx = _fallthroughContext;
1141 dynamicChild =
false;
1142 noIndentationBasedFolding=_noIndentationBasedFolding;
1143 if (_noIndentationBasedFolding)
kdDebug(13010)<<TQString(
"**********************_noIndentationBasedFolding is TRUE*****************")<<
endl;
1147 KateHlContext *KateHlContext::clone(
const TQStringList *args)
1149 KateHlContext *ret =
new KateHlContext(hlId, attr, ctx, lineBeginContext, fallthrough, ftctx,
false,noIndentationBasedFolding);
1151 for (uint n=0; n < items.size(); ++n)
1153 KateHlItem *item = items[n];
1154 KateHlItem *i = (item->dynamic ? item->clone(args) : item);
1155 ret->items.append(i);
1158 ret->dynamicChild =
true;
1163 KateHlContext::~KateHlContext()
1167 for (uint n=0; n < items.size(); ++n)
1169 if (items[n]->dynamicChild)
1179 m_attributeArrays.setAutoDelete (
true);
1181 errorsAndWarnings =
"";
1184 m_foldingIndentationSensitive =
false;
1186 internalIDList.setAutoDelete(
true);
1192 iNameTranslated = i18n(
"None");
1196 m_additionalData.insert(
"none",
new HighlightPropertyBag );
1197 m_additionalData[
"none"]->deliminator = stdDeliminator;
1198 m_additionalData[
"none"]->wordWrapDeliminator = stdDeliminator;
1199 m_hlIndex[0] =
"none";
1204 iNameTranslated = def->nameTranslated;
1205 iSection = def->section;
1206 iHidden = def->hidden;
1207 iWildcards = def->extension;
1208 iMimetypes = def->mimetype;
1209 identifier = def->identifier;
1210 iVersion=def->version;
1211 iAuthor=def->author;
1212 iLicense=def->license;
1213 m_priority=def->priority.toInt();
1216 deliminator = stdDeliminator;
1219 KateHighlighting::~KateHighlighting()
1222 for (uint i=0; i < m_contexts.size(); ++i)
1223 delete m_contexts[i];
1224 m_contexts.clear ();
1227 void KateHighlighting::generateContextStack(
int *ctxNum,
int ctx, TQMemArray<short>* ctxs,
int *prevLine)
1236 ctxs->resize (ctxs->size()+1, TQGArray::SpeedOptim);
1237 (*ctxs)[ctxs->size()-1]=(*ctxNum);
1245 (*ctxNum)=( (ctxs->isEmpty() ) ? 0 : (*ctxs)[ctxs->size()-1]);
1249 int size = ctxs->size() + ctx + 1;
1253 ctxs->resize (size, TQGArray::SpeedOptim);
1254 (*ctxNum)=(*ctxs)[size-1];
1258 ctxs->resize (0, TQGArray::SpeedOptim);
1264 if ((*prevLine) >= (
int)(ctxs->size()-1))
1266 *prevLine=ctxs->size()-1;
1268 if ( ctxs->isEmpty() )
1271 KateHlContext *c = contextNum((*ctxs)[ctxs->size()-1]);
1272 if (c && (c->ctx != -1))
1290 int KateHighlighting::makeDynamicContext(KateHlContext *model,
const TQStringList *args)
1292 QPair<KateHlContext *, TQString>
key(model, args->front());
1295 if (dynamicCtxs.contains(key))
1296 value = dynamicCtxs[key];
1299 kdDebug(13010) <<
"new stuff: " << startctx <<
endl;
1301 KateHlContext *newctx = model->clone(args);
1303 m_contexts.push_back (newctx);
1306 dynamicCtxs[
key] = value;
1307 KateHlManager::self()->incDynamicCtxs();
1319 void KateHighlighting::dropDynamicContexts()
1321 for (uint i=base_startctx; i < m_contexts.size(); ++i)
1322 delete m_contexts[i];
1324 m_contexts.resize (base_startctx);
1326 dynamicCtxs.clear();
1327 startctx = base_startctx;
1338 void KateHighlighting::doHighlight (
KateTextLine *prevLine,
1340 TQMemArray<uint>* foldingList,
1348 if (textLine->
length() > 0)
1355 TQMemArray<short> ctx;
1356 ctx.duplicate (prevLine->
ctxArray());
1359 int previousLine = -1;
1360 KateHlContext *context;
1365 context = contextNum(ctxNum);
1370 ctxNum = ctx[ctx.size()-1];
1376 if (!(context = contextNum(ctxNum)))
1377 context = contextNum(0);
1381 previousLine=ctx.size()-1;
1390 generateContextStack(&ctxNum, context->ctx, &ctx, &previousLine);
1392 if (!(context = contextNum(ctxNum)))
1393 context = contextNum(0);
1402 TQChar lastChar =
' ';
1403 const TQString& text = textLine->
string();
1404 const int len = textLine->
length();
1407 const int firstChar = textLine->
firstChar();
1408 const int startNonSpace = (firstChar == -1) ? len : firstChar;
1411 KateHlItem *item = 0;
1415 while (offset < len)
1417 bool anItemMatched =
false;
1418 bool standardStartEnableDetermined =
false;
1419 bool customStartEnableDetermined =
false;
1422 for (item = context->items.empty() ? 0 : context->items[0]; item; item = (++index < context->items.size()) ? context->items[index] : 0 )
1425 if (item->firstNonSpace && (offset > startNonSpace))
1429 if ((item->column != -1) && (item->column != offset))
1432 if (!item->alwaysStartEnable)
1434 if (item->customStartEnable)
1436 if (customStartEnableDetermined || kateInsideString (m_additionalData[context->hlId]->deliminator, lastChar))
1437 customStartEnableDetermined =
true;
1443 if (standardStartEnableDetermined || kateInsideString (stdDeliminator, lastChar))
1444 standardStartEnableDetermined =
true;
1450 int offset2 = item->checkHgl(text, offset, len-offset);
1452 if (offset2 <= offset)
1456 if ( item->lookAhead && item->ctx == ctxNum )
1462 if ( !foldingList->isEmpty() && ((item->region2 < 0) && ((
int)((*foldingList)[foldingList->size()-2]) == -item->region2) ) )
1464 foldingList->resize (foldingList->size()-2, TQGArray::SpeedOptim);
1468 foldingList->resize (foldingList->size()+2, TQGArray::SpeedOptim);
1469 (*foldingList)[foldingList->size()-2] = (uint)item->region2;
1470 if (item->region2<0)
1471 (*foldingList)[foldingList->size()-1] = offset2;
1473 (*foldingList)[foldingList->size()-1] = offset;
1488 foldingList->resize (foldingList->size()+2, TQGArray::SpeedOptim);
1489 (*foldingList)[foldingList->size()-2] = item->region;
1491 (*foldingList)[foldingList->size()-1] = offset2;
1493 (*foldingList)[foldingList->size()-1] = offset;
1499 if (item->ctx != -1)
1501 generateContextStack (&ctxNum, item->ctx, &ctx, &previousLine);
1502 context = contextNum(ctxNum);
1506 if (context->dynamic)
1508 TQStringList *lst = item->capturedTexts();
1512 int newctx = makeDynamicContext(context, lst);
1514 ctx[ctx.size() - 1] = newctx;
1516 context = contextNum(ctxNum);
1522 if (!item->lookAhead)
1529 , item->onlyConsume ? context->attr : item->attr
1533 lastChar = text[offset-1];
1536 anItemMatched =
true;
1546 if ( context->fallthrough )
1549 generateContextStack(&ctxNum, context->ftctx, &ctx, &previousLine);
1550 context=contextNum(ctxNum);
1563 *(textLine->
attributes() + offset) = context->attr;
1564 lastChar = text[offset];
1573 (*ctxChanged) =
false;
1578 (*ctxChanged) =
true;
1587 if (m_foldingIndentationSensitive) {
1588 bool noindent=
false;
1589 for(
int i=ctx.size()-1; i>=0; --i) {
1590 if (contextNum(ctx[i])->noIndentationBasedFolding) {
1599 void KateHighlighting::loadWildcards()
1601 TDEConfig *config = KateHlManager::self()->getTDEConfig();
1602 config->setGroup(
"Highlighting " + iName);
1604 TQString extensionString = config->readEntry(
"Wildcards", iWildcards);
1606 if (extensionSource != extensionString) {
1607 regexpExtensions.clear();
1608 plainExtensions.clear();
1610 extensionSource = extensionString;
1612 static TQRegExp sep(
"\\s*;\\s*");
1614 TQStringList l = TQStringList::split( sep, extensionSource );
1616 static TQRegExp boringExpression(
"\\*\\.[\\d\\w]+");
1618 for( TQStringList::Iterator it = l.begin(); it != l.end(); ++it )
1619 if (boringExpression.exactMatch(*it))
1620 plainExtensions.append((*it).mid(1));
1622 regexpExtensions.append(TQRegExp((*it),
true,
true));
1626 TQValueList<TQRegExp>& KateHighlighting::getRegexpExtensions()
1628 return regexpExtensions;
1631 TQStringList& KateHighlighting::getPlainExtensions()
1633 return plainExtensions;
1636 TQString KateHighlighting::getMimetypes()
1638 TDEConfig *config = KateHlManager::self()->getTDEConfig();
1639 config->setGroup(
"Highlighting " + iName);
1641 return config->readEntry(
"Mimetypes", iMimetypes);
1644 int KateHighlighting::priority()
1646 TDEConfig *config = KateHlManager::self()->getTDEConfig();
1647 config->setGroup(
"Highlighting " + iName);
1649 return config->readNumEntry(
"Priority", m_priority);
1652 KateHlData *KateHighlighting::getData()
1654 TDEConfig *config = KateHlManager::self()->getTDEConfig();
1655 config->setGroup(
"Highlighting " + iName);
1657 KateHlData *hlData =
new KateHlData(
1658 config->readEntry(
"Wildcards", iWildcards),
1659 config->readEntry(
"Mimetypes", iMimetypes),
1660 config->readEntry(
"Identifier", identifier),
1661 config->readNumEntry(
"Priority", m_priority));
1666 void KateHighlighting::setData(KateHlData *hlData)
1668 TDEConfig *config = KateHlManager::self()->getTDEConfig();
1669 config->setGroup(
"Highlighting " + iName);
1671 config->writeEntry(
"Wildcards",hlData->wildcards);
1672 config->writeEntry(
"Mimetypes",hlData->mimetypes);
1673 config->writeEntry(
"Priority",hlData->priority);
1676 void KateHighlighting::getKateHlItemDataList (uint schema, KateHlItemDataList &list)
1678 TDEConfig *config = KateHlManager::self()->getTDEConfig();
1679 config->setGroup(
"Highlighting " + iName +
" - Schema " + KateFactory::self()->schemaManager()->name(schema));
1682 createKateHlItemData(list);
1684 for (KateHlItemData *p = list.first(); p != 0L; p = list.next())
1686 TQStringList s = config->readListEntry(p->name);
1692 while(s.count()<9) s<<
"";
1695 TQString tmp=s[0];
if (!tmp.isEmpty()) p->defStyleNum=tmp.toInt();
1699 tmp=s[1];
if (!tmp.isEmpty()) {
1700 col=tmp.toUInt(0,16); p->setTextColor(col); }
1702 tmp=s[2];
if (!tmp.isEmpty()) {
1703 col=tmp.toUInt(0,16); p->setSelectedTextColor(col); }
1705 tmp=s[3];
if (!tmp.isEmpty()) p->setBold(tmp!=
"0");
1707 tmp=s[4];
if (!tmp.isEmpty()) p->setItalic(tmp!=
"0");
1709 tmp=s[5];
if (!tmp.isEmpty()) p->setStrikeOut(tmp!=
"0");
1711 tmp=s[6];
if (!tmp.isEmpty()) p->setUnderline(tmp!=
"0");
1713 tmp=s[7];
if (!tmp.isEmpty()) {
1714 col=tmp.toUInt(0,16); p->setBGColor(col); }
1716 tmp=s[8];
if (!tmp.isEmpty()) {
1717 col=tmp.toUInt(0,16); p->setSelectedBGColor(col); }
1729 void KateHighlighting::setKateHlItemDataList(uint schema, KateHlItemDataList &list)
1731 TDEConfig *config = KateHlManager::self()->getTDEConfig();
1732 config->setGroup(
"Highlighting " + iName +
" - Schema "
1733 + KateFactory::self()->schemaManager()->name(schema));
1735 TQStringList settings;
1737 for (KateHlItemData *p = list.first(); p != 0L; p = list.next())
1740 settings<<TQString::number(p->defStyleNum,10);
1741 settings<<(p->itemSet(KateAttribute::TextColor)?TQString::number(p->textColor().rgb(),16):
"");
1742 settings<<(p->itemSet(KateAttribute::SelectedTextColor)?TQString::number(p->selectedTextColor().rgb(),16):
"");
1743 settings<<(p->itemSet(KateAttribute::Weight)?(p->bold()?
"1":
"0"):
"");
1744 settings<<(p->itemSet(KateAttribute::Italic)?(p->italic()?
"1":
"0"):
"");
1745 settings<<(p->itemSet(KateAttribute::StrikeOut)?(p->strikeOut()?
"1":
"0"):
"");
1746 settings<<(p->itemSet(KateAttribute::Underline)?(p->underline()?
"1":
"0"):
"");
1747 settings<<(p->itemSet(KateAttribute::BGColor)?TQString::number(p->bgColor().rgb(),16):
"");
1748 settings<<(p->itemSet(KateAttribute::SelectedBGColor)?TQString::number(p->selectedBGColor().rgb(),16):
"");
1750 config->writeEntry(p->name,settings);
1757 void KateHighlighting::use()
1768 void KateHighlighting::release()
1780 void KateHighlighting::init()
1786 for (uint i=0; i < m_contexts.size(); ++i)
1787 delete m_contexts[i];
1788 m_contexts.clear ();
1798 void KateHighlighting::done()
1804 for (uint i=0; i < m_contexts.size(); ++i)
1805 delete m_contexts[i];
1806 m_contexts.clear ();
1808 internalIDList.clear();
1818 void KateHighlighting::createKateHlItemData(KateHlItemDataList &list)
1823 list.append(
new KateHlItemData(i18n(
"Normal Text"), KateHlItemData::dsNormal));
1828 if (internalIDList.isEmpty())
1831 list=internalIDList;
1837 void KateHighlighting::addToKateHlItemDataList()
1840 KateHlManager::self()->syntax->setIdentifier(buildIdentifier);
1841 KateSyntaxContextData *data = KateHlManager::self()->syntax->getGroupInfo(
"highlighting",
"itemData");
1844 while (KateHlManager::self()->syntax->nextGroup(data))
1847 TQString color = KateHlManager::self()->syntax->groupData(data,TQString(
"color"));
1848 TQString selColor = KateHlManager::self()->syntax->groupData(data,TQString(
"selColor"));
1849 TQString bold = KateHlManager::self()->syntax->groupData(data,TQString(
"bold"));
1850 TQString italic = KateHlManager::self()->syntax->groupData(data,TQString(
"italic"));
1851 TQString underline = KateHlManager::self()->syntax->groupData(data,TQString(
"underline"));
1852 TQString strikeOut = KateHlManager::self()->syntax->groupData(data,TQString(
"strikeOut"));
1853 TQString bgColor = KateHlManager::self()->syntax->groupData(data,TQString(
"backgroundColor"));
1854 TQString selBgColor = KateHlManager::self()->syntax->groupData(data,TQString(
"selBackgroundColor"));
1856 KateHlItemData* newData =
new KateHlItemData(
1857 buildPrefix+KateHlManager::self()->syntax->groupData(data,TQString(
"name")).simplifyWhiteSpace(),
1858 getDefStyleNum(KateHlManager::self()->syntax->groupData(data,TQString(
"defStyleNum"))));
1861 if (!color.isEmpty()) newData->setTextColor(TQColor(color));
1862 if (!selColor.isEmpty()) newData->setSelectedTextColor(TQColor(selColor));
1863 if (!bold.isEmpty()) newData->setBold( IS_TRUE(bold) );
1864 if (!italic.isEmpty()) newData->setItalic( IS_TRUE(italic) );
1866 if (!underline.isEmpty()) newData->setUnderline( IS_TRUE(underline) );
1867 if (!strikeOut.isEmpty()) newData->setStrikeOut( IS_TRUE(strikeOut) );
1868 if (!bgColor.isEmpty()) newData->setBGColor(TQColor(bgColor));
1869 if (!selBgColor.isEmpty()) newData->setSelectedBGColor(TQColor(selBgColor));
1871 internalIDList.append(newData);
1876 KateHlManager::self()->syntax->freeGroupInfo(data);
1889 int KateHighlighting::lookupAttrName(
const TQString& name, KateHlItemDataList &iDl)
1891 for (uint i = 0; i < iDl.count(); i++)
1892 if (iDl.at(i)->name == buildPrefix+name)
1895 kdDebug(13010)<<
"Couldn't resolve itemDataName:"<<name<<
endl;
1913 KateHlItemDataList &iDl,
1914 TQStringList *RegionList,
1915 TQStringList *ContextNameList)
1922 TQString dataname=KateHlManager::self()->syntax->groupItemData(data,TQString(
""));
1925 TQString beginRegionStr=KateHlManager::self()->syntax->groupItemData(data,TQString(
"beginRegion"));
1926 TQString endRegionStr=KateHlManager::self()->syntax->groupItemData(data,TQString(
"endRegion"));
1928 signed char regionId=0;
1929 signed char regionId2=0;
1931 if (!beginRegionStr.isEmpty())
1933 regionId = RegionList->findIndex(beginRegionStr);
1937 (*RegionList)<<beginRegionStr;
1938 regionId = RegionList->findIndex(beginRegionStr);
1943 kdDebug(13010) <<
"########### BEG REG: " << beginRegionStr <<
" NUM: " << regionId <<
endl;
1946 if (!endRegionStr.isEmpty())
1948 regionId2 = RegionList->findIndex(endRegionStr);
1952 (*RegionList)<<endRegionStr;
1953 regionId2 = RegionList->findIndex(endRegionStr);
1956 regionId2 = -regionId2 - 1;
1958 kdDebug(13010) <<
"########### END REG: " << endRegionStr <<
" NUM: " << regionId2 <<
endl;
1962 TQString tmpAttr=KateHlManager::self()->syntax->groupItemData(data,TQString(
"attribute")).simplifyWhiteSpace();
1963 bool onlyConsume = tmpAttr.isEmpty();
1968 if (TQString(
"%1").arg(tmpAttr.toInt())==tmpAttr)
1970 errorsAndWarnings+=i18n(
1971 "<B>%1</B>: Deprecated syntax. Attribute (%2) not addressed by symbolic name<BR>").
1972 arg(buildIdentifier).arg(tmpAttr);
1973 attr=tmpAttr.toInt();
1976 attr=lookupAttrName(tmpAttr,iDl);
1981 TQString unresolvedContext;
1982 TQString tmpcontext=KateHlManager::self()->syntax->groupItemData(data,TQString(
"context"));
1983 if (!tmpcontext.isEmpty())
1984 context=getIdFromString(ContextNameList, tmpcontext,unresolvedContext);
1988 if (! KateHlManager::self()->syntax->groupItemData(data,TQString(
"char")).isEmpty())
1989 chr= (KateHlManager::self()->syntax->groupItemData(data,TQString(
"char")).latin1())[0];
1994 TQString stringdata=KateHlManager::self()->syntax->groupItemData(data,TQString(
"String"));
1998 if (! KateHlManager::self()->syntax->groupItemData(data,TQString(
"char1")).isEmpty())
1999 chr1= (KateHlManager::self()->syntax->groupItemData(data,TQString(
"char1")).latin1())[0];
2004 const TQString & insensitive_str = KateHlManager::self()->syntax->groupItemData(data,TQString(
"insensitive"));
2005 bool insensitive = IS_TRUE( insensitive_str );
2008 bool minimal = IS_TRUE( KateHlManager::self()->syntax->groupItemData(data,TQString(
"minimal")) );
2011 bool lookAhead = IS_TRUE( KateHlManager::self()->syntax->groupItemData(data,TQString(
"lookAhead")) );
2013 bool dynamic= IS_TRUE(KateHlManager::self()->syntax->groupItemData(data,TQString(
"dynamic")) );
2015 bool firstNonSpace = IS_TRUE(KateHlManager::self()->syntax->groupItemData(data,TQString(
"firstNonSpace")) );
2018 TQString colStr = KateHlManager::self()->syntax->groupItemData(data,TQString(
"column"));
2019 if (!colStr.isEmpty())
2020 column = colStr.toInt();
2023 KateHlItem *tmpItem;
2025 if (dataname==
"keyword")
2027 bool keywordInsensitive = insensitive_str.isEmpty() ? !casesensitive : insensitive;
2028 KateHlKeyword *keyword=
new KateHlKeyword(attr,context,regionId,regionId2,keywordInsensitive,
2029 m_additionalData[ buildIdentifier ]->deliminator);
2032 keyword->addList(KateHlManager::self()->syntax->finddata(
"highlighting",stringdata));
2035 else if (dataname==
"Float") tmpItem= (
new KateHlFloat(attr,context,regionId,regionId2));
2036 else if (dataname==
"Int") tmpItem=(
new KateHlInt(attr,context,regionId,regionId2));
2037 else if (dataname==
"DetectChar") tmpItem=(
new KateHlCharDetect(attr,context,regionId,regionId2,chr));
2038 else if (dataname==
"Detect2Chars") tmpItem=(
new KateHl2CharDetect(attr,context,regionId,regionId2,chr,chr1));
2039 else if (dataname==
"RangeDetect") tmpItem=(
new KateHlRangeDetect(attr,context,regionId,regionId2, chr, chr1));
2040 else if (dataname==
"LineContinue") tmpItem=(
new KateHlLineContinue(attr,context,regionId,regionId2));
2041 else if (dataname==
"StringDetect") tmpItem=(
new KateHlStringDetect(attr,context,regionId,regionId2,stringdata,insensitive));
2042 else if (dataname==
"AnyChar") tmpItem=(
new KateHlAnyChar(attr,context,regionId,regionId2,stringdata));
2043 else if (dataname==
"RegExpr") tmpItem=(
new KateHlRegExpr(attr,context,regionId,regionId2,stringdata, insensitive, minimal));
2044 else if (dataname==
"HlCChar") tmpItem= (
new KateHlCChar(attr,context,regionId,regionId2));
2045 else if (dataname==
"HlCHex") tmpItem= (
new KateHlCHex(attr,context,regionId,regionId2));
2046 else if (dataname==
"HlCOct") tmpItem= (
new KateHlCOct(attr,context,regionId,regionId2));
2047 else if (dataname==
"HlCFloat") tmpItem= (
new KateHlCFloat(attr,context,regionId,regionId2));
2048 else if (dataname==
"HlCStringChar") tmpItem= (
new KateHlCStringChar(attr,context,regionId,regionId2));
2049 else if (dataname==
"DetectSpaces") tmpItem= (
new KateHlDetectSpaces(attr,context,regionId,regionId2));
2050 else if (dataname==
"DetectIdentifier") tmpItem= (
new KateHlDetectIdentifier(attr,context,regionId,regionId2));
2058 tmpItem->lookAhead = lookAhead;
2059 tmpItem->dynamic = dynamic;
2060 tmpItem->firstNonSpace = firstNonSpace;
2061 tmpItem->column = column;
2062 tmpItem->onlyConsume = onlyConsume;
2064 if (!unresolvedContext.isEmpty())
2066 unresolvedContextReferences.insert(&(tmpItem->ctx),unresolvedContext);
2072 TQString KateHighlighting::hlKeyForAttrib(
int i )
const
2077 TQMap<int,TQString>::const_iterator it = m_hlIndex.constEnd();
2078 while ( it != m_hlIndex.constBegin() )
2088 bool KateHighlighting::isInWord( TQChar c,
int attrib )
const
2090 return m_additionalData[ hlKeyForAttrib( attrib ) ]->deliminator.find(c) < 0
2091 && !c.isSpace() && c !=
'"' && c !=
'\'';
2094 bool KateHighlighting::canBreakAt( TQChar c,
int attrib )
const
2097 return (m_additionalData[ hlKeyForAttrib( attrib ) ]->wordWrapDeliminator.find(c) != -1) && (sq.find(c) == -1);
2100 signed char KateHighlighting::commentRegion(
int attr)
const {
2101 TQString commentRegion=m_additionalData[ hlKeyForAttrib( attr ) ]->multiLineRegion;
2102 return (commentRegion.isEmpty()?0:(commentRegion.toShort()));
2105 bool KateHighlighting::canComment(
int startAttrib,
int endAttrib )
const
2107 TQString k = hlKeyForAttrib( startAttrib );
2108 return ( k == hlKeyForAttrib( endAttrib ) &&
2109 ( ( !m_additionalData[k]->multiLineCommentStart.isEmpty() && !m_additionalData[k]->multiLineCommentEnd.isEmpty() ) ||
2110 ! m_additionalData[k]->singleLineCommentMarker.isEmpty() ) );
2113 TQString KateHighlighting::getCommentStart(
int attrib )
const
2115 return m_additionalData[ hlKeyForAttrib( attrib) ]->multiLineCommentStart;
2118 TQString KateHighlighting::getCommentEnd(
int attrib )
const
2120 return m_additionalData[ hlKeyForAttrib( attrib ) ]->multiLineCommentEnd;
2123 TQString KateHighlighting::getCommentSingleLineStart(
int attrib )
const
2125 return m_additionalData[ hlKeyForAttrib( attrib) ]->singleLineCommentMarker;
2128 KateHighlighting::CSLPos KateHighlighting::getCommentSingleLinePosition(
int attrib )
const
2130 return m_additionalData[ hlKeyForAttrib( attrib) ]->singleLineCommentPosition;
2138 void KateHighlighting::readCommentConfig()
2140 KateHlManager::self()->syntax->setIdentifier(buildIdentifier);
2143 TQString cmlStart=
"", cmlEnd=
"", cmlRegion=
"", cslStart=
"";
2144 CSLPos cslPosition=CSLPosColumn0;
2148 while (KateHlManager::self()->syntax->nextGroup(data))
2150 if (KateHlManager::self()->syntax->groupData(data,
"name")==
"singleLine")
2152 cslStart=KateHlManager::self()->syntax->groupData(data,
"start");
2153 TQString cslpos=KateHlManager::self()->syntax->groupData(data,
"position");
2154 if (cslpos==
"afterwhitespace")
2155 cslPosition=CSLPosAfterWhitespace;
2157 cslPosition=CSLPosColumn0;
2159 else if (KateHlManager::self()->syntax->groupData(data,
"name")==
"multiLine")
2161 cmlStart=KateHlManager::self()->syntax->groupData(data,
"start");
2162 cmlEnd=KateHlManager::self()->syntax->groupData(data,
"end");
2163 cmlRegion=KateHlManager::self()->syntax->groupData(data,
"region");
2167 KateHlManager::self()->syntax->freeGroupInfo(data);
2170 m_additionalData[buildIdentifier]->singleLineCommentMarker = cslStart;
2171 m_additionalData[buildIdentifier]->singleLineCommentPosition = cslPosition;
2172 m_additionalData[buildIdentifier]->multiLineCommentStart = cmlStart;
2173 m_additionalData[buildIdentifier]->multiLineCommentEnd = cmlEnd;
2174 m_additionalData[buildIdentifier]->multiLineRegion = cmlRegion;
2182 void KateHighlighting::readGlobalKeywordConfig()
2184 deliminator = stdDeliminator;
2186 kdDebug(13010)<<
"readGlobalKeywordConfig:BEGIN"<<
endl;
2188 KateHlManager::self()->syntax->setIdentifier(buildIdentifier);
2193 kdDebug(13010)<<
"Found global keyword config"<<
endl;
2195 if ( IS_TRUE( KateHlManager::self()->syntax->groupItemData(data,TQString(
"casesensitive")) ) )
2198 casesensitive=
false;
2201 weakDeliminator=(KateHlManager::self()->syntax->groupItemData(data,TQString(
"weakDeliminator")));
2203 kdDebug(13010)<<
"weak delimiters are: "<<weakDeliminator<<
endl;
2206 for (uint s=0; s < weakDeliminator.length(); s++)
2208 int f = deliminator.find (weakDeliminator[s]);
2211 deliminator.remove (f, 1);
2214 TQString addDelim = (KateHlManager::self()->syntax->groupItemData(data,TQString(
"additionalDeliminator")));
2216 if (!addDelim.isEmpty())
2217 deliminator=deliminator+addDelim;
2219 KateHlManager::self()->syntax->freeGroupInfo(data);
2225 weakDeliminator=TQString(
"");
2228 kdDebug(13010)<<
"readGlobalKeywordConfig:END"<<
endl;
2230 kdDebug(13010)<<
"delimiterCharacters are: "<<deliminator<<
endl;
2232 m_additionalData[buildIdentifier]->deliminator = deliminator;
2245 void KateHighlighting::readWordWrapConfig()
2250 KateHlManager::self()->syntax->setIdentifier(buildIdentifier);
2253 TQString wordWrapDeliminator = stdDeliminator;
2256 kdDebug(13010)<<
"Found global keyword config"<<
endl;
2258 wordWrapDeliminator = (KateHlManager::self()->syntax->groupItemData(data,TQString(
"wordWrapDeliminator")));
2260 if ( wordWrapDeliminator.length() == 0 ) wordWrapDeliminator = deliminator;
2262 kdDebug(13010) <<
"word wrap deliminators are " << wordWrapDeliminator <<
endl;
2264 KateHlManager::self()->syntax->freeGroupInfo(data);
2269 m_additionalData[buildIdentifier]->wordWrapDeliminator = wordWrapDeliminator;
2272 void KateHighlighting::readIndentationConfig()
2276 KateHlManager::self()->syntax->setIdentifier(buildIdentifier);
2281 m_indentation = (KateHlManager::self()->syntax->groupItemData(data,TQString(
"mode")));
2283 KateHlManager::self()->syntax->freeGroupInfo(data);
2287 void KateHighlighting::readFoldingConfig()
2292 KateHlManager::self()->syntax->setIdentifier(buildIdentifier);
2297 kdDebug(13010)<<
"Found global keyword config"<<
endl;
2299 if ( IS_TRUE( KateHlManager::self()->syntax->groupItemData(data,TQString(
"indentationsensitive")) ) )
2300 m_foldingIndentationSensitive=
true;
2302 m_foldingIndentationSensitive=
false;
2304 KateHlManager::self()->syntax->freeGroupInfo(data);
2309 m_foldingIndentationSensitive =
false;
2314 kdDebug(13010)<<
"############################ use indent for fold are: "<<m_foldingIndentationSensitive<<
endl;
2317 void KateHighlighting::createContextNameList(TQStringList *ContextNameList,
int ctx0)
2319 kdDebug(13010)<<
"creatingContextNameList:BEGIN"<<
endl;
2322 ContextNameList->clear();
2324 KateHlManager::self()->syntax->setIdentifier(buildIdentifier);
2332 while (KateHlManager::self()->syntax->nextGroup(data))
2334 TQString tmpAttr=KateHlManager::self()->syntax->groupData(data,TQString(
"name")).simplifyWhiteSpace();
2335 if (tmpAttr.isEmpty())
2337 tmpAttr=TQString(
"!KATE_INTERNAL_DUMMY! %1").arg(
id);
2338 errorsAndWarnings +=i18n(
"<B>%1</B>: Deprecated syntax. Context %2 has no symbolic name<BR>").arg(buildIdentifier).arg(
id-ctx0);
2340 else tmpAttr=buildPrefix+tmpAttr;
2341 (*ContextNameList)<<tmpAttr;
2344 KateHlManager::self()->syntax->freeGroupInfo(data);
2346 kdDebug(13010)<<
"creatingContextNameList:END"<<
endl;
2350 int KateHighlighting::getIdFromString(TQStringList *ContextNameList, TQString tmpLineEndContext, TQString &unres)
2354 if ((tmpLineEndContext==
"#stay") || (tmpLineEndContext.simplifyWhiteSpace().isEmpty()))
2357 else if (tmpLineEndContext.startsWith(
"#pop"))
2360 for(;tmpLineEndContext.startsWith(
"#pop");context--)
2362 tmpLineEndContext.remove(0,4);
2367 else if ( tmpLineEndContext.contains(
"##"))
2369 int o = tmpLineEndContext.find(
"##");
2372 TQString tmp=tmpLineEndContext.mid(o+2);
2373 if (!embeddedHls.contains(tmp)) embeddedHls.insert(tmp,KateEmbeddedHlInfo());
2374 unres=tmp+
':'+tmpLineEndContext.left(o);
2380 context=ContextNameList->findIndex(buildPrefix+tmpLineEndContext);
2383 context=tmpLineEndContext.toInt();
2384 errorsAndWarnings+=i18n(
2385 "<B>%1</B>:Deprecated syntax. Context %2 not addressed by a symbolic name"
2386 ).arg(buildIdentifier).arg(tmpLineEndContext);
2399 void KateHighlighting::makeContextList()
2404 embeddedHls.clear();
2405 unresolvedContextReferences.clear();
2407 ContextNameList.clear();
2411 embeddedHls.insert(iName,KateEmbeddedHlInfo());
2413 bool something_changed;
2415 startctx=base_startctx=0;
2421 kdDebug(13010)<<
"**************** Outer loop in make ContextList"<<
endl;
2422 kdDebug(13010)<<
"**************** Hl List count:"<<embeddedHls.count()<<
endl;
2423 something_changed=
false;
2424 for (KateEmbeddedHlInfos::const_iterator it=embeddedHls.begin(); it!=embeddedHls.end();++it)
2426 if (!it.data().loaded)
2428 kdDebug(13010)<<
"**************** Inner loop in make ContextList"<<
endl;
2429 TQString identifierToUse;
2430 kdDebug(13010)<<
"Trying to open highlighting definition file: "<< it.key()<<
endl;
2431 if (iName==it.key())
2432 identifierToUse=identifier;
2434 identifierToUse=KateHlManager::self()->identifierForName(it.key());
2436 kdDebug(13010)<<
"Location is:"<< identifierToUse<<
endl;
2438 buildPrefix=it.key()+
':';
2441 if (identifierToUse.isEmpty())
2443 kdDebug(13010)<<
"OHOH, unknown highlighting description referenced"<<
endl;
2444 kdDebug(13010)<<
"Highlighting for ("<<it.key()<<
") can not be loaded"<<
endl;
2449 kdDebug(13010)<<
"setting ("<<it.key()<<
") to loaded"<<
endl;
2452 it=embeddedHls.insert(it.key(),KateEmbeddedHlInfo(
true,startctx));
2454 buildContext0Offset=startctx;
2456 startctx=addToContextList(identifierToUse,startctx);
2460 base_startctx = startctx;
2461 something_changed=
true;
2465 }
while (something_changed);
2470 kdDebug(13010)<<
"Unresolved contexts, which need attention: "<<unresolvedContextReferences.count()<<
endl;
2473 for (KateHlUnresolvedCtxRefs::iterator unresIt=unresolvedContextReferences.begin();
2474 unresIt!=unresolvedContextReferences.end();++unresIt)
2476 TQString incCtx = unresIt.data();
2477 kdDebug(13010)<<
"Context "<<incCtx<<
" is unresolved"<<
endl;
2480 if (incCtx.endsWith(
":")) {
2481 kdDebug(13010)<<
"Looking up context0 for ruleset "<<incCtx<<
endl;
2482 incCtx = incCtx.left(incCtx.length()-1);
2484 KateEmbeddedHlInfos::const_iterator hlIt=embeddedHls.find(incCtx);
2485 if (hlIt!=embeddedHls.end())
2486 *(unresIt.key())=hlIt.data().context0;
2494 handleKateHlIncludeRules();
2496 embeddedHls.clear();
2497 unresolvedContextReferences.clear();
2499 ContextNameList.clear();
2503 if (!errorsAndWarnings.isEmpty())
2505 "There were warning(s) and/or error(s) while parsing the syntax "
2506 "highlighting configuration."),
2507 errorsAndWarnings, i18n(
"Kate Syntax Highlighting Parser"));
2513 void KateHighlighting::handleKateHlIncludeRules()
2516 kdDebug(13010)<<
"KateHlIncludeRules, which need attention: " <<includeRules.count()<<
endl;
2517 if (includeRules.isEmpty())
return;
2528 for (KateHlIncludeRules::iterator it=includeRules.begin();it!=includeRules.end();)
2530 if ((*it)->incCtx==-1)
2533 if ((*it)->incCtxN.isEmpty())
2537 KateHlIncludeRules::iterator it1=it;
2540 includeRules.remove(it);
2546 (*it)->incCtx=getIdFromString(&ContextNameList,(*it)->incCtxN,dummy);
2547 kdDebug(13010)<<
"Resolved "<<(*it)->incCtxN<<
" to "<<(*it)->incCtx<<
" for include rule"<<
endl;
2560 while (!includeRules.isEmpty())
2561 handleKateHlIncludeRulesRecursive(includeRules.begin(),&includeRules);
2564 void KateHighlighting::handleKateHlIncludeRulesRecursive(KateHlIncludeRules::iterator it, KateHlIncludeRules *list)
2566 if (it==list->end())
return;
2568 KateHlIncludeRules::iterator it1=it;
2569 int ctx=(*it1)->ctx;
2579 while ((it!=list->end()) && ((*it)->ctx==ctx))
2586 while ((it1!=list->end()) && ((*it1)->ctx==ctx))
2588 int ctx1=(*it1)->incCtx;
2591 for (KateHlIncludeRules::iterator it2=list->begin();it2!=list->end();++it2)
2593 if ((*it2)->ctx==ctx1)
2597 handleKateHlIncludeRulesRecursive(it2,list);
2603 KateHlContext *dest=m_contexts[ctx];
2604 KateHlContext *src=m_contexts[ctx1];
2610 if ( (*it1)->includeAttrib )
2611 dest->attr = src->attr;
2617 int oldLen = dest->items.size();
2618 uint itemsToInsert = src->items.size();
2621 dest->items.resize (oldLen + itemsToInsert);
2624 for (
int i=oldLen-1; i >= p; --i)
2625 dest->items[i+itemsToInsert] = dest->items[i];
2628 for (uint i=0; i < itemsToInsert; ++i )
2629 dest->items[p+i] = src->items[i];
2643 int KateHighlighting::addToContextList(
const TQString &ident,
int ctx0)
2645 kdDebug(13010)<<
"=== Adding hl with ident '"<<ident<<
"'"<<
endl;
2647 buildIdentifier=ident;
2654 if (!KateHlManager::self()->syntax->setIdentifier(ident))
2658 "Since there has been an error parsing the highlighting description, "
2659 "this highlighting will be disabled"));
2664 if (identifier == ident)
2666 readIndentationConfig ();
2669 RegionList<<
"!KateInternal_TopLevel!";
2671 m_hlIndex[internalIDList.count()] = ident;
2672 m_additionalData.insert( ident,
new HighlightPropertyBag );
2675 readCommentConfig();
2676 readGlobalKeywordConfig();
2677 readWordWrapConfig();
2679 readFoldingConfig ();
2685 addToKateHlItemDataList();
2686 KateHlItemDataList iDl = internalIDList;
2688 createContextNameList(&ContextNameList,ctx0);
2691 kdDebug(13010)<<
"Parsing Context structure"<<
endl;
2693 data=KateHlManager::self()->syntax->getGroupInfo(
"highlighting",
"context");
2694 uint i=buildContext0Offset;
2697 while (KateHlManager::self()->syntax->nextGroup(data))
2699 kdDebug(13010)<<
"Found a context in file, building structure now"<<
endl;
2701 TQString tmpAttr=KateHlManager::self()->syntax->groupData(data,TQString(
"attribute")).simplifyWhiteSpace();
2703 if (TQString(
"%1").arg(tmpAttr.toInt())==tmpAttr)
2704 attr=tmpAttr.toInt();
2706 attr=lookupAttrName(tmpAttr,iDl);
2709 ctxName=buildPrefix+KateHlManager::self()->syntax->groupData(data,TQString(
"lineEndContext")).simplifyWhiteSpace();
2711 TQString tmpLineEndContext=KateHlManager::self()->syntax->groupData(data,TQString(
"lineEndContext")).simplifyWhiteSpace();
2714 context=getIdFromString(&ContextNameList, tmpLineEndContext,dummy);
2716 TQString tmpNIBF = KateHlManager::self()->syntax->groupData(data, TQString(
"noIndentationBasedFolding") );
2717 bool noIndentationBasedFolding=IS_TRUE(tmpNIBF);
2724 TQString tmpFt = KateHlManager::self()->syntax->groupData(data, TQString(
"fallthrough") );
2725 if ( IS_TRUE(tmpFt) )
2729 TQString tmpFtc = KateHlManager::self()->syntax->groupData( data, TQString(
"fallthroughContext") );
2731 ftc=getIdFromString(&ContextNameList, tmpFtc,dummy);
2732 if (ftc == -1) ftc =0;
2734 kdDebug(13010)<<
"Setting fall through context (context "<<i<<
"): "<<ftc<<
endl;
2739 bool dynamic =
false;
2740 TQString tmpDynamic = KateHlManager::self()->syntax->groupData(data, TQString(
"dynamic") );
2741 if ( tmpDynamic.lower() ==
"true" || tmpDynamic.toInt() == 1 )
2744 KateHlContext *ctxNew =
new KateHlContext (
2748 (KateHlManager::self()->syntax->groupData(data,TQString(
"lineBeginContext"))).isEmpty()?-1:
2749 (KateHlManager::self()->syntax->groupData(data,TQString(
"lineBeginContext"))).toInt(),
2750 ft, ftc, dynamic,noIndentationBasedFolding);
2752 m_contexts.push_back (ctxNew);
2754 kdDebug(13010) <<
"INDEX: " << i <<
" LENGTH " << m_contexts.size()-1 <<
endl;
2757 while (KateHlManager::self()->syntax->nextItem(data))
2763 TQString tag = KateHlManager::self()->syntax->groupItemData(data,TQString(
""));
2764 if ( tag ==
"IncludeRules" )
2766 TQString incCtx = KateHlManager::self()->syntax->groupItemData( data, TQString(
"context"));
2767 TQString incAttrib = KateHlManager::self()->syntax->groupItemData( data, TQString(
"includeAttrib"));
2768 bool includeAttrib = IS_TRUE( incAttrib );
2770 if (incCtx.startsWith(
"##") || (!incCtx.startsWith(
"#")))
2772 int incCtxi = incCtx.find(
"##");
2776 TQString incSet = incCtx.mid(incCtxi + 2);
2777 TQString incCtxN = incSet +
":" + incCtx.left(incCtxi);
2780 kdDebug(13010)<<
"Cross highlight reference <IncludeRules>, context "<<incCtxN<<
endl;
2781 KateHlIncludeRule *ir=
new KateHlIncludeRule(i,m_contexts[i]->items.count(),incCtxN,includeAttrib);
2784 if (!embeddedHls.contains(incSet))
2785 embeddedHls.insert(incSet,KateEmbeddedHlInfo());
2787 kdDebug(13010)<<
"Skipping embeddedHls.insert for "<<incCtxN<<
endl;
2789 unresolvedContextReferences.insert(&(ir->incCtx), incCtxN);
2791 includeRules.append(ir);
2796 incCtx=buildPrefix+incCtx.simplifyWhiteSpace();
2797 includeRules.append(
new KateHlIncludeRule(i,m_contexts[i]->items.count(),incCtx, includeAttrib));
2805 TQString tag = KateHlManager::self()->syntax->groupKateHlItemData(data,TQString(
""));
2806 if ( tag ==
"IncludeRules" ) {
2810 int ctxId = getIdFromString(&ContextNameList,
2811 KateHlManager::self()->syntax->groupKateHlItemData( data, TQString(
"context")),dummy);
2813 kdDebug(13010)<<
"makeContextList["<<i<<
"]: including all items of context "<<ctxId<<
endl;
2814 if ( ctxId < (
int) i ) {
2815 for ( c = m_contexts[ctxId]->items.first(); c; c = m_contexts[ctxId]->items.next() )
2816 m_contexts[i]->items.append(c);
2819 kdDebug(13010)<<
"Context "<<ctxId<<
"not defined. You can not include the rules of an undefined context"<<
endl;
2824 c=createKateHlItem(data,iDl,&RegionList,&ContextNameList);
2827 m_contexts[i]->items.append(c);
2831 datasub=KateHlManager::self()->syntax->getSubItems(data);
2833 if ((tmpbool = KateHlManager::self()->syntax->nextItem(datasub)))
2835 for (;tmpbool;tmpbool=KateHlManager::self()->syntax->nextItem(datasub))
2837 c->subItems.resize (c->subItems.size()+1);
2838 c->subItems[c->subItems.size()-1] = createKateHlItem(datasub,iDl,&RegionList,&ContextNameList);
2840 KateHlManager::self()->syntax->freeGroupInfo(datasub);
2848 KateHlManager::self()->syntax->freeGroupInfo(data);
2850 if (RegionList.count()!=1)
2853 folding = folding || m_foldingIndentationSensitive;
2856 if (!m_additionalData[ ident ]->multiLineRegion.isEmpty()) {
2857 long commentregionid=RegionList.findIndex( m_additionalData[ ident ]->multiLineRegion );
2858 if (-1==commentregionid) {
2859 errorsAndWarnings+=i18n(
2860 "<B>%1</B>: Specified multiline comment region (%2) could not be resolved<BR>"
2861 ).arg(buildIdentifier).arg( m_additionalData[ ident ]->multiLineRegion );
2862 m_additionalData[ ident ]->multiLineRegion = TQString();
2863 kdDebug(13010)<<
"ERROR comment region attribute could not be resolved"<<
endl;
2866 m_additionalData[ ident ]->multiLineRegion=TQString::number(commentregionid+1);
2867 kdDebug(13010)<<
"comment region resolved to:"<<m_additionalData[ ident ]->multiLineRegion<<
endl;
2874 void KateHighlighting::clearAttributeArrays ()
2876 for ( TQIntDictIterator< TQMemArray<KateAttribute> > it( m_attributeArrays ); it.current(); ++it )
2879 KateAttributeList defaultStyleList;
2880 defaultStyleList.setAutoDelete(
true);
2881 KateHlManager::self()->getDefaults(it.currentKey(), defaultStyleList);
2883 KateHlItemDataList itemDataList;
2884 getKateHlItemDataList(it.currentKey(), itemDataList);
2886 uint nAttribs = itemDataList.count();
2887 TQMemArray<KateAttribute> *array = it.current();
2888 array->resize (nAttribs);
2890 for (uint z = 0; z < nAttribs; z++)
2892 KateHlItemData *itemData = itemDataList.at(z);
2893 KateAttribute n = *defaultStyleList.at(itemData->defStyleNum);
2895 if (itemData && itemData->isSomethingSet())
2903 TQMemArray<KateAttribute> *KateHighlighting::attributes (uint schema)
2905 TQMemArray<KateAttribute> *array;
2908 if ((array = m_attributeArrays[schema]))
2912 if (!KateFactory::self()->schemaManager()->validSchema(schema))
2915 return attributes (0);
2919 KateAttributeList defaultStyleList;
2920 defaultStyleList.setAutoDelete(
true);
2921 KateHlManager::self()->getDefaults(schema, defaultStyleList);
2923 KateHlItemDataList itemDataList;
2924 getKateHlItemDataList(schema, itemDataList);
2926 uint nAttribs = itemDataList.count();
2927 array =
new TQMemArray<KateAttribute> (nAttribs);
2929 for (uint z = 0; z < nAttribs; z++)
2931 KateHlItemData *itemData = itemDataList.at(z);
2932 KateAttribute n = *defaultStyleList.at(itemData->defStyleNum);
2934 if (itemData && itemData->isSomethingSet())
2940 m_attributeArrays.insert(schema, array);
2945 void KateHighlighting::getKateHlItemDataListCopy (uint schema, KateHlItemDataList &outlist)
2947 KateHlItemDataList itemDataList;
2948 getKateHlItemDataList(schema, itemDataList);
2951 outlist.setAutoDelete (
true);
2952 for (uint z=0; z < itemDataList.count(); z++)
2953 outlist.append (
new KateHlItemData (*itemDataList.at(z)));
2959 KateHlManager::KateHlManager()
2961 , m_config (
"katesyntaxhighlightingrc", false, false)
2962 , commonSuffixes (TQStringList::split(
";",
".orig;.new;~;.bak;.BAK"))
2964 , dynamicCtxsCount(0)
2965 , forceNoDCReset(false)
2967 hlList.setAutoDelete(
true);
2968 hlDict.setAutoDelete(
false);
2970 KateSyntaxModeList modeList = syntax->modeList();
2971 for (uint i=0; i < modeList.count(); i++)
2973 KateHighlighting *hl =
new KateHighlighting(modeList[i]);
2976 for (; insert <= hlList.count(); insert++)
2978 if (insert == hlList.count())
2981 if ( TQString(hlList.at(insert)->section() + hlList.at(insert)->nameTranslated()).lower()
2982 > TQString(hl->section() + hl->nameTranslated()).lower() )
2986 hlList.insert (insert, hl);
2987 hlDict.insert (hl->name(), hl);
2991 KateHighlighting *hl =
new KateHighlighting(0);
2992 hlList.prepend (hl);
2993 hlDict.insert (hl->name(), hl);
2995 lastCtxsReset.start();
2998 KateHlManager::~KateHlManager()
3005 KateHlManager *KateHlManager::self()
3008 sdHlMan.
setObject(s_self,
new KateHlManager ());
3013 KateHighlighting *KateHlManager::getHl(
int n)
3015 if (n < 0 || n >= (
int) hlList.count())
3018 return hlList.at(n);
3021 int KateHlManager::nameFind(
const TQString &name)
3023 int z (hlList.count() - 1);
3025 if (hlList.at(z)->name() == name)
3031 int KateHlManager::detectHighlighting (KateDocument *doc)
3033 int hl = wildcardFind( doc->url().filename() );
3035 hl = mimeFind ( doc );
3040 int KateHlManager::wildcardFind(
const TQString &fileName)
3043 if ((result = realWildcardFind(fileName)) != -1)
3046 int length = fileName.length();
3047 TQString backupSuffix = KateDocumentConfig::global()->backupSuffix();
3048 if (fileName.endsWith(backupSuffix)) {
3049 if ((result = realWildcardFind(fileName.left(length - backupSuffix.length()))) != -1)
3053 for (TQStringList::Iterator it = commonSuffixes.begin(); it != commonSuffixes.end(); ++it) {
3054 if (*it != backupSuffix && fileName.endsWith(*it)) {
3055 if ((result = realWildcardFind(fileName.left(length - (*it).length()))) != -1)
3063 int KateHlManager::realWildcardFind(
const TQString &fileName)
3065 static TQRegExp sep(
"\\s*;\\s*");
3067 TQPtrList<KateHighlighting> highlights;
3069 for (KateHighlighting *highlight = hlList.first(); highlight != 0L; highlight = hlList.next()) {
3070 highlight->loadWildcards();
3072 for (TQStringList::Iterator it = highlight->getPlainExtensions().begin(); it != highlight->getPlainExtensions().end(); ++it)
3073 if (fileName.endsWith((*it)))
3074 highlights.append(highlight);
3076 for (
int i = 0; i < (int)highlight->getRegexpExtensions().count(); i++) {
3077 TQRegExp re = highlight->getRegexpExtensions()[i];
3078 if (re.exactMatch(fileName))
3079 highlights.append(highlight);
3083 if ( !highlights.isEmpty() )
3088 for (KateHighlighting *highlight = highlights.first(); highlight != 0L; highlight = highlights.next())
3090 if (highlight->priority() > pri)
3092 pri = highlight->priority();
3093 hl = hlList.findRef (highlight);
3102 int KateHlManager::mimeFind( KateDocument *doc )
3104 static TQRegExp sep(
"\\s*;\\s*");
3106 KMimeType::Ptr mt = doc->mimeTypeForContent();
3108 TQPtrList<KateHighlighting> highlights;
3110 for (KateHighlighting *highlight = hlList.first(); highlight != 0L; highlight = hlList.next())
3112 TQStringList l = TQStringList::split( sep, highlight->getMimetypes() );
3114 for( TQStringList::Iterator it = l.begin(); it != l.end(); ++it )
3116 if ( *it == mt->name() )
3117 highlights.append (highlight);
3121 if ( !highlights.isEmpty() )
3126 for (KateHighlighting *highlight = highlights.first(); highlight != 0L; highlight = highlights.next())
3128 if (highlight->priority() > pri)
3130 pri = highlight->priority();
3131 hl = hlList.findRef (highlight);
3141 uint KateHlManager::defaultStyles()
3146 TQString KateHlManager::defaultStyleName(
int n,
bool translateNames)
3148 static TQStringList names;
3149 static TQStringList translatedNames;
3151 if (names.isEmpty())
3155 names <<
"Data Type";
3156 names <<
"Decimal/Value";
3157 names <<
"Base-N Integer";
3158 names <<
"Floating Point";
3159 names <<
"Character";
3164 names <<
"Function";
3166 names <<
"Region Marker";
3170 translatedNames << i18n(
"Normal");
3171 translatedNames << i18n(
"Keyword");
3172 translatedNames << i18n(
"Data Type");
3173 translatedNames << i18n(
"Decimal/Value");
3174 translatedNames << i18n(
"Base-N Integer");
3175 translatedNames << i18n(
"Floating Point");
3176 translatedNames << i18n(
"Character");
3177 translatedNames << i18n(
"String");
3178 translatedNames << i18n(
"Comment");
3179 translatedNames << i18n(
"Others");
3180 translatedNames << i18n(
"Alert");
3181 translatedNames << i18n(
"Function");
3183 translatedNames << i18n(
"Region Marker");
3185 translatedNames << i18n(
"Error");
3188 return translateNames ? translatedNames[n] : names[n];
3191 void KateHlManager::getDefaults(uint schema, KateAttributeList &list)
3193 list.setAutoDelete(
true);
3196 normal->setTextColor(Qt::black);
3197 normal->setSelectedTextColor(Qt::white);
3198 list.append(normal);
3201 keyword->setTextColor(Qt::black);
3202 keyword->setSelectedTextColor(Qt::white);
3203 keyword->setBold(
true);
3204 list.append(keyword);
3207 dataType->setTextColor(Qt::darkRed);
3208 dataType->setSelectedTextColor(Qt::white);
3209 list.append(dataType);
3212 decimal->setTextColor(Qt::blue);
3213 decimal->setSelectedTextColor(Qt::cyan);
3214 list.append(decimal);
3217 basen->setTextColor(Qt::darkCyan);
3218 basen->setSelectedTextColor(Qt::cyan);
3222 floatAttribute->setTextColor(Qt::darkMagenta);
3223 floatAttribute->setSelectedTextColor(Qt::cyan);
3224 list.append(floatAttribute);
3227 charAttribute->setTextColor(Qt::magenta);
3228 charAttribute->setSelectedTextColor(Qt::magenta);
3229 list.append(charAttribute);
3232 string->setTextColor(TQColor(
"#D00"));
3233 string->setSelectedTextColor(Qt::red);
3234 list.append(
string);
3237 comment->setTextColor(Qt::darkGray);
3238 comment->setSelectedTextColor(Qt::gray);
3239 comment->setItalic(
true);
3240 list.append(comment);
3243 others->setTextColor(Qt::darkGreen);
3244 others->setSelectedTextColor(Qt::green);
3245 list.append(others);
3248 alert->setTextColor(Qt::black);
3249 alert->setSelectedTextColor( TQColor(
"#FCC") );
3250 alert->setBold(
true);
3251 alert->setBGColor( TQColor(
"#FCC") );
3255 functionAttribute->setTextColor(Qt::darkBlue);
3256 functionAttribute->setSelectedTextColor(Qt::white);
3257 list.append(functionAttribute);
3260 regionmarker->setTextColor(Qt::white);
3261 regionmarker->setBGColor(Qt::gray);
3262 regionmarker->setSelectedTextColor(Qt::gray);
3263 list.append(regionmarker);
3266 error->setTextColor(Qt::red);
3267 error->setUnderline(
true);
3268 error->setSelectedTextColor(Qt::red);
3271 TDEConfig *config = KateHlManager::self()->self()->getTDEConfig();
3272 config->setGroup(
"Default Item Styles - Schema " + KateFactory::self()->schemaManager()->name(schema));
3274 for (uint z = 0; z < defaultStyles(); z++)
3277 TQStringList s = config->readListEntry(defaultStyleName(z));
3286 tmp=s[0];
if (!tmp.isEmpty()) {
3287 col=tmp.toUInt(0,16); i->setTextColor(col); }
3289 tmp=s[1];
if (!tmp.isEmpty()) {
3290 col=tmp.toUInt(0,16); i->setSelectedTextColor(col); }
3292 tmp=s[2];
if (!tmp.isEmpty()) i->setBold(tmp!=
"0");
3294 tmp=s[3];
if (!tmp.isEmpty()) i->setItalic(tmp!=
"0");
3296 tmp=s[4];
if (!tmp.isEmpty()) i->setStrikeOut(tmp!=
"0");
3298 tmp=s[5];
if (!tmp.isEmpty()) i->setUnderline(tmp!=
"0");
3300 tmp=s[6];
if (!tmp.isEmpty()) {
3303 col=tmp.toUInt(0,16);
3307 i->clearAttribute(KateAttribute::BGColor);
3309 tmp=s[7];
if (!tmp.isEmpty()) {
3312 col=tmp.toUInt(0,16);
3313 i->setSelectedBGColor(col);
3316 i->clearAttribute(KateAttribute::SelectedBGColor);
3322 void KateHlManager::setDefaults(uint schema, KateAttributeList &list)
3324 TDEConfig *config = KateHlManager::self()->self()->getTDEConfig();
3325 config->setGroup(
"Default Item Styles - Schema " + KateFactory::self()->schemaManager()->name(schema));
3327 for (uint z = 0; z < defaultStyles(); z++)
3329 TQStringList settings;
3332 settings<<(i->itemSet(KateAttribute::TextColor)?TQString::number(i->textColor().rgb(),16):
"");
3333 settings<<(i->itemSet(KateAttribute::SelectedTextColor)?TQString::number(i->selectedTextColor().rgb(),16):
"");
3334 settings<<(i->itemSet(KateAttribute::Weight)?(i->bold()?
"1":
"0"):
"");
3335 settings<<(i->itemSet(KateAttribute::Italic)?(i->italic()?
"1":
"0"):
"");
3336 settings<<(i->itemSet(KateAttribute::StrikeOut)?(i->strikeOut()?
"1":
"0"):
"");
3337 settings<<(i->itemSet(KateAttribute::Underline)?(i->underline()?
"1":
"0"):
"");
3338 settings<<(i->itemSet(KateAttribute::BGColor)?TQString::number(i->bgColor().rgb(),16):
"-");
3339 settings<<(i->itemSet(KateAttribute::SelectedBGColor)?TQString::number(i->selectedBGColor().rgb(),16):
"-");
3342 config->writeEntry(defaultStyleName(z),settings);
3348 int KateHlManager::highlights()
3350 return (
int) hlList.count();
3353 TQString KateHlManager::hlName(
int n)
3355 return hlList.at(n)->name();
3358 TQString KateHlManager::hlNameTranslated(
int n)
3360 return hlList.at(n)->nameTranslated();
3363 TQString KateHlManager::hlSection(
int n)
3365 return hlList.at(n)->section();
3368 bool KateHlManager::hlHidden(
int n)
3370 return hlList.at(n)->hidden();
3373 TQString KateHlManager::identifierForName(
const TQString& name)
3375 KateHighlighting *hl = 0;
3377 if ((hl = hlDict[name]))
3378 return hl->getIdentifier ();
3383 bool KateHlManager::resetDynamicCtxs()
3388 if (lastCtxsReset.elapsed() < KATE_DYNAMIC_CONTEXTS_RESET_DELAY)
3391 KateHighlighting *hl;
3392 for (hl = hlList.first(); hl; hl = hlList.next())
3393 hl->dropDynamicContexts();
3395 dynamicCtxsCount = 0;
3396 lastCtxsReset.start();
3403 void KateViewHighlightAction::init()
3406 subMenus.setAutoDelete(
true );
3408 connect(popupMenu(),TQT_SIGNAL(aboutToShow()),
this,TQT_SLOT(slotAboutToShow()));
3416 void KateViewHighlightAction::slotAboutToShow()
3419 int count = KateHlManager::self()->highlights();
3421 for (
int z=0; z<count; z++)
3423 TQString hlName = KateHlManager::self()->hlNameTranslated (z);
3424 TQString hlSection = KateHlManager::self()->hlSection (z);
3426 if (!KateHlManager::self()->hlHidden(z))
3428 if ( !hlSection.isEmpty() && (names.contains(hlName) < 1) )
3430 if (subMenusName.contains(hlSection) < 1)
3432 subMenusName << hlSection;
3433 TQPopupMenu *menu =
new TQPopupMenu ();
3434 subMenus.append(menu);
3435 popupMenu()->insertItem (
'&' + hlSection, menu);
3438 int m = subMenusName.findIndex (hlSection);
3440 subMenus.at(m)->insertItem (
'&' + hlName,
this, TQT_SLOT(setHl(
int)), 0, z);
3442 else if (names.contains(hlName) < 1)
3445 popupMenu()->insertItem (
'&' + hlName,
this, TQT_SLOT(setHl(
int)), 0, z);
3452 for (uint i=0;i<subMenus.count();i++)
3454 for (uint i2=0;i2<subMenus.at(i)->count();i2++)
3456 subMenus.at(i)->setItemChecked(subMenus.at(i)->idAt(i2),
false);
3459 popupMenu()->setItemChecked (0,
false);
3461 int i = subMenusName.findIndex (KateHlManager::self()->hlSection(doc->hlMode()));
3462 if (i >= 0 && subMenus.at(i))
3463 subMenus.at(i)->setItemChecked (doc->hlMode(),
true);
3465 popupMenu()->setItemChecked (0,
true);
3468 void KateViewHighlightAction::setHl (
int mode)
3473 doc->setHlMode((uint)mode);
The Attribute class incorporates all text decorations supported by Kate.
bool hlLineContinue() const
has the line the hl continue flag set
const TQMemArray< short > & ctxArray() const
context stack
This interface provides access to the Kate Document class.
int key(StdAccel) KDE_DEPRECATED
void setNoIndentBasedFolding(bool val)
sets if for the next line indent based folding should be disabled
uint length() const
Returns the length.
kdbgstream kdDebug(int area=0)
KDE_DEPRECATED type * setObject(type *obj, bool isArray=false)
Store and manage the information about Syntax Highlighting.
static void information(TQWidget *parent, const TQString &text, const TQString &caption=TQString::null, const TQString &dontShowAgainName=TQString::null, int options=Notify)
static void detailedSorry(TQWidget *parent, const TQString &text, const TQString &details, const TQString &caption=TQString::null, int options=Notify)
const TDEShortcut & find()
const TQString & string() const
Gets a QString.
void setContext(TQMemArray< short > &val)
Sets the syntax highlight context number.
static const TQString & staticQString(const char *str)
Information about each syntax hl Mode.
void setHlLineContinue(bool cont)
set hl continue flag
uchar * attributes() const
Highlighting array The size of this is string().length()
The KateTextLine represents a line of text.
int firstChar() const
Returns the position of the first non-whitespace character.
kndbgstream & endl(kndbgstream &s)
Class holding the data around the current QDomElement.
const TDEShortcut & insert()