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

New file has no highlighting when using diff-hl-flydiff-mode (and make Emacs slow) #226

Open
whhone opened this issue Nov 25, 2024 · 6 comments

Comments

@whhone
Copy link
Contributor

whhone commented Nov 25, 2024

Repro steps

  1. Create a new file in a repo (Git or Hg), open it.
  2. Enable diff-hl-flydiff-mode

Expected
I can see highlights (all green for each line since they are new)

Actual
There is no highlight. Also, it makes Emacs slow.

Causes

  1. diff-hl tries to find the new file from the previous revision (around (diff-hl-create-revision file revision))
  2. Since the file does not exist in the previous revision, it throws an error.
  3. Hence, it does not show the diff highlights.
  4. Also, on every file modification, it repeats calling the expensive call the find the file from a previous revision.
@whhone whhone changed the title New file has no highlighting when using diff-hl-flydiff-mode (and can be laggy) New file has no highlighting when using diff-hl-flydiff-mode (and make Emacs slow) Nov 25, 2024
@dgutov
Copy link
Owner

dgutov commented Nov 28, 2024

Hi! Thanks for the report.

It seems there are a few other conditions needed to reproduce it. First, diff-hl-show-staged-changes needs to be nil. Second, (vc-backend buffer-file-name) needs to return non-nil - that normally doesn't happen in files that aren't registered yet.

So I managed to trigger this once, but don't have a stable scenario yet.

@dgutov
Copy link
Owner

dgutov commented Nov 28, 2024

I've pushed a change that seems logical - please see if the error is gone, and how the performance is now.

@whhone
Copy link
Contributor Author

whhone commented Dec 2, 2024

Thanks for the fix for Git. :) I forgot to mention that I was using Hg, not Git, when seeing the issue.

@dgutov
Copy link
Owner

dgutov commented Dec 3, 2024

Okay, could you clarify the scenario then?

I create a file, enable python-mode, the syntax highlighting works. No diff highlighting though - but no errors either.

We don't get to diff-hl-create-revision because (vc-backend buffer-file-name) returns nil - since the file is not registered yet. As you can see, for example, diff-hl-diff-buffer-with-reference calls vc-ensure-vc-buffer first, and it should error if this point of the execution was reached. At what point does vc-backend return Hg with the newly added file?

@whhone
Copy link
Contributor Author

whhone commented Dec 4, 2024

The scenario is the same as the issue description.

Issue 1: I can see "syntax highlight" but not "diff-hl highlight". See the screenshot below.

Screenshot 2024-12-04 08 31 09

Issue 2: It can make Emacs slow, especially when the VC backend is slow, since it queries the backend for a non-existing file for every edit.

Note that the vc-backend returns Hg when it is in a Mercurial repository.

@dgutov
Copy link
Owner

dgutov commented Dec 5, 2024

Note that the vc-backend returns Hg when it is in a Mercurial repository.

But it returns nil if the file has just been created, doesn't it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants