This is second of three big naming convention changes. In this commit, we change the naming conventions for hook functions and variable functions: 1. Replace the bar | to indicate a hook function with a -h suffix, e.g. doom|init-ui -> doom-init-ui-h doom|run-local-var-hooks -> doom-run-local-var-hooks-h 2. And add a -fn suffix for functions meant to be set on variables, e.g. (setq magit-display-buffer-function #'+magit-display-buffer-fn) See ccf327f8 for the reasoning behind these changes.
89 lines
3.8 KiB
EmacsLisp
89 lines
3.8 KiB
EmacsLisp
;;; 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
|
|
"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.")
|
|
|
|
|
|
;;
|
|
;; Packages
|
|
|
|
(def-package! git-gutter
|
|
:commands (git-gutter:revert-hunk git-gutter:stage-hunk)
|
|
:init
|
|
(add-hook! '(text-mode-hook prog-mode-hook conf-mode-hook)
|
|
(defun +vc-gutter-init-maybe-h ()
|
|
"Enable `git-gutter-mode' in the current buffer.
|
|
|
|
If the buffer doesn't represent an existing file, `git-gutter-mode's activation
|
|
is deferred until the file is saved. Respects `git-gutter:disabled-modes'."
|
|
(when (or +vc-gutter-in-remote-files
|
|
(not (file-remote-p (or buffer-file-name default-directory))))
|
|
(if (not buffer-file-name)
|
|
(add-hook 'after-save-hook #'+vc-gutter-init-maybe-h nil t)
|
|
(when (and (vc-backend buffer-file-name)
|
|
(progn
|
|
(require 'git-gutter)
|
|
(not (memq major-mode git-gutter:disabled-modes))))
|
|
(if (and (display-graphic-p)
|
|
(require 'git-gutter-fringe nil t))
|
|
(progn
|
|
(setq-local git-gutter:init-function #'git-gutter-fr:init)
|
|
(setq-local git-gutter:view-diff-function #'git-gutter-fr:view-diff-infos)
|
|
(setq-local git-gutter:clear-function #'git-gutter-fr:clear)
|
|
(setq-local git-gutter:window-width -1))
|
|
(setq-local git-gutter:init-function 'nil)
|
|
(setq-local git-gutter:view-diff-function #'git-gutter:view-diff-infos)
|
|
(setq-local git-gutter:clear-function #'git-gutter:clear-diff-infos)
|
|
(setq-local git-gutter:window-width 1))
|
|
(git-gutter-mode +1)
|
|
(remove-hook 'after-save-hook #'+vc-gutter-init-maybe-h t))))))
|
|
|
|
;; standardize default fringe width
|
|
(if (fboundp 'fringe-mode) (fringe-mode '4))
|
|
:config
|
|
(set-popup-rule! "^\\*git-gutter" :select nil :size '+popup-shrink-to-fit)
|
|
|
|
;; Update git-gutter on focus (in case I was using git externally)
|
|
(add-hook 'focus-in-hook #'git-gutter:update-all-windows)
|
|
|
|
(add-hook! :append '(doom-escape-hook doom-switch-window-hook)
|
|
(defun +vc-gutter-update-h (&rest _)
|
|
"Refresh git-gutter on ESC. Return nil to prevent shadowing other
|
|
`doom-escape-hook' hooks."
|
|
(when git-gutter-mode
|
|
(ignore (git-gutter)))))
|
|
;; update git-gutter when using magit commands
|
|
(advice-add #'magit-stage-file :after #'+vc-gutter-update-h)
|
|
(advice-add #'magit-unstage-file :after #'+vc-gutter-update-h))
|
|
|
|
|
|
;; subtle diff indicators in the fringe
|
|
(when +vc-gutter-default-style
|
|
(after! git-gutter-fringe
|
|
;; 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]
|
|
nil nil 'bottom)
|
|
;; let diff have left fringe, flycheck can have right fringe
|
|
(after! flycheck
|
|
(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))))
|