summaryrefslogtreecommitdiff
path: root/lisp/init-projectile.el
blob: b5004a1a9bcabb387570e58138257283405ac6de (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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
(require-package 'projectile)

(projectile-global-mode)

(setq projectile-switch-project-action 'projectile-commander
      projectile-find-dir-includes-top-level t
      projectile-use-git-grep t)

(defun km/projectile-switch-project-to-file ()
  "Provide access to the of default `projectile-find-file'.

I have set `projectile-switch-project-action' to
`projectile-commander' but would still like quick access to
`projectile-find-file'."
  (interactive)
  (let ((projectile-switch-project-action 'projectile-find-file))
    (projectile-switch-project)))

(defun km/projectile-open-external-terminal-in-root ()
  "Run `km/open-external-terminal' in project root."
  (interactive)
  (let ((default-directory (projectile-project-root)))
    (km/open-external-terminal)))

(defun km/projectile-view-file ()
  "View project file.
Interactive arguments are processed according to
`projectile-find-file'."
  (interactive)
  (call-interactively 'projectile-find-file)
  (view-mode 1))

(defun km/projectile-view-file-other-window ()
  "View project file in other window.
Interactive arguments are processed according to
`projectile-find-file-other-window'."
  (interactive)
  (call-interactively 'projectile-find-file-other-window)
  (view-mode 1))

(defun km/project-filename-at-point ()
  "Return file name relative to `projectile-project-root'."
  (file-relative-name (thing-at-point 'filename)
                      (projectile-project-root)))

(defun km/projectile-copy-project-filename-as-kill ()
  (interactive)
  (let ((fname (km/project-filename-at-point)))
    (if (eq last-command 'kill-region)
        (kill-append fname nil)
      (kill-new fname))
    (message "%s" fname)))

;; Default binding is D.
(def-projectile-commander-method ?r
  "Open project root in dired."
  (projectile-dired))

(def-projectile-commander-method ?D
  "Find a project directory in other window."
  (call-interactively 'projectile-find-dir-other-window))

;; Default binding is v.
(def-projectile-commander-method ?m
  "Open project root in vc-dir or magit."
  (projectile-vc))

(def-projectile-commander-method ?v
  "View project file."
  (km/projectile-view-file))

(def-projectile-commander-method ?V
  "View project file in other window."
  (km/projectile-view-file-other-window))

(def-projectile-commander-method ?c
  "Run project compilation command."
  (call-interactively 'projectile-compile-project))

(def-projectile-commander-method ?F
  "Find project file in other window."
  (call-interactively 'projectile-find-file-other-window))

(def-projectile-commander-method ?B
  "Find project buffer in other window."
  (call-interactively 'projectile-switch-to-buffer-other-window))

(def-projectile-commander-method ?O
  "Display a project buffer in other window."
  (call-interactively 'projectile-display-buffer))

(key-chord-define-global ";s" 'projectile-switch-project)
(key-chord-define-global ";f" 'projectile-find-file)
(key-chord-define-global ";v" 'km/projectile-view-file)
(key-chord-define-global ";d" 'projectile-find-dir)
(key-chord-define-global ";t" 'km/projectile-open-external-terminal-in-root)
(key-chord-define-global ";g" 'projectile-grep)
(key-chord-define-global ";w" 'projectile-multi-occur)
(key-chord-define-global ";r" 'projectile-recentf)
(key-chord-define-global ";c" 'projectile-commander)

(define-key projectile-command-map "j"
  'km/projectile-switch-project-to-file)
(define-key projectile-command-map "."
  'km/projectile-copy-project-filename-as-kill)

(define-key projectile-command-map (kbd "4 v")
  'km/projectile-view-file-other-window)

(define-prefix-command 'km/projectile-ctl-x-4-map)
(define-key ctl-x-4-map "p" 'km/projectile-ctl-x-4-map)

(define-key km/projectile-ctl-x-4-map (kbd "C-o")
  'projectile-display-buffer)
(define-key km/projectile-ctl-x-4-map "b"
  'projectile-switch-to-buffer-other-window)
(define-key km/projectile-ctl-x-4-map "d"
  'projectile-find-dir-other-window)
(define-key km/projectile-ctl-x-4-map "f"
  'projectile-find-file-other-window)
(define-key km/projectile-ctl-x-4-map "v"
  'km/projectile-view-file-other-window)
(define-key km/projectile-ctl-x-4-map "t"
  'projectile-find-implementation-or-test-other-window)

(provide 'init-projectile)