Magit: Add support for --color-moved

Created on 14 Apr 2018  路  4Comments  路  Source: magit/magit

git v2.15 added a fancy new --color-moved option, which is... amazing. There's a good write-up and demo of it over here.

I made a half-hearted effort at adding support for this by just adding it to the diff popup switches:

diff --git a/lisp/magit-diff.el b/lisp/magit-diff.el
index 3304935589..3344a41722 100644
--- a/lisp/magit-diff.el
+++ b/lisp/magit-diff.el
@@ -617,7 +617,8 @@ and `:slant'."
                (?b "Ignore whitespace changes"      "--ignore-space-change")
                (?w "Ignore all whitespace"          "--ignore-all-space")
                (?x "Disallow external diff drivers" "--no-ext-diff")
-               (?s "Show stats"                     "--stat"))
+               (?s "Show stats"                     "--stat")
+               (?c "Color moved"                     "--color-moved"))
     :actions  ((?d "Dwim"          magit-diff-dwim)
                (?u "Diff unstaged" magit-diff-unstaged)
                (?c "Show commit"   magit-show-commit)

but the switch didn't seem to have any affect.

I'm not sure if we can really even plumb this through since Magit seems to apply its own diff faces by "washing" the raw diff text (discarding any color escape sequences coming through from git itself)? Just wanted to start a discussion about whether or not this is even possible.

diff feature request

Most helpful comment

git v2.15 added a fancy new --color-moved option

I think that is a typo in this announcement about v2.17.

Magit seems to apply its own diff faces by "washing" the raw diff text (discarding any color escape sequences coming through from git itself)

Yes, that's how it currently works (except we simply ask git not to print any control characters), but I plan to support word-diff and that will require that git's output is manipulated beyond adding text properties and overlays. So this too will probably happen eventually, but it could be a while.

All 4 comments

git v2.15 added a fancy new --color-moved option

I think that is a typo in this announcement about v2.17.

Magit seems to apply its own diff faces by "washing" the raw diff text (discarding any color escape sequences coming through from git itself)

Yes, that's how it currently works (except we simply ask git not to print any control characters), but I plan to support word-diff and that will require that git's output is manipulated beyond adding text properties and overlays. So this too will probably happen eventually, but it could be a while.

Let me know if there is anything I can do to help here. I have limited time and elisp knowledge, but if this feature can be split into chunks I can take a stab at it, because I'd really love --color-moved to be supported by magit :)

Thanks for all the work :)

For some stupid reason I wanted to see whether or not I could implement --color-moved with just advices, and it seemed to work! It's pretty fragile, of course.

I created a gist which should work with the current Magit.

All --color-moved options are supported with the exception of dimmed-zebra, since it would uglify up the code.

Great! I would be interested to see the non-advice version too! :wink:

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mrkkrp picture mrkkrp  路  5Comments

elemakil picture elemakil  路  3Comments

ipburbank picture ipburbank  路  3Comments

kpurdon picture kpurdon  路  4Comments

xged picture xged  路  5Comments