From 74372b71ec04f39cbe62244c4c823b4aa7a3d412 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Thu, 27 Apr 2017 15:50:06 -0400 Subject: [PATCH] feature/version-control: show revision info in header-line rather than minibuffer --- modules/feature/version-control/+git.el | 46 ++++++++++++++++++++----- 1 file changed, 38 insertions(+), 8 deletions(-) diff --git a/modules/feature/version-control/+git.el b/modules/feature/version-control/+git.el index 3d33fe6b6..b44001842 100644 --- a/modules/feature/version-control/+git.el +++ b/modules/feature/version-control/+git.el @@ -31,18 +31,48 @@ (def-package! browse-at-remote :commands (browse-at-remote browse-at-remote-get-url)) + (def-package! git-timemachine :commands (git-timemachine git-timemachine-toggle) :config - (add-hook! 'git-timemachine-mode-hook #'evil-force-normal-state) + ;; 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 is always visible. + (setq git-timemachine-show-minibuffer-details nil) + + (defun +vcs|toggle-header-line () + (if git-timemachine-mode + (+vcs*update-header-line) + (setq-local header-line-format nil))) + + (defun +vcs*update-header-line (&rest _) + (when (and git-timemachine-mode git-timemachine-revision) + (let* ((revision git-timemachine-revision) + (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-local + 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))))) + + (add-hook 'git-timemachine-mode-hook #'+vcs|toggle-header-line) + (advice-add #'git-timemachine-show-revision :after #'+vcs*update-header-line) + + ;; Force evil to rehash keybindings for the current state + (add-hook 'git-timemachine-mode-hook #'evil-force-normal-state) (map! :map git-timemachine-mode-map - :nv "p" 'git-timemachine-show-previous-revision - :nv "n" 'git-timemachine-show-next-revision - :nv "g" 'git-timemachine-show-nth-revision - :nv "q" 'git-timemachine-quit - :nv "w" 'git-timemachine-kill-abbreviated-revision - :nv "W" 'git-timemachine-kill-revision - :nv "b" 'git-timemachine-blame)) + :nv "p" #'git-timemachine-show-previous-revision + :nv "n" #'git-timemachine-show-next-revision + :nv "g" #'git-timemachine-show-nth-revision + :nv "q" #'git-timemachine-quit + :nv "w" #'git-timemachine-kill-abbreviated-revision + :nv "W" #'git-timemachine-kill-revision + :nv "b" #'git-timemachine-blame)) + (def-package! magit :commands magit-status