about summary refs log tree commit diff
path: root/configs/shared/emacs/.emacs.d/elpa/evil-collection-20180720.526/evil-collection-ggtags.el
blob: c9dd8cc02806afd7a0d3ad317913638b741a61a4 (plain) (blame)
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
;;; evil-collection-ggtags.el --- Evil bindings for ggtags -*- lexical-binding: t -*-

;; Copyright (C) 2017 James Nguyen

;; Author: James Nguyen <james@jojojames.com>
;; Maintainer: James Nguyen <james@jojojames.com>
;; Pierre Neidhardt <ambrevar@gmail.com>
;; URL: https://github.com/emacs-evil/evil-collection
;; Version: 0.0.1
;; Package-Requires: ((emacs "25.1"))
;; Keywords: evil, ggtags, 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 `ggtags-mode'.

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

(defvar ggtags-global-mode-map)
(defvar ggtags-mode-map)
(defvar ggtags-view-search-history-mode-map)
(defvar ggtags-view-tag-history-mode-map)
(defvar ggtags-navigation-map)

(defconst evil-collection-ggtags-maps '(ggtags-mode-map
                                        ggtags-view-search-history-mode-map
                                        ggtags-view-tag-history-mode-map
                                        ggtags-navigation-map))

(defun evil-collection-ggtags-setup ()
  "Set up `evil' bindings for `ggtags'."
  (evil-set-initial-state 'ggtags-global-mode 'normal)
  (evil-set-initial-state 'ggtags-view-search-history-mode 'normal)
  (evil-set-initial-state 'ggtags-view-tag-history-mode 'normal)

  ;; `ggtags-navigation-mode' is global and will conflict with other bindings.
  ;; https://github.com/leoliu/ggtags/issues/124
  (when (boundp 'ggtags-enable-navigation-keys)
    (setq ggtags-enable-navigation-keys nil))

  (evil-collection-define-key 'normal 'ggtags-mode-map
    "gd" 'ggtags-find-tag-dwim
    (kbd "C-t") 'ggtags-prev-mark
    "gf" 'ggtags-find-file)

  (evil-collection-define-key 'normal 'ggtags-view-search-history-mode-map
    "gj" 'ggtags-view-search-history-next
    "gk" 'ggtags-view-search-history-prev
    (kbd "C-j") 'ggtags-view-search-history-next
    (kbd "C-k") 'ggtags-view-search-history-prev
    "]" 'ggtags-view-search-history-next
    "[" 'ggtags-view-search-history-prev
    "x" 'ggtags-view-search-history-kill
    "gr" 'ggtags-view-search-history-update
    "r" 'ggtags-save-to-register
    "R" 'ggtags-view-search-history-action
    "q" 'ggtags-kill-window)

  (evil-collection-define-key 'normal 'ggtags-view-tag-history-mode-map
    "gj" 'next-error-no-select
    (kbd "C-j") 'next-error-no-select
    "]" 'next-error-no-select
    "gk" 'previous-error-no-select
    (kbd "C-k") 'previous-error-no-select
    (kbd "[") 'previous-error-no-select
    "q" 'ggtags-kill-window)

  (evil-collection-define-key 'normal 'ggtags-navigation-map
    ;; navigation
    "gj" 'next-error
    "gk" 'next-error
    (kbd "C-j") 'previous-error
    (kbd "C-k") 'previous-error
    "]" 'ggtags-navigation-next-file
    "[" 'ggtags-navigation-previous-file

    ;; search
    "s" 'ggtags-navigation-isearch-forward
    "S" 'ggtags-navigation-isearch-forward

    "go" 'ggtags-navigation-visible-mode ;; FIXME: This can be anything.
    (kbd "<return>") 'ggtags-navigation-mode-done))

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