[prev in list] [next in list] [prev in thread] [next in thread]
List: kwrite-devel
Subject: Re: A problem with highlighting: matching blank lines
From: Bruce Hoult <bruce.hoult () gmail ! com>
Date: 2005-02-08 4:10:05
Message-ID: 391c0620050207201033506ec2 () mail ! gmail ! com
[Download RAW message or body]
I've taken the liberty of implementing the suggested new
blankLineContext attribute for contexts. My patch is attached.
It seems to work fine, but I've never looked at the Kate code (well,
or used Kate, for that matter) before so I may well have missed
something.
While I was there I also changed the lineBeginContext attribute
handling to work with symbolic contexts as well as numeric. This
attribute doesn't look to actually do anything though??
["blankLine.patch" (text/x-patch)]
Index: data/language.dtd
===================================================================
RCS file: /home/kde/kdelibs/kate/data/language.dtd,v
retrieving revision 1.37
diff -u -3 -p -r1.37 language.dtd
--- data/language.dtd 21 Nov 2004 23:05:32 -0000 1.37
+++ data/language.dtd 8 Feb 2005 03:44:44 -0000
@@ -162,6 +162,7 @@ TODO
attribute: The name of the ItemData to be used for matching text
lineEndContext: Next context if end of line is encountered
lineBeginContext: Next context if begin of line is encountered [optional]
+ blankLineContext: Next context if the line is totally empty [optional]
fallthrough: Use a fallthrough context [optional]
fallthroughContext: Fall through to this context [optional]
dynamic: Dynamic context [boolean, optional]
@@ -177,6 +178,7 @@ TODO:
attribute CDATA #REQUIRED
lineEndContext CDATA #REQUIRED
lineBeginContext CDATA #IMPLIED
+ blankLineContext CDATA #IMPLIED
fallthrough (%boolean;) #IMPLIED
fallthroughContext CDATA #IMPLIED
dynamic (%boolean;) #IMPLIED
Index: part/katehighlight.cpp
===================================================================
RCS file: /home/kde/kdelibs/kate/part/katehighlight.cpp,v
retrieving revision 1.214
diff -u -3 -p -r1.214 katehighlight.cpp
--- part/katehighlight.cpp 24 Jan 2005 13:27:03 -0000 1.214
+++ part/katehighlight.cpp 8 Feb 2005 03:44:45 -0000
@@ -115,7 +115,7 @@ class KateHlContext
{
public:
KateHlContext(const QString &_hlId, int attribute, int lineEndContext,int \
_lineBeginContext,
- bool _fallthrough, int _fallthroughContext, bool _dynamic);
+ int _blankLineContext, bool _fallthrough, int _fallthroughContext, \
bool _dynamic); virtual ~KateHlContext();
KateHlContext *clone(const QStringList *args);
@@ -124,6 +124,7 @@ class KateHlContext
int attr;
int ctx;
int lineBeginContext;
+ int blankLineContext;
/** @internal anders: possible escape if no rules matches.
false unless 'fallthrough="1|true"' (insensitive)
if true, go to ftcxt w/o eating of string.
@@ -1126,12 +1127,14 @@ KateHlData::KateHlData(const QString &wi
}
//BEGIN KateHlContext
-KateHlContext::KateHlContext (const QString &_hlId, int attribute, int \
lineEndContext, int _lineBeginContext, bool _fallthrough, int _fallthroughContext, \
bool _dynamic) +KateHlContext::KateHlContext (const QString &_hlId, int attribute, \
int lineEndContext, int _lineBeginContext, + int _blankLineContext, bool \
_fallthrough, int _fallthroughContext, bool _dynamic) {
hlId = _hlId;
attr = attribute;
ctx = lineEndContext;
lineBeginContext = _lineBeginContext;
+ blankLineContext = _blankLineContext;
fallthrough = _fallthrough;
ftctx = _fallthroughContext;
dynamic = _dynamic;
@@ -1140,7 +1143,7 @@ KateHlContext::KateHlContext (const QStr
KateHlContext *KateHlContext::clone(const QStringList *args)
{
- KateHlContext *ret = new KateHlContext(hlId, attr, ctx, lineBeginContext, \
fallthrough, ftctx, false); + KateHlContext *ret = new KateHlContext(hlId, attr, \
ctx, lineBeginContext, blankLineContext, fallthrough, ftctx, false);
for (uint n=0; n < items.size(); ++n)
{
@@ -1395,6 +1398,13 @@ void KateHighlighting::doHighlight ( Kat
const QString& text = textLine->string();
const int len = textLine->length();
+ if (len == 0 && context->blankLineContext != -1)
+ {
+ // regenerate context stack if needed
+ generateContextStack (&ctxNum, context->blankLineContext, &ctx, \
&previousLine); + context = contextNum(ctxNum);
+ }
+
// calc at which char the first char occurs, set it to lenght of line if never
const int firstChar = textLine->firstChar();
const int startNonSpace = (firstChar == -1) ? len : firstChar;
@@ -2682,8 +2692,8 @@ int KateHighlighting::addToContextList(c
ident,
attr,
context,
- (KateHlManager::self()->syntax->groupData(data,QString("lineBeginContext"))).isEmpty()?-1:
- (KateHlManager::self()->syntax->groupData(data,QString("lineBeginContext"))).toInt(),
+ getIdFromString(&ContextNameList, \
KateHlManager::self()->syntax->groupData(data,QString("lineBeginContext")), dummy), \
+ getIdFromString(&ContextNameList, \
KateHlManager::self()->syntax->groupData(data,QString("blankLineContext")), dummy), \
ft, ftc, dynamic);
m_contexts.push_back (ctxNew);
_______________________________________________
KWrite-Devel mailing list
KWrite-Devel@kde.org
https://mail.kde.org/mailman/listinfo/kwrite-devel
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic