Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Diffs should optionally support syntax highlighting #2942

Open
tarsius opened this issue Jan 9, 2017 · 6 comments
Open

Diffs should optionally support syntax highlighting #2942

tarsius opened this issue Jan 9, 2017 · 6 comments
Labels
area: diff enhancement New feature or request

Comments

@tarsius
Copy link
Member

tarsius commented Jan 9, 2017

After adding this feature, the line-prefix (+, -, or ) continues to be visible and shows whether a given line is an added, removed, or context line. And as before the background color (red/green/gray) continues to be used for the same purpose, but the foreground color.

(When there is a hunk-internal region, then the parts outside of the region currently lose the background color, so that's a first complication to think about.)

Roughtly speaking this feature requires that for each modified file both versions (A..B) have to be visited in a buffer in which font-lock is enabled. After font-lock is done, the text properties are extracted and re-applied in the buffer showing the diff.

This obviously is costly and therefore has to be done asynchronously. For large diffs it is quite possible that the user initially sees a diff with no syntax highlighting and that that only appears after a delay.


This is only one of the many improvements I want to make to diffs and it will be a while until I get to it. It's also not one of the most important improvements, improved performance very clearly has to be the priority. Also the changes that I intend to make in order to achieve better performance are actually prerequisits for this feature. Not only in the sense that we "cannot make diff parsing even slower just to get some additional eye-candy", but also for technical reasons. Asynchronous and selective diff parsing in a separate buffer is a most before the feature proposed here can be implemented.)

@tarsius tarsius added the enhancement New feature or request label Jan 9, 2017
@tarsius
Copy link
Member Author

tarsius commented Jan 9, 2017

This could also be used to highlight whitespace errors. In order to do that whitespace-mode would have to be enabled in the two file-visiting buffers and the text-properties set by that would have to be copied along with the text-properties set by font-lock.

@tarsius tarsius mentioned this issue Feb 13, 2017
12 tasks
@tarsius tarsius added this to the 2.14.0 milestone Mar 29, 2018
@dsvensson
Copy link

How does this relate to the new Emacs 27 diff-font-lock-syntax?

emacs-mirror/emacs@6973b14

@tarsius
Copy link
Member Author

tarsius commented Mar 15, 2019

diff-mode beat magit-diff-mode to it.

@tarsius tarsius removed this from the 2.93.0 milestone Aug 9, 2021
@tarsius
Copy link
Member Author

tarsius commented Oct 4, 2021

I still intend to implement this eventually but since I (also still) plan to give the whole diffing functionality a major overhaul, I will delay doing the former until it becomes part of the latter.

@rirze
Copy link

rirze commented Jan 31, 2022

Is this a feature that could benefit from tree-sitter?

Pardon me if I'm misunderstanding the feature.

@jperras
Copy link

jperras commented Jan 31, 2022

@rirze fwiw you can get diff highlights via magit-delta and something like the following in your config.el:

(use-package! magit-delta
  :after magit
  :config
  (setq
    magit-delta-default-dark-theme "Monokai Extended"
    magit-delta-default-light-theme "Github"
    magit-delta-hide-plus-minus-markers nil)
  (magit-delta-mode))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: diff enhancement New feature or request
Development

No branches or pull requests

4 participants