Would it be possible to some how combine the diff highlighting with the highlighting of a source code? I know that it's possible to insert other grammars in a grammar but I was thinking of a general solution that doesn't require changing every existing grammar to add diff support.
It would be really cool if it would be possible to recognize each file (if multiple files in a diff) and highlight it according to the file extension.
On 16 Jan 2015, at 3:55, Jacob Carlborg wrote:
Would it be possible to some how combine the diff highlighting with the highlighting of a source code? I know that it's possible to insert other grammars in a grammar but I was thinking of a general solution that doesn't require changing every existing grammar to add diff support.
The problem is that you only have a subset of the file in a diff and TextMate’s grammars will often work on larger structures.
Take the JSON grammar where we highlight misplaced commas, such rules can’t work when we just get a random line of a JSON file.
For proper diff highlighting, we need to highlight the two source files separately, then grab the highlighted subsets for the diff.
On 2015-01-18 14:07, Allan Odgaard wrote:
The problem is that you only have a subset of the file in a diff and TextMate’s grammars will often work on larger structures.
Take the JSON grammar where we highlight misplaced commas, such rules can’t work when we just get a random line of a JSON file.
I tried to add the Diff rules in the D grammar, it wasn't perfect but ok. But it was not a general solution.
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.
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.
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.
On 2015-01-19 03:27, Allan Odgaard wrote:
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?
Oh, I see. I guess it can't. It would render everything after the line starting with "@@ ..." as C++. If possible, ignoring leading + or -.
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.
Right.