mirror of
https://gitlab.com/dwt1/dotfiles.git
synced 2026-04-23 19:40:24 +10:00
Moving to Doom Emacs!
This commit is contained in:
27
.emacs.d/modules/ui/vc-gutter/autoload.el
Normal file
27
.emacs.d/modules/ui/vc-gutter/autoload.el
Normal file
@@ -0,0 +1,27 @@
|
||||
;;; ui/vc-gutter/autoload.el -*- lexical-binding: t; -*-
|
||||
;;;###if (featurep! :ui hydra)
|
||||
|
||||
;;;###autoload (autoload '+vc/gutter-hydra/body "ui/vc-gutter/autoload" nil t)
|
||||
(defhydra +vc/gutter-hydra
|
||||
(:body-pre (git-gutter-mode 1) :hint nil)
|
||||
"
|
||||
[git gutter]
|
||||
Movement Hunk Actions Misc. +%-4s(car (git-gutter:statistic))/ -%-4s(cdr (git-gutter:statistic))
|
||||
╭──────────────────────────────────┴────────────────╯
|
||||
^_g_^ [_s_] stage [_R_] set start Rev
|
||||
^_k_^ [_r_] revert
|
||||
^↑ ^ [_m_] mark
|
||||
^↓ ^ [_p_] popup ╭─────────────────────
|
||||
^_j_^ │[_q_] quit
|
||||
^_G_^ │[_Q_] Quit and disable"
|
||||
("j" (progn (git-gutter:next-hunk 1) (recenter)))
|
||||
("k" (progn (git-gutter:previous-hunk 1) (recenter)))
|
||||
("g" (progn (goto-char (point-min)) (git-gutter:next-hunk 1)))
|
||||
("G" (progn (goto-char (point-min)) (git-gutter:previous-hunk 1)))
|
||||
("s" git-gutter:stage-hunk)
|
||||
("r" git-gutter:revert-hunk)
|
||||
("m" git-gutter:mark-hunk)
|
||||
("p" git-gutter:popup-hunk)
|
||||
("R" git-gutter:set-start-revision)
|
||||
("q" nil :color blue)
|
||||
("Q" (git-gutter-mode -1) :color blue))
|
||||
111
.emacs.d/modules/ui/vc-gutter/config.el
Normal file
111
.emacs.d/modules/ui/vc-gutter/config.el
Normal file
@@ -0,0 +1,111 @@
|
||||
;;; 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
|
||||
|
||||
(use-package! git-gutter
|
||||
:commands git-gutter:revert-hunk git-gutter:stage-hunk
|
||||
:init
|
||||
(add-hook! 'find-file-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 'local)
|
||||
(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 'local))))))
|
||||
|
||||
;; Disable in Org mode, as per
|
||||
;; <https://github.com/syl20bnr/spacemacs/issues/10555> and
|
||||
;; <https://github.com/syohex/emacs-git-gutter/issues/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.
|
||||
(setq git-gutter:disabled-modes '(fundamental-mode image-mode pdf-view-mode))
|
||||
|
||||
;; 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! '(doom-escape-hook doom-switch-window-hook) :append
|
||||
(defun +vc-gutter-update-h (&rest _)
|
||||
"Refresh git-gutter on ESC. Return nil to prevent shadowing other
|
||||
`doom-escape-hook' hooks."
|
||||
(when (and git-gutter-mode
|
||||
(not (memq this-command '(git-gutter:stage-hunk
|
||||
git-gutter:revert-hunk))))
|
||||
(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)
|
||||
|
||||
(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
|
||||
(cl-position-if (let ((lineno (line-number-at-pos)))
|
||||
(lambda (line)
|
||||
(funcall (if is-reverse #'> #'<) lineno line)))
|
||||
diffinfos
|
||||
:key #'git-gutter-hunk-start-line
|
||||
:from-end is-reverse)))
|
||||
|
||||
|
||||
;; 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))))
|
||||
4
.emacs.d/modules/ui/vc-gutter/packages.el
Normal file
4
.emacs.d/modules/ui/vc-gutter/packages.el
Normal file
@@ -0,0 +1,4 @@
|
||||
;; -*- no-byte-compile: t; -*-
|
||||
;;; ui/vc-gutter/packages.el
|
||||
|
||||
(package! git-gutter-fringe)
|
||||
Reference in New Issue
Block a user