sublime-text-git icon indicating copy to clipboard operation
sublime-text-git copied to clipboard

--color-words support

Open franciscolourenco opened this issue 12 years ago • 8 comments

This option should be configurable for displaying diffs.

franciscolourenco avatar Jun 27 '12 17:06 franciscolourenco

+1

aziz avatar Jul 06 '12 09:07 aziz

as we use the +- at the start of diff lines to add markers for theme colors, we might struggle to get this right and maintain the colored lines. any ideas?

sheldon avatar Jul 15 '12 08:07 sheldon

Color words manually? Although I really like the magenta/lime green diff when using monokai..

franciscolourenco avatar Jul 15 '12 11:07 franciscolourenco

think we'll have to, seems git have a porcelain version of the word diff so that should help, as long as it also keeps some way to differentiate lines too. here's hoping.

sheldon avatar Jul 15 '12 12:07 sheldon

Any status on this? It would be really nice to have :smile:

emichael avatar Jan 26 '16 21:01 emichael

Currently diff.py calls the --no-color option to provide diff output without ANSI escape sequences. Then, the Diff.tmLanguage file is used to provide the coloring of the added/removed lines. In order to use --color-words (or --word-diff), we would need to handle the output differently.

git diff --word-diff[=<mode>] supports three modes, as described here.

color Highlight changed words using only colors. Implies --color.

plain Show words as [-removed-] and {+added+}. Makes no attempts to escape the delimiters if they appear in the input, so the output may be ambiguous.

porcelain Use a special line-based format intended for script consumption. Added/removed/unchanged runs are printed in the usual unified diff format, starting with a +/-/ character at the beginning of the line and extending to the end of the line. Newlines in the input are represented by a tilde ~ on a line of its own.

I see two options for proceeding.

  1. Use --word-diff=plain --no-color and add rules to Diff.tmLanguage to highlight the words. This will most likely retain the ugly braces around the words removed and added (unless there's a way to hide characters with syntax highlighting?)
  2. Use --word-diff=color so that the output produces ANSI color codes, and then use an external package (e.g., SublimeANSI, https://github.com/aziz/SublimeANSI) to handle the syntax highlighting. I played around a bit with SublimeANSI, but it seems like it has some problems (https://github.com/aziz/SublimeANSI/issues/2) which I couldn't work around in ten minutes.

I'd appreciate any thoughts.

whophil avatar Feb 20 '16 02:02 whophil

I've implemented word diff in my own fork, using method 1 for syntax highlighting. Please feel free to test. https://github.com/whophil/sublime-text-git

New options for "Git Diff (Words)" have been added to the menu and command palette.

I did get some insight from this GitSavvy issue (https://github.com/divmain/GitSavvy/issues/295)

whophil avatar Feb 20 '16 21:02 whophil

See https://github.com/kemayo/sublime-text-git/pull/468

whophil avatar Feb 20 '16 22:02 whophil