aboutsummaryrefslogtreecommitdiff
path: root/.config/emacs/lisp/evil-collection/modes/magit-section/evil-collection-magit-section.el
blob: 23103935b06aa05257922d747d84364206817e18 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
;;; evil-collection-magit-section.el --- Bindings for magit-section -*- lexical-binding: t -*-

;; Copyright (C) 2022 James Nguyen

;; Author: James Nguyen <james@jojojames.com>
;; Maintainer: James Nguyen <james@jojojames.com>
;; URL: https://github.com/emacs-evil/evil-collection
;; Version: 0.0.2
;; Package-Requires: ((emacs "27.1"))
;; Keywords: evil, emacs, convenience, tools

;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with this program.  If not, see <http://www.gnu.org/licenses/>.

;;; Commentary:
;;; Bindings for magit-section.

;;; Code:
(require 'evil-collection)
(require 'magit-section nil t)

(defvar magit-section-mode-map)
(defconst evil-collection-magit-section-maps '(magit-section-mode-map))

(defcustom evil-collection-magit-section-use-z-for-folds nil
  "When non nil, use \"z\" as a prefix for common vim fold commands, such as
  - z1 Reset visibility to level 1 for all sections
  - z2 Reset visibility to level 2 for all sections
  - z3 Reset visibility to level 3 for all sections
  - z4 Reset visibility to level 4 for all sections
  - za Toggle a section
  - zo Show section
  - zO Show sections recursively
  - zc Hide section
  - zC Hide sections recursively
  - zr Same as z4.

When this option is enabled, the stash popup is available on \"Z\"."
  :group 'magit
  :type  'boolean)

(defun evil-collection-magit-section-setup ()
  "Set up `evil' bindings for magit-section."
  (if evil-collection-magit-section-use-z-for-folds
      (evil-collection-define-key 'normal 'magit-section-mode-map
        "z1" 'magit-section-show-level-1-all
        "z2" 'magit-section-show-level-2-all
        "z3" 'magit-section-show-level-3-all
        "z4" 'magit-section-show-level-4-all
        "za" 'magit-section-toggle
        "zc" 'magit-section-hide
        "zC" 'magit-section-hide-children
        "zo" 'magit-section-show
        "zO" 'magit-section-show-children
        "zr" 'magit-section-show-level-4-all)
    (evil-collection-define-key 'normal 'magit-section-mode-map
      (kbd "M-1") 'magit-section-show-level-1-all
      (kbd "M-2") 'magit-section-show-level-2-all
      (kbd "M-3") 'magit-section-show-level-3-all
      (kbd "M-4") 'magit-section-show-level-4-all))

  (evil-collection-define-key 'normal 'magit-section-mode-map
    (kbd "TAB") 'magit-section-toggle
    [C-tab]     'magit-section-cycle
    [M-tab]     'magit-section-cycle
    ;; [backtab] is the most portable binding for Shift+Tab.
    [backtab]   'magit-section-cycle-global
    "gh" 'magit-section-up
    (kbd "C-k") 'magit-section-backward
    (kbd "C-j") 'magit-section-forward
    "gk" 'magit-section-backward-sibling
    "[" 'magit-section-backward-sibling
    "gj" 'magit-section-forward-sibling
    "]" 'magit-section-forward-sibling
    (kbd "1") 'magit-section-show-level-1
    (kbd "2") 'magit-section-show-level-2
    (kbd "3") 'magit-section-show-level-3
    (kbd "4") 'magit-section-show-level-4))

(provide 'evil-collection-magit-section)
;;; evil-collection-magit-section.el ends here