dgutov / diff-hl

Emacs package for highlighting uncommitted changes
GNU General Public License v3.0
914 stars 44 forks source link

Added option to not enable diff-hl in certain major-modes #143

Closed walseb closed 4 years ago

walseb commented 4 years ago

Currently global-diff-hl-mode makes diff-hl run in every buffer regardless of major-mode. This becomes a problem in image-mode buffers under git control in emacs 27 built without imagemagick support (which is the default currently), where files ~5 mb starts taking minutes to load instead of seconds. I haven't checked to see if this also a problem when using imagemagick to render images, but it probably is.

dgutov commented 4 years ago

Hi!

Perhaps we could model this after font-lock-global-modes? With the special meaning for the not symbol.

Another example: company-global-modes.

Using '(not image-mode) as the default sounds fine to me.

walseb commented 4 years ago

Thanks for the suggestion! I finally got around to doing this. I just copied the mechanism directly from font-lock and it seems to work fine

walseb commented 4 years ago

As a side note, when a image is opened it's read in fundamental-mode before switching to image-mode. This causes diff-hl to be run on the image data which takes a while depending on image size. This is also a problem for a lot of other minor modes and the only solution besides fixing it upstream seems to be to make them ignore fundamental-mode, which can be a problem if you edit a lot of files in fundamental-mode. So while this new option decreases the loading time of images, the global mode still slows it down a bit, at least in my testing. Nevermind, I was going to report this upstream but now I can't replicate it. I must have done something wrong in the earlier tests

dgutov commented 4 years ago

Nevermind, I was going to report this upstream but now I can't replicate it. I must have done something wrong in the earlier tests

I'm guessing this might have been a difference between just visiting a file for the first time and M-x image-mode in an existing buffer. But I'm not sure.

walseb commented 4 years ago

Do you think it would also be ok to add minibuffer-inactive-mode to the default ignore list? Is there any use case where you would want diff-hl in the minibuffer? I haven't observed any downsides to running it in the minibuffer however, so maybe this isn't worth doing

dgutov commented 4 years ago

Do you think it would also be ok to add minibuffer-inactive-mode to the default ignore list?

No need. buffer-file-name is nil in minibuffer.

walseb commented 4 years ago

I have now merged all the commits and fixed all the problems I think

dgutov commented 4 years ago

Looks good. I'll edit it a bit later to make it shorter.

Thanks!