reddit / emacs
Modern Git-Gutter in Emacs
yep808 · 2022-02-17 19:40
wargxs · 2022-02-17 19:50
Strange, diff-hl works extremely well and looks nice (and also works with other vcs) - some themes have not set appropriate faces but that is very easy to fix. [diff-hl](https://github.com/dgutov/diff-hl)
yep808 · 2022-02-17 20:02
Nothing wrong with diff-hl. It's just that Doom already has the bitmap code for git gutter fringe.
andreyorst · 2022-02-17 20:03
IIRC diff-hl had `diff-hl-flydiff-mode` but in my experience it was very laggy and performance hog. Though my PC wasn't very fast to be fair.
wargxs · 2022-02-17 20:11
Hm… Never experienced any performance problems and this is on an old laptop and a large code base.
emax-gomax · 2022-02-17 23:26
> However, in Emacs there doesn’t seem to be a built-in variable indicating whether a buffer is in a git repository.
There is, it's part of vc-mode and supports both git and subversion. You can query it in a buffer with `(vc-backend buffer-file-name)`.
yep808 · 2022-02-18 00:25
>(vc-backend buffer-file-name)
Thanks! I've edited my post accordingly.
vifon · 2022-02-18 00:46
FYI, you've got an unpaired paren in your third snippet, at its very end. Probably copied over from the last snippet, where this part was inside one more expression.
You may also want to mention using `:ensure t` or a similar option with `use-package` because the way it is, it has no chance of working with the default settings. You probably have `use-package-always-ensure` enabled.
FrozenOnPluto · 2022-02-18 02:13
Big problem I found is.. git-gutter mode seems to work \_terribly\_ with Tramp, at least in my limited experience - since its so broken, I have to immediately disable it, and never experiment too much. I just get reentrant tramp connection errors and then a hung emacs (have to force kill it... odd!)
PErhaps there are some git-gutter-mode elisp hacks to make it properly handle a tramp based git or something..
Anyone tried?
mnp · 2022-02-18 02:38
I needed to bump the timeout to 0.05, maybe fiddle some more. I was getting flicker at 0.02.
yep808 · 2022-02-18 04:08
Thanks, nice catch, I'll update my post.
andreyorst · 2022-02-18 05:24
I wonder why DOOM Emacs replaced diff-hl with git-gutter
jimehgeek · 2022-02-18 10:19
I'd suggest giving it another try. A while back it had a pretty bad performance regression which forced me to pin it to a older version for a few months.
But now a days I find diff-hl's live mode reacting noticeably faster than git-gutter.
jimehgeek · 2022-02-18 10:29
For anyone who might be interested, my diff-hl setup produces a similar style of different colored lines in the fringe. And in a terminal it renders the colored lines using text, like git-gutter also does.
Config: [https://github.com/jimeh/.emacs.d/blob/master/modules/version-control/siren-diff-hl.el](https://github.com/jimeh/.emacs.d/blob/master/modules/version-control/siren-diff-hl.el)
Screenshot: [https://share.jimeh.me/Screen-Shot-2022-02-18-10-26-18.90-CRLzvqbiO1fA.png](https://share.jimeh.me/Screen-Shot-2022-02-18-10-26-18.90-CRLzvqbiO1fA.png)
jimehgeek · 2022-02-18 10:44
I took inspiration from doom-emacs' setup a while back too. I found a easier way to define the fringe bitmaps is to use Emacs' binary notation for decimals, making it easier to customize them.
Basically, instead of this:
(define-fringe-bitmap 'git-gutter-fr:added [224] nil nil '(center repeated))
(define-fringe-bitmap 'git-gutter-fr:modified [224] nil nil '(center repeated))
(define-fringe-bitmap 'git-gutter-fr:deleted [128 192 224 240] nil nil 'bottom)
We can visualize the bitmap's filled pixels with `1`s and `0`s like this:
(define-fringe-bitmap 'git-gutter-fr:added [#b11100000] nil nil '(center repeated))
(define-fringe-bitmap 'git-gutter-fr:modified [#b11100000] nil nil '(center repeated))
(define-fringe-bitmap 'git-gutter-fr:deleted
[#b10000000
#b11000000
#b11100000
#b11110000] nil nil 'bottom)
On the deleted bitmap especially, it's then easy to see that it is drawing a little triangle :)
[deleted] · 2022-02-18 15:07
[deleted]
jamez5800 · 2022-08-07 17:20
I tried to copy this but I still have fat fringes, not the nice thin ones that you have. I'm not sure why
jimehgeek · 2022-08-07 17:27
Ah, damn. I forgot I also have some face overrides in my overrides theme: https://github.com/jimeh/.emacs.d/blob/master/themes/siren-doom-themes-overrides-theme.el
Basically, doom-themes by default set both foreground and background colors to the relevant accent color. My overrides sets the background color to the standard background color.
jamez5800 · 2022-08-08 17:29
That's great! I noticed that the background kept on reverting to the foreground colour, but I didn't know why. Thank you for this! I'm very happy with the result.
Ok-Adhesiveness-89 · 2022-08-20 19:41
Maybe using :ensure t or a similar option with use-package because the way it is, it has no chance of [working](https://www.drhwindowandguttercleaning.co.uk/) with the default settings. You probably have use-package-always-ensure enabled.
mariownyou · 2022-09-27 19:32
My diff hl flick every time I change something. I use flydiff mode