[TxMt] Re: Combined diff and source code highlighting

Allan Odgaard mailinglist at textmate.org
Mon Jan 19 02:27:00 UTC 2015


On 19 Jan 2015, at 3:03, Jacob Carlborg wrote:

> I tried to add the Diff rules in the D grammar, it wasn't perfect but 
> ok. But it was not a general solution.

The general solution would probably be via injection.

> How would that be any difference if that's only what a user has typed 
> in a regular JSON file?
>
> For languages with keywords only typing a keyword is necessary to get 
> highlighting. I think that would help.

I don’t understand you here.

The problem is that TextMate grammars have nested rules that will match 
constructs that span multiple lines. Take e.g. this:

	 1  --- test.cc (saved version)
	 2  +++ (current document)
	 3  @@ -1,6 +1,6 @@
	 4   int main (int argc, char const* argv[])
	 5   {
	 6  -       for(size_t i = 0; i < count; ++i)
	 7  +/*     for(size_t i = 0; i < count; ++i)
	 8                  fprintf(stderr, "%zu\n", i);
	 9  -       return 0;
	10  +*/     return 0;
	11   }

How can you use the existing C++ grammar to figure out that line 9 
should not be rendered as commented?

Or even worse, take this (truncated horizontally):

	--- ns.mm (saved version)
	+++ (current document)
	@@ -202,8 +202,6 @@
	 		if ⌘ changes key (Qwerty-Dvorak ⌘ hybrid):
	 			if ⌥ is down: treat ⌥ as literal
	 			if ⇧ is down and (changed) key is not a-z […]
	+		else if ⌃ is down and key string is non-ASCII
	+			ignore keymap and decode virtual key code to get […]
	 		else
	 			If ⌥ is down and character (with flags & ⌥⇧) is non-ASCII 
[…]
	 			if ⇧ is down and character (with flags & ⌥⇧) is non-ASCII 
[…]

How would you know that the above is inside a comment, and should be 
styled as such?

>> For proper diff highlighting, we need to highlight the two source 
>> files
>> separately, then grab the highlighted subsets for the diff.
>
> Anyway, Github recently added this feature. I don't know how they did 
> it but to me it looks good.

GitHub produces the diff themselves from the two versions of the file, 
so they have the ability to style the two original versions.

TextMate generally just sees the resulting diff file.


More information about the textmate mailing list