aboutsummaryrefslogtreecommitdiff
path: root/.config/emacs/lisp/evil-collection/modes/speedbar/evil-collection-speedbar.el
blob: 5abc28b28b51e2d12d50521c765c7f64ac188b44 (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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
;;; evil-collection-speedbar.el --- Evil bindings for speedbar -*- lexical-binding: t -*-

;; Copyright (C) 2020 Zhiwei Chen

;; Author: Zhiwei Chen <condy0919@gmail.com>
;; Maintainer: James Nguyen <james@jojojames.com>
;; Pierre Neidhardt <mail@ambrevar.xyz>
;; URL: https://github.com/emacs-evil/evil-collection
;; Version: 0.0.1
;; Package-Requires: ((emacs "26.3"))
;; Keywords: evil, speedbar, 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:
;; Evil bindings for speedbar.

;;; Code:

(require 'evil-collection)
(require 'speedbar)

(defconst evil-collection-speedbar-maps '(speedbar-mode-map
                                          speedbar-file-key-map
                                          speedbar-buffers-key-map))

(defun evil-collection-speedbar-switch-to-previous-expansion-list ()
  "Back to previously used expansion list."
  (interactive)
  (speedbar-change-initial-expansion-list speedbar-previously-used-expansion-list-name))

(defun evil-collection-speedbar-switch-to-quick-buffers ()
  "Switch to quick-buffers expansion list."
  (interactive)
  (speedbar-change-initial-expansion-list "quick buffers"))

(defun evil-collection-speedbar-switch-to-files ()
  "Switch to files expansion list."
  (interactive)
  (speedbar-change-initial-expansion-list "files"))

;;;###autoload
(defun evil-collection-speedbar-setup ()
  "Set up `evil' bindings for `speedbar'."
  (evil-set-initial-state 'speedbar-mode 'normal)
  (evil-collection-define-key 'normal 'speedbar-mode-map
    "j" 'speedbar-next
    "k" 'speedbar-prev
    "gr" 'speedbar-refresh
    "gg" 'evil-goto-first-line
    "G"  'evil-goto-line

    ;; Basic tree features
    (kbd "RET") 'speedbar-edit-line
    (kbd "TAB") 'speedbar-toggle-line-expansion

    ;; Fold
    "zo" 'speedbar-expand-line
    "zO" 'speedbar-expand-line-descendants
    "zc" 'speedbar-contract-line
    "zC" 'speedbar-contract-line-descendants

    ;; Toggle
    "a" 'speedbar-toggle-show-all-files
    "t" 'speedbar-toggle-updates
    "i" 'speedbar-toggle-images
    "o" 'speedbar-toggle-sorting

    ;; Navigation
    (kbd "M-j") 'speedbar-restricted-next
    (kbd "M-k") 'speedbar-restricted-prev
    "]]" 'speedbar-forward-list
    "[[" 'speedbar-backward-list
    (kbd "C-p") 'evil-collection-speedbar-switch-to-previous-expansion-list
    (kbd "C-n") 'evil-collection-speedbar-switch-to-previous-expansion-list
    "b" 'evil-collection-speedbar-switch-to-quick-buffers
    "f" 'evil-collection-speedbar-switch-to-files
    "J" 'speedbar-change-initial-expansion-list)

  (evil-collection-define-key 'normal 'speedbar-file-key-map
    ;; File based commands
    "B" 'speedbar-item-byte-compile
    "C" 'speedbar-item-copy
    "D" 'speedbar-item-delete
    "I" 'speedbar-item-info
    "K" 'speedbar-item-object-delete
    "L" 'speedbar-item-load
    "R" 'speedbar-item-rename
    "+" 'speedbar-create-directory
    "^" 'speedbar-up-directory
    "-" 'speedbar-up-directory)

  (evil-collection-define-key 'normal 'speedbar-buffers-key-map
    ;; Buffer specific keybindings
    "K" 'speedbar-buffer-kill-buffer
    "gr" 'speedbar-buffer-revert-buffer))

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