doomemacs/modules/emacs/vc/config.el
2019-12-15 15:53:28 -05:00

74 lines
2.7 KiB
EmacsLisp

;;; emacs/vc/config.el -*- lexical-binding: t; -*-
(when IS-WINDOWS
(setenv "GIT_ASKPASS" "git-gui--askpass"))
(after! vc-annotate
(set-popup-rules!
'(("^\\vc-d" :select nil) ; *vc-diff*
("^\\vc-c" :select t))) ; *vc-change-log*
(set-evil-initial-state!
'(vc-annotate-mode vc-git-log-view-mode)
'normal)
;; Clean up after itself
(define-key vc-annotate-mode-map [remap quit-window] #'kill-current-buffer))
(after! git-timemachine
;; Sometimes I forget `git-timemachine' is enabled in a buffer, so instead of
;; showing revision details in the minibuffer, show them in
;; `header-line-format', which has better visibility.
(setq git-timemachine-show-minibuffer-details t)
(defadvice! +vc-update-header-line-a (revision)
"Show revision details in the header-line, instead of the minibuffer.
Sometimes I forget `git-timemachine' is enabled in a buffer. Putting revision
info in the `header-line-format' is a good indication."
:override #'git-timemachine--show-minibuffer-details
(let* ((date-relative (nth 3 revision))
(date-full (nth 4 revision))
(author (if git-timemachine-show-author (concat (nth 6 revision) ": ") ""))
(sha-or-subject (if (eq git-timemachine-minibuffer-detail 'commit) (car revision) (nth 5 revision))))
(setq header-line-format
(format "%s%s [%s (%s)]"
(propertize author 'face 'git-timemachine-minibuffer-author-face)
(propertize sha-or-subject 'face 'git-timemachine-minibuffer-detail-face)
date-full date-relative))))
(after! evil
;; rehash evil keybindings so they are recognized
(add-hook 'git-timemachine-mode-hook #'evil-normalize-keymaps))
(when (featurep! :tools magit)
(add-transient-hook! #'git-timemachine-blame (require 'magit-blame)))
(map! :map git-timemachine-mode-map
:n "C-p" #'git-timemachine-show-previous-revision
:n "C-n" #'git-timemachine-show-next-revision
:n "gb" #'git-timemachine-blame
:n "gtc" #'git-timemachine-show-commit))
(use-package! git-commit
:after-call after-find-file
:config
(global-git-commit-mode +1)
(set-yas-minor-mode! 'git-commit-mode)
;; Enforce git commit conventions.
;; See https://chris.beams.io/posts/git-commit/
(setq git-commit-summary-max-length 50
git-commit-style-convention-checks '(overlong-summary-line non-empty-second-line))
(setq-hook! 'git-commit-mode-hook fill-column 72)
(add-hook! 'git-commit-setup-hook
(defun +vc-start-in-insert-state-maybe-h ()
"Start git-commit-mode in insert state if in a blank commit message,
otherwise in default state."
(when (and (bound-and-true-p evil-mode)
(bobp) (eolp))
(evil-insert-state)))))