refactor(vc-gutter): simplify & DRY

These advice were unnecessary when not only does diff-hl expose
variables to change them, but one of the overridden definitions is
identical to the function it's replacing.

Also includes some other minor refactors.
This commit is contained in:
Henrik Lissner 2024-07-10 03:19:19 -04:00
parent 78304f4d79
commit f1f72c291a
No known key found for this signature in database
GPG key ID: B60957CA074D39A3

View file

@ -32,17 +32,15 @@
(make-string (- w half-w) ?0)))
2))
nil nil 'center)))
(defun +vc-gutter-type-face-fn (type _pos)
(intern (format "diff-hl-%s" type)))
(defun +vc-gutter-type-at-pos-fn (type _pos)
(if (eq type 'delete)
'diff-hl-bmp-delete
'diff-hl-bmp-middle))
(advice-add #'diff-hl-fringe-bmp-from-pos :override #'+vc-gutter-type-at-pos-fn)
(advice-add #'diff-hl-fringe-bmp-from-type :override #'+vc-gutter-type-at-pos-fn)
(setq diff-hl-fringe-bmp-function #'+vc-gutter-type-at-pos-fn)
(setq diff-hl-draw-borders nil)
(add-hook! 'diff-hl-mode-hook
(defun +vc-gutter-fix-diff-hl-faces-h ()
(defun +vc-gutter-make-diff-hl-faces-transparent-h ()
(mapc (doom-rpartial #'set-face-background nil)
'(diff-hl-insert
diff-hl-delete
@ -122,9 +120,9 @@
(when (modulep! :editor evil)
(add-hook! 'diff-hl-flydiff-mode-hook
(defun +vc-gutter-init-flydiff-mode-h ()
(if (not diff-hl-flydiff-mode)
(remove-hook 'evil-insert-state-exit-hook #'diff-hl-flydiff-update)
(add-hook 'evil-insert-state-exit-hook #'diff-hl-flydiff-update)))))
(if diff-hl-flydiff-mode
(add-hook 'evil-insert-state-exit-hook #'diff-hl-flydiff-update)
(remove-hook 'evil-insert-state-exit-hook #'diff-hl-flydiff-update)))))
;; FIX: Reverting a hunk causes the cursor to be moved to an unexpected place,
;; often far from the target hunk.