Support git-timemachine

Supports evil bindings for git-timemachine. On my machine, git-timemachine
starts with evil in normal mode, which is problematic when trying to access the
keybindings "n" and "p", which navigate to the next and previous revisions.
Additionally, normal mode eclispses "q", which exits the mode.

I tried using `(evil-set-initial-state 'git-timemachine-mode 'motion)`, but that
didn't work. I assume this is because `git-timemachine` is a minor-mode. To work
around this, I used `add-hook` to ensure motion mode was the initial state.

Once motion mode is the initial state, "p" and "q" become available.
Unfortunately, "n" is still not. To get around this, I used a buffer-local
binding in the local motion state map to map "n" appropriately. One known
shortcoming of this approach is that there is no cleanup done after exiting the
mode.

Any suggestions are eagerly welcomed. Forgive any crude techniques that I used
to get this functioning. I just wanted to broach the discussion with some of the
other maintainers to get some insights and hopefully augment my implementation
as needed.
This commit is contained in:
William Carroll 2018-03-31 13:13:43 -04:00 committed by James N
parent aca031a7f3
commit 9298988cc4
1 changed files with 22 additions and 0 deletions

View File

@ -0,0 +1,22 @@
;;; evil-collection-git-timemachine.el --- Bindings for `git-timemachine' -*- lexical-binding: t -*-
;; Author: William Carroll <wpcarro@gmail.com>
;;; Commentary:
;; Evil keybindings for `git-timemachine' that conform to the principles outlines in evil-collection
;;; Code:
(require 'evil)
(require 'git-timemachine)
(defun ecgt--setup-bindings ()
"Setup `git-timemachine' since `evil-set-initial-state' is unavailable to
minor modes."
(evil-motion-state nil)
(evil-local-set-key 'motion "n" #'git-timemachine-show-next-revision))
(defun evil-collection-git-timemachine-setup ()
"Setup `evil' keybindings for `git-timemachine'."
(add-hook 'git-timemachine-mode-hook #'ecgt--setup-bindings))
(provide 'evil-collection-git-timemachine)
;;; evil-collection-git-timemachine.el ends here