-
Notifications
You must be signed in to change notification settings - Fork 3
/
idee-actions.el
270 lines (225 loc) · 7.15 KB
/
idee-actions.el
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
;; idee-actions.el --- IDE actions -*- lexical-binding: t -*-
;; Copyright (C) 2018 Ioannis Canellos
;; Licensed under the Apache License, Version 2.0 (the "License");
;; you may not use this file except in compliance with the License.
;; You may obtain a copy of the License at
;; http://www.apache.org/licenses/LICENSE-2.0
;;Unless required by applicable law or agreed to in writing, software
;;distributed under the License is distributed on an "AS IS" BASIS,
;;WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
;;See the License for the specific language governing permissions and
;;limitations under the License.
;; Author: Ioannis Canellos
;;; Commentary:
;;; Code:
(require 'idee-vars)
(require 'idee-navigation)
;;
;; Optional
;;
(require 'helm-ag nil t)
(require 'cc-vars nil t)
(require 'evil-vars nil t)
;;
;;Project
;;;###autoload
(defun idee/open()
"Open project."
(interactive)
(idee/back-push)
(funcall (alist-get 'idee/open-function idee/function-alist)))
;;;###autoload
(defun idee/new-project()
"Create a new file."
(interactive)
(idee/back-push)
(funcall (alist-get 'idee/new-project-function idee/function-alist)))
;;;###autoload
(defun idee/new-file()
"Create a new file."
(interactive)
(idee/back-push)
(funcall (alist-get 'idee/new-file-function idee/function-alist)))
;;;###autoload
(defun idee/recent()
"Recent project."
(interactive)
(idee/back-push)
(funcall (alist-get 'idee/recent-function idee/function-alist)))
;;;###autoload
(defun idee/save-all()
"Save all project buffers."
(interactive)
(funcall (alist-get 'idee/save-all-function idee/function-alist)))
;;;###autoload
(defun idee/close()
"Close project."
(interactive)
(delete-other-windows-internal)
(funcall (alist-get 'idee/close-function idee/function-alist)))
;;;###autoload
(defun idee/build()
"Build."
(interactive)
(funcall (alist-get 'idee/build-function idee/function-alist)))
;;;###autoload
(defun idee/vcs()
"Version Control."
(interactive)
(funcall (alist-get 'idee/vcs-function idee/function-alist)))
;;Source
;;;###autoload
(defun idee/optimize-imports()
"Optimize Imports."
(interactive)
(funcall (alist-get 'idee/optimize-imports-function idee/function-alist)))
;;;###autoload
(defun idee/indent()
"Indent."
(interactive)
(funcall (alist-get 'idee/indent-function idee/function-alist)))
;;;###autoload
(defun idee/indent-region()
"Indent Region."
(interactive)
(funcall (alist-get 'idee/indent-region-function idee/function-alist)))
;;;###autoload
(defun idee/header-select()
"Select header for project files."
(interactive)
(funcall (alist-get 'idee/header-select-function idee/function-alist)))
(defun idee/apply-code-actions()
"Select header for project files."
(interactive)
(funcall (alist-get 'idee/apply-code-actions-function idee/function-alist)))
;;Navigate
;;;###autoload
(defun idee/references()
"Find references."
(interactive)
(idee/back-push)
(funcall (alist-get 'idee/references-function idee/function-alist)))
;;;###autoload
(defun idee/implementation()
"Find implementations."
(interactive)
(idee/back-push)
(funcall (alist-get 'idee/implementation-function idee/function-alist)))
;;;###autoload
(defun idee/declaration()
"Jump to declaration."
(interactive)
(idee/back-push)
(funcall (alist-get 'idee/declaration-function idee/function-alist)))
;;;###autoload
(defun idee/back()
"Jump back."
(interactive)
(funcall (alist-get 'idee/back-function idee/function-alist)))
;;Search
;;;###autoload
(defun idee/grep()
"Grep."
(interactive)
(funcall (alist-get 'idee/grep-function idee/function-alist)))
;;;###autoload
(defun idee/find-file()
"Find file."
(interactive)
(idee/back-push)
(funcall (alist-get 'idee/find-file-function idee/function-alist)))
;;;###autoload
(defun idee/find-variable()
"Find variable."
(interactive)
(idee/back-push)
(funcall (alist-get 'idee/find-variable-function idee/function-alist)))
;;Task
;;;###autoload
(defun idee/run-or-eval ()
"Run the project."
(interactive)
(funcall (alist-get 'idee/run-or-eval-function idee/function-alist)))
;;;###autoload
(defun idee/test()
"Run test."
(interactive)
(funcall (alist-get 'idee/test-function idee/function-alist)))
;;Layout
;;;###autoload
(defun idee/repl ()
"Run a REPL."
(interactive)
(let ((repl-funcition (alist-get 'idee/repl-function idee/function-alist)))
(if repl-funcition (funcall repl-funcition)
(message "No repl available for mode."))))
;;;###autoload
(defun idee/mode-hydra ()
"Open the mode specific hydra."
(interactive)
(funcall (alist-get 'idee/mode-hydra-function idee/function-alist)))
;; Toggles
;;;###autoload
(defun idee/toggle-tab-width ()
"Toggle between 2 and 4 space indentation."
(interactive)
(if (equal 4 idee/tab-width)
(setq idee/tab-width 2)
(setq idee/tab-width 4))
(setq tab-width idee/tab-width)
(idee/set-tab-width))
;;;###autoload
(defun idee/set-tab-width ()
"Set the tab width."
(let ((f (alist-get 'idee/mode-tab-width-function idee/function-alist)))
(if f
(funcall f idee/tab-width)
(idee/global-set-tab-width-function idee/tab-width))))
;;;###autoload
(defun idee/global-set-tab-width-function (width)
"Set the tab WIDTH."
(when (and (require 'cc-vars nil t) (require 'evil-vars nil t))
(setq standard-indent width
tab-width width
evil-shift-width width
c-basic-offset width)))
;;;###autoload
(defun idee/toggle-use-tabs ()
"Toggle between tabs and spaces."
(interactive)
(when (require 'evil-vars nil t)
(if idee/use-tabs
(setq evil-indent-convert-tabs t)
(setq evil-indent-convert-tabs nil)))
(if idee/use-tabs (setq idee/use-tabs nil) (setq idee/use-tabs t))
(setq indent-tabs-mode idee/use-tabs)
(if idee/use-tabs
(message "Use tabs: enabled.")
(message "Use tabs: disabled.")))
;;;###autoload
(defun idee/execute-code-actions ()
"Execute code actions."
(interactive)
(funcall (alist-get 'idee/execute-code-actions-function idee/function-alist)))
(defun idee/shell-command-execute-in-project (command &optional new-shell)
"Run a single COMMAND in the current project shell.
When NEW-SHELL is specified the old eshell project buffer is killed."
(funcall (alist-get 'idee/shell-command-execute-in-project-function idee/function-alist) command new-shell))
(defun idee/shell-visible-window ()
"Return the visible shell window."
(funcall (alist-get 'idee/shell-visible-window-function idee/function-alist)))
(defun idee/shell-open-in-project ()
"Return the visible shell window."
(funcall (alist-get 'idee/shell-open-in-project-function idee/function-alist)))
(defmacro idee/shell-in-project (&rest body)
"Load a SETTINGS-FILE as local OPTIONS and evaluate BODY."
(declare (indent 1) (debug t))
`(let ()
(with-temp-buffer
,@body
(let* ((begin (point-min))
(end (point-max))
(content (buffer-substring-no-properties begin end)))
(mapc (lambda (l) (when (not (idee/string-blank l)) (idee/shell-command-execute-in-project l))) (split-string content "\n"))))))
(provide 'idee-actions)
;;; idee-actions.el ends here