diff options
| author | nyamatongwe <unknown> | 2004-03-19 21:46:08 +0000 | 
|---|---|---|
| committer | nyamatongwe <unknown> | 2004-03-19 21:46:08 +0000 | 
| commit | 2b58900257436c14fe09fa9b67305d7041cce16d (patch) | |
| tree | f0d8ae2d2c91694e2ebfb88971b9ad3acd854e89 | |
| parent | 4c438e8baf37e99b5c21c169718e35430738be66 (diff) | |
| download | scintilla-mirror-2b58900257436c14fe09fa9b67305d7041cce16d.tar.gz | |
Patch from Bruce Dodson for diff/patch files improves lexer and
adds folder.
| -rw-r--r-- | src/LexOthers.cxx | 62 | 
1 files changed, 56 insertions, 6 deletions
| diff --git a/src/LexOthers.cxx b/src/LexOthers.cxx index 819dd3129..66de98c3b 100644 --- a/src/LexOthers.cxx +++ b/src/LexOthers.cxx @@ -166,20 +166,39 @@ static void ColouriseDiffLine(char *lineBuffer, int endLine, Accessor &styler) {  	// 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)) { +	if (0 == strncmp(lineBuffer, "diff ", 5)) {  		styler.ColourTo(endLine, SCE_DIFF_COMMAND); -	} else if (0 == strncmp(lineBuffer, "--- ", 3)) { -		styler.ColourTo(endLine, SCE_DIFF_HEADER); -	} else if (0 == strncmp(lineBuffer, "+++ ", 3)) { -		styler.ColourTo(endLine, SCE_DIFF_HEADER); +	} else if (0 == strncmp(lineBuffer, "--- ", 4)) { +		// In a context diff, --- appears in both the header and the position markers +		if (atoi(lineBuffer+4) && !strchr(lineBuffer, '/')) +			styler.ColourTo(endLine, SCE_DIFF_POSITION); +		else +			styler.ColourTo(endLine, SCE_DIFF_HEADER); +	} else if (0 == strncmp(lineBuffer, "+++ ", 4)) { +		// I don't know of any diff where "+++ " is a position marker, but for +		// consistency, do the same as with "--- " and "*** ". +		if (atoi(lineBuffer+4) && !strchr(lineBuffer, '/')) +			styler.ColourTo(endLine, SCE_DIFF_POSITION); +		else +			styler.ColourTo(endLine, SCE_DIFF_HEADER);  	} else if (0 == strncmp(lineBuffer, "====", 4)) {  // For p4's diff  		styler.ColourTo(endLine, SCE_DIFF_HEADER);   	} else if (0 == strncmp(lineBuffer, "***", 3)) { +		// In a context diff, *** appears in both the header and the position markers. +		// Also ******** is a chunk header, but here it's treated as part of the +		// position marker since there is no separate style for a chunk header. +		if (lineBuffer[3] == ' ' && atoi(lineBuffer+4) && !strchr(lineBuffer, '/')) +			styler.ColourTo(endLine, SCE_DIFF_POSITION); +		else if (lineBuffer[3] == '*') +			styler.ColourTo(endLine, SCE_DIFF_POSITION); +		else  		styler.ColourTo(endLine, SCE_DIFF_HEADER);  	} else if (0 == strncmp(lineBuffer, "? ", 2)) {    // For difflib  		styler.ColourTo(endLine, SCE_DIFF_HEADER);  	} else if (lineBuffer[0] == '@') {  		styler.ColourTo(endLine, SCE_DIFF_POSITION); +	} else if (lineBuffer[0] >= '0' && lineBuffer[0] <= '9') { +		styler.ColourTo(endLine, SCE_DIFF_POSITION);  	} else if (lineBuffer[0] == '-' || lineBuffer[0] == '<') {  		styler.ColourTo(endLine, SCE_DIFF_DELETED);  	} else if (lineBuffer[0] == '+' || lineBuffer[0] == '>') { @@ -210,6 +229,37 @@ static void ColouriseDiffDoc(unsigned int startPos, int length, int, WordList *[  	}  } +static void FoldDiffDoc(unsigned int startPos, int length, int, WordList*[], Accessor &styler) { +	int curLine = styler.GetLine(startPos); +	int prevLevel = SC_FOLDLEVELBASE; +	if (curLine > 0) +		prevLevel = styler.LevelAt(curLine-1); + +	int curLineStart = styler.LineStart(curLine); +	do { +		int nextLevel = prevLevel; +		if (prevLevel & SC_FOLDLEVELHEADERFLAG) +			nextLevel = (prevLevel & SC_FOLDLEVELNUMBERMASK) + 1; +		 +		int lineType = styler.StyleAt(curLineStart); +		if (lineType == SCE_DIFF_COMMAND) +			nextLevel = (SC_FOLDLEVELBASE + 1) | SC_FOLDLEVELHEADERFLAG; +		else if (lineType == SCE_DIFF_HEADER) { +			nextLevel = (SC_FOLDLEVELBASE + 2) | SC_FOLDLEVELHEADERFLAG; +		} else if (lineType == SCE_DIFF_POSITION) +			nextLevel = (SC_FOLDLEVELBASE + 3) | SC_FOLDLEVELHEADERFLAG; +		 +		if ((nextLevel & SC_FOLDLEVELHEADERFLAG) && (nextLevel == prevLevel)) +			styler.SetLevel(curLine-1, prevLevel & ~SC_FOLDLEVELHEADERFLAG); + +		styler.SetLevel(curLine, nextLevel); +		prevLevel = nextLevel; +		 +		curLineStart = styler.LineStart(++curLine); +	} while (static_cast<int>(startPos) + length > curLineStart); +} + +  static void ColourisePropsLine(      char *lineBuffer,      unsigned int lengthLine, @@ -696,7 +746,7 @@ static void ColouriseNullDoc(unsigned int startPos, int length, int, WordList *[  }  LexerModule lmBatch(SCLEX_BATCH, ColouriseBatchDoc, "batch", 0, batchWordListDesc); -LexerModule lmDiff(SCLEX_DIFF, ColouriseDiffDoc, "diff", 0, emptyWordListDesc); +LexerModule lmDiff(SCLEX_DIFF, ColouriseDiffDoc, "diff", FoldDiffDoc, emptyWordListDesc);  LexerModule lmProps(SCLEX_PROPERTIES, ColourisePropsDoc, "props", FoldPropsDoc, emptyWordListDesc);  LexerModule lmMake(SCLEX_MAKEFILE, ColouriseMakeDoc, "makefile", 0, emptyWordListDesc);  LexerModule lmErrorList(SCLEX_ERRORLIST, ColouriseErrorListDoc, "errorlist", 0, emptyWordListDesc); | 
