diff options
Diffstat (limited to 'src/LexOthers.cxx')
| -rw-r--r-- | src/LexOthers.cxx | 45 | 
1 files changed, 43 insertions, 2 deletions
| diff --git a/src/LexOthers.cxx b/src/LexOthers.cxx index 90f41e3bf..edbf5d06f 100644 --- a/src/LexOthers.cxx +++ b/src/LexOthers.cxx @@ -49,6 +49,46 @@ static void ColouriseBatchDoc(unsigned int startPos, int length, int, WordList *  		ColouriseBatchLine(lineBuffer, startPos + length, styler);  } +static void ColouriseDiffLine(char *lineBuffer, int endLine, Accessor &styler) { +	// It is needed to remember the current state to recognize starting +	// comment lines before the first "diff " or "--- ". If a real +	// difference starts then each line starting with ' ' is a whitespace +	// otherwise it is considered a comment (Only in..., Binary file...) +	if (0 == strncmp(lineBuffer, "diff ", 3)) { +		styler.ColourTo(endLine, 2); +	} else if (0 == strncmp(lineBuffer, "--- ", 3)) { +		styler.ColourTo(endLine, 3); +	} else if (0 == strncmp(lineBuffer, "+++ ", 3)) { +		styler.ColourTo(endLine, 3); +	} else if (lineBuffer[0] == '@') { +		styler.ColourTo(endLine, 4); +	} else if (lineBuffer[0] == '-') { +		styler.ColourTo(endLine, 5); +	} else if (lineBuffer[0] == '+') { +		styler.ColourTo(endLine, 6); +	} else if (lineBuffer[0] != ' ') { +		styler.ColourTo(endLine, 1); +	} else { +		styler.ColourTo(endLine, 0); +	} +} + +static void ColouriseDiffDoc(unsigned int startPos, int length, int, WordList *[], Accessor &styler) { +	char lineBuffer[1024]; +	styler.StartAt(startPos); +	styler.StartSegment(startPos); +	unsigned int linePos = 0; +	for (unsigned int i = startPos; i < startPos + length; i++) { +		lineBuffer[linePos++] = styler[i]; +		if (styler[i] == '\r' || styler[i] == '\n' || (linePos >= sizeof(lineBuffer) - 1)) { +			ColouriseDiffLine(lineBuffer, i, styler); +			linePos = 0; +		} +	} +	if (linePos > 0) +		ColouriseDiffLine(lineBuffer, startPos + length, styler); +} +  static void ColourisePropsLine(char *lineBuffer, int lengthLine, int startLine, int endPos, Accessor &styler) {  	int i = 0;  	while (isspace(lineBuffer[i]) && (i < lengthLine))	// Skip initial spaces @@ -297,8 +337,9 @@ static void ColouriseLatexDoc(unsigned int startPos, int length, int initStyle,  	styler.ColourTo(lengthDoc, state);  } +LexerModule lmBatch(SCLEX_BATCH, ColouriseBatchDoc); +LexerModule lmDiff(SCLEX_DIFF, ColouriseDiffDoc);  LexerModule lmProps(SCLEX_PROPERTIES, ColourisePropsDoc); -LexerModule lmErrorList(SCLEX_ERRORLIST, ColouriseErrorListDoc);  LexerModule lmMake(SCLEX_MAKEFILE, ColouriseMakeDoc); -LexerModule lmBatch(SCLEX_BATCH, ColouriseBatchDoc); +LexerModule lmErrorList(SCLEX_ERRORLIST, ColouriseErrorListDoc);  LexerModule lmLatex(SCLEX_LATEX, ColouriseLatexDoc); | 
