2018-06-21 21:14:00 +02:00
|
|
|
;;; ui/vc-gutter/config.el -*- lexical-binding: t; -*-
|
|
|
|
|
|
|
|
(defvar +vc-gutter-in-margin nil
|
|
|
|
"If non-nil, use the margin for diffs instead of the fringe.")
|
|
|
|
|
|
|
|
(defvar +vc-gutter-in-remote-files nil
|
|
|
|
"If non-nil, enable the vc gutter in remote files (e.g. open through TRAMP).")
|
|
|
|
|
|
|
|
(defvar +vc-gutter-diff-unsaved-buffer nil
|
|
|
|
"If non-nil, `diff-hl-flydiff-mode' will be activated. This allows on-the-fly
|
|
|
|
diffing, even for unsaved buffers.")
|
|
|
|
|
|
|
|
(defvar +vc-gutter-default-style t
|
2020-02-23 15:41:49 -05:00
|
|
|
"If non-nil, enable the default look of the vc gutter.
|
|
|
|
This means subtle thin bitmaps on the left, an arrow bitmap for flycheck, and
|
|
|
|
flycheck indicators moved to the right fringe.")
|
2018-06-21 21:14:00 +02:00
|
|
|
|
|
|
|
|
|
|
|
;;
|
2020-05-25 02:20:26 -04:00
|
|
|
;;; Packages
|
2018-06-21 21:14:00 +02:00
|
|
|
|
2019-07-23 12:44:03 +02:00
|
|
|
(use-package! git-gutter
|
2019-07-22 19:11:12 +02:00
|
|
|
:commands git-gutter:revert-hunk git-gutter:stage-hunk
|
2018-06-21 21:14:00 +02:00
|
|
|
:init
|
2019-07-26 19:57:13 +02:00
|
|
|
(add-hook! 'find-file-hook
|
2019-07-18 15:27:20 +02:00
|
|
|
(defun +vc-gutter-init-maybe-h ()
|
|
|
|
"Enable `git-gutter-mode' in the current buffer.
|
2019-05-06 02:14:14 -04:00
|
|
|
If the buffer doesn't represent an existing file, `git-gutter-mode's activation
|
2019-06-14 11:08:59 +02:00
|
|
|
is deferred until the file is saved. Respects `git-gutter:disabled-modes'."
|
2020-02-25 12:49:52 -05:00
|
|
|
(let ((file-name (buffer-file-name (buffer-base-buffer))))
|
2021-02-26 21:25:16 -05:00
|
|
|
(cond
|
|
|
|
((and (file-remote-p (or file-name default-directory))
|
|
|
|
(not +vc-gutter-in-remote-files)))
|
|
|
|
;; If not a valid file, wait until it is written/saved to activate
|
|
|
|
;; git-gutter.
|
|
|
|
((not (and file-name (vc-backend file-name)))
|
|
|
|
(add-hook 'after-save-hook #'+vc-gutter-init-maybe-h nil 'local))
|
|
|
|
;; Allow git-gutter or git-gutter-fringe to activate based on the type
|
|
|
|
;; of frame we're in. This allows git-gutter to work for silly geese
|
|
|
|
;; who open both tty and gui frames from the daemon.
|
|
|
|
((if (and (display-graphic-p)
|
|
|
|
(require 'git-gutter-fringe nil t))
|
|
|
|
(setq-local git-gutter:init-function #'git-gutter-fr:init
|
|
|
|
git-gutter:view-diff-function #'git-gutter-fr:view-diff-infos
|
|
|
|
git-gutter:clear-function #'git-gutter-fr:clear
|
|
|
|
git-gutter:window-width -1)
|
|
|
|
(setq-local git-gutter:init-function 'nil
|
|
|
|
git-gutter:view-diff-function #'git-gutter:view-diff-infos
|
|
|
|
git-gutter:clear-function #'git-gutter:clear-diff-infos
|
|
|
|
git-gutter:window-width 1))
|
2021-03-18 01:05:39 -04:00
|
|
|
(unless (memq major-mode git-gutter:disabled-modes)
|
|
|
|
(git-gutter-mode +1)
|
|
|
|
(remove-hook 'after-save-hook #'+vc-gutter-init-maybe-h 'local)))))))
|
2019-07-18 15:27:20 +02:00
|
|
|
|
2020-04-16 21:55:59 -04:00
|
|
|
;; Disable in Org mode, as per syl20bnr/spacemacs#10555 and
|
|
|
|
;; syohex/emacs-git-gutter#24. Apparently, the mode-enabling function for
|
|
|
|
;; global minor modes gets called for new buffers while they are still in
|
|
|
|
;; `fundamental-mode', before a major mode has been assigned. I don't know why
|
|
|
|
;; this is the case, but adding `fundamental-mode' here fixes the issue.
|
2019-07-23 20:43:35 +02:00
|
|
|
(setq git-gutter:disabled-modes '(fundamental-mode image-mode pdf-view-mode))
|
2018-06-21 21:14:00 +02:00
|
|
|
:config
|
2020-04-16 21:55:59 -04:00
|
|
|
(set-popup-rule! "^\\*git-gutter" :select nil :size '+popup-shrink-to-fit)
|
|
|
|
|
2020-03-01 01:36:16 -05:00
|
|
|
;; Only enable the backends that are available, so it doesn't have to check
|
|
|
|
;; when opening each buffer.
|
2020-04-16 21:55:59 -04:00
|
|
|
(setq git-gutter:handled-backends
|
|
|
|
(cons 'git (cl-remove-if-not #'executable-find (list 'hg 'svn 'bzr)
|
|
|
|
:key #'symbol-name)))
|
2018-06-21 21:14:00 +02:00
|
|
|
|
|
|
|
;; Update git-gutter on focus (in case I was using git externally)
|
|
|
|
(add-hook 'focus-in-hook #'git-gutter:update-all-windows)
|
|
|
|
|
2019-07-26 19:57:13 +02:00
|
|
|
(add-hook! '(doom-escape-hook doom-switch-window-hook) :append
|
2019-07-18 15:27:20 +02:00
|
|
|
(defun +vc-gutter-update-h (&rest _)
|
|
|
|
"Refresh git-gutter on ESC. Return nil to prevent shadowing other
|
2018-06-21 21:14:00 +02:00
|
|
|
`doom-escape-hook' hooks."
|
2021-03-05 20:07:26 -05:00
|
|
|
(ignore (or (memq this-command '(git-gutter:stage-hunk
|
2021-02-26 21:25:16 -05:00
|
|
|
git-gutter:revert-hunk))
|
2021-03-05 20:07:26 -05:00
|
|
|
inhibit-redisplay
|
|
|
|
(if git-gutter-mode
|
|
|
|
(git-gutter)
|
|
|
|
(+vc-gutter-init-maybe-h))))))
|
2018-07-12 18:47:36 +02:00
|
|
|
;; update git-gutter when using magit commands
|
2019-07-18 15:27:20 +02:00
|
|
|
(advice-add #'magit-stage-file :after #'+vc-gutter-update-h)
|
2019-09-27 15:15:30 -04:00
|
|
|
(advice-add #'magit-unstage-file :after #'+vc-gutter-update-h)
|
|
|
|
|
|
|
|
(defadvice! +vc-gutter--fix-linearity-of-hunks-a (diffinfos is-reverse)
|
|
|
|
"Fixes `git-gutter:next-hunk' and `git-gutter:previous-hunk' sometimes
|
|
|
|
jumping to random hunks."
|
|
|
|
:override #'git-gutter:search-near-diff-index
|
2021-03-05 20:07:26 -05:00
|
|
|
(cl-position-if (let ((lineno (line-number-at-pos))
|
|
|
|
(fn (if is-reverse #'> #'<)))
|
|
|
|
(lambda (line) (funcall fn lineno line)))
|
2019-09-27 15:15:30 -04:00
|
|
|
diffinfos
|
|
|
|
:key #'git-gutter-hunk-start-line
|
|
|
|
:from-end is-reverse)))
|
2018-06-21 21:14:00 +02:00
|
|
|
|
2018-10-03 19:01:06 -04:00
|
|
|
|
|
|
|
;; subtle diff indicators in the fringe
|
2020-02-27 14:52:53 -05:00
|
|
|
(after! git-gutter-fringe
|
|
|
|
(when +vc-gutter-default-style
|
|
|
|
;; standardize default fringe width
|
|
|
|
(if (fboundp 'fringe-mode) (fringe-mode '4))
|
2020-02-23 15:41:49 -05:00
|
|
|
|
2018-06-21 21:14:00 +02:00
|
|
|
;; places the git gutter outside the margins.
|
|
|
|
(setq-default fringes-outside-margins t)
|
|
|
|
;; thin fringe bitmaps
|
|
|
|
(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]
|
2020-02-27 14:52:53 -05:00
|
|
|
nil nil 'bottom)))
|
|
|
|
|
|
|
|
(after! flycheck
|
|
|
|
(when +vc-gutter-default-style
|
2018-06-21 21:14:00 +02:00
|
|
|
;; let diff have left fringe, flycheck can have right fringe
|
2020-02-25 12:45:30 -05:00
|
|
|
(setq flycheck-indication-mode 'right-fringe)
|
|
|
|
;; A non-descript, left-pointing arrow
|
|
|
|
(define-fringe-bitmap 'flycheck-fringe-bitmap-double-arrow
|
|
|
|
[16 48 112 240 112 48 16] nil nil 'center)))
|