-
Notifications
You must be signed in to change notification settings - Fork 1
/
my-devel.el
356 lines (297 loc) · 9.64 KB
/
my-devel.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
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
;;; my-devel.el --- Central configuration for development hooks
;;
;;; Commentary:
;;
;; All other development modes should be triggered from here.
;;
;;; Code:
(require 'use-package)
(require 'my-vars)
(require 'my-find)
(require 'my-tracking)
(require 'my-hydra)
;; EditorConfig
(use-package editorconfig
:ensure t
:diminish "EdCf"
:config
;; See https://github.com/editorconfig/editorconfig-emacs/issues/246
(add-to-list 'editorconfig-exclude-modes 'git-rebase-mode)
(editorconfig-mode 1))
(use-package editorconfig-custom-majormode
:ensure t
:config (add-hook 'editorconfig-after-apply-functions
#'editorconfig-custom-majormode))
;; Origami code folding
(use-package origami
:if (locate-library "origami")
:commands origami-mode
:after hydra
:hook (prog-mode . origami-mode)
:bind (:map origami-mode-map
("C-c f" . hydra-folding/body))
:init (defhydra hydra-folding (:color red :hint nil)
"
_o_pen node _n_ext fold toggle _f_orward _F_ill column: %`fill-column
_c_lose node _p_revious fold toggle _a_ll e_x_it
"
("o" origami-open-node)
("c" origami-close-node)
("n" origami-next-fold)
("p" origami-previous-fold)
("f" origami-forward-toggle-node)
("a" origami-toggle-all-nodes)
("F" fill-column)
("x" nil :color blue)))
(use-package prog-mode
:hook (prog-mode . turn-on-auto-fill))
;; Regex's
(use-package rx
:ensure t
:commands rx)
;; xr allows you to covert regex into rx
(use-package xr
:ensure t
:pin gnu)
(use-package re-builder
:ensure t
:after (hydra my-toggles)
:commands (re-builder reb-change-syntax)
:bind (:map reb-mode-map
("C-x t" . my-reb-hydra/body)
:map reb-lisp-mode-map
("C-x t" . my-reb-hydra/body))
:config (setq reb-re-syntax 'rx)
:init (defhydra my-reb-hydra (:color teal)
(concat "<TAB> Toggle syntax: %`reb-re-syntax ")
("TAB" reb-change-syntax nil)
("t" my-hydra-toggle/body "main toggles")
("q" quit-window "quit")))
;;
;; All hail LSP mode
;;
(use-package lsp-mode
:ensure t
:commands (lsp)
:hook ((c-mode . lsp)
(python-mode . lsp))
:bind (:map lsp-mode-map ("C-c C-c" . lsp-execute-code-action))
:init (setq lsp-keymap-prefix "C-c C-l")
:config
(setq
;; lsp-log-io t
;; lsp-enable-on-type-formatting nil - if it starts getting in the
;; way
lsp-clients-clangd-args '("--header-insertion-decorators=0" "--header-insertion=never")
lsp-use-plists t))
(with-eval-after-load 'lsp-mode
(add-hook 'lsp-mode-hook #'lsp-enable-which-key-integration))
(use-package lsp-ui
:commands lsp-ui-mode
:ensure t
:hook (lsp-mode . lsp-ui-mode)
:custom
(lsp-ui-peek-always-show t)
(lsp-ui-sideline-show-hover t)
(lsp-ui-doc-enable nil))
;;
;; Rust
;;
(use-package rustic
:ensure t
:config (progn (add-to-list 'compilation-error-regexp-alist-alist
(cons 'rustic-error rustic-compilation-error))
(add-to-list 'compilation-error-regexp-alist-alist
(cons 'rustic-warning rustic-compilation-warning))
(add-to-list 'compilation-error-regexp-alist-alist
(cons 'rustic-info rustic-compilation-info))
(add-to-list 'compilation-error-regexp-alist-alist
(cons 'rustic-panic rustic-compilation-panic))
(add-to-list 'compilation-error-regexp-alist 'rustic-error)
(add-to-list 'compilation-error-regexp-alist 'rustic-warning)
(add-to-list 'compilation-error-regexp-alist 'rustic-info)
(add-to-list 'compilation-error-regexp-alist 'rustic-panic)))
;;
;; Rust
;;
(use-package rustic
:ensure t)
;;
;; Compile Mode
;;
(use-package my-c-mode)
;; See: http://emacs.stackexchange.com/questions/3802/how-can-i-detect-compilation-mode-is-waiting-for-input/3807?noredirect=1#comment5796_3807
(defun my-compilation-mode-warn-about-prompt ()
"Pop up a warning if we stall due to interactive config questions."
(save-excursion
(let ((re (rx "[" (one-or-more (any "n" "N" "m" "M" "Y" "y") "/") "?]"
(optional " (NEW)") (zero-or-more whitespace) buffer-end)))
(when (re-search-backward re nil 'no-error)
(lwarn 'emacs :warning "Compilation process in %s seems stalled!"
(buffer-name))))))
(defun my-hide-compilation-buffer (proc)
"Hide the compile buffer `PROC' is ignored."
(let* ((window (get-buffer-window "*compilation*"))
(frame (window-frame window))
(buf (current-buffer)))
(ignore-errors
(delete-window window))
;; preserve the buffer we are in
(set-buffer buf)))
(defun my-report-compilation-finished (buf exit-string)
"Report the compilation buffer `BUF' to tracker."
(tracking-add-buffer buf))
;; Smart compile commands
(defvar my-core-count
(string-to-number
(shell-command-to-string
"cat /proc/cpuinfo | grep processor | wc -l"))
"Count of the CPU cores on this system.")
;; compilation-mode error regexs
(defvar my-tsan-compilation-mode-regex
(rx
(: bol (zero-or-more blank) ; start-of-line
"#" (one-or-more digit) ; stack depth
blank
(one-or-more (in alnum "_")) ; function name
blank
(group-n 1 (one-or-more (in alnum "/.-"))) ; path
":"
(group-n 2 (one-or-more digit)) ; line number
))
"A regex to match lines of the form:
#1 page_flush_tb_1 /home/alex/lsrc/qemu/qemu.git/translate-all.c:818 (qemu-arm+0x00006000cb42)
")
;;
;; The keymap for counsel-compile-map is too complicated and should be
;; cleared up:
;; M-o brings up actions (d to delete the entry from history)
;; C-j execute current minibuffer (rather than take matching entry)
;; C-o brings up the ivy hydra
;;
(use-package compile
:after counsel
:bind (("C-c r" . recompile)
(:map compilation-mode-map
("n" . compilation-next-error)
("p" . compilation-previous-error)))
:diminish ((compilation-in-progress . "*COM*"))
:config
(progn
(setq
compilation-auto-jump-to-first-error nil
compilation-scroll-output t
compilation-window-height 10
counsel-compile-make-args (format "-j%d" (+ 1 my-core-count)))
(add-to-list
'compilation-error-regexp-alist-alist
(list 'tsan my-tsan-compilation-mode-regex 1 2 nil 0))
;; lets not overtax the regex match on our huge compilation buffers
(when I-am-at-work
(setq compilation-error-regexp-alist '(gcc-include gnu tsan
rustic-error rustic-warning rustic-info rustic-panic)))
;; Detect stalls
(add-hook 'compilation-filter-hook
#'my-compilation-mode-warn-about-prompt)
;; Add tracking to the compilation buffer
(with-eval-after-load 'tracking
(add-hook 'compilation-start-hook 'my-hide-compilation-buffer)
(add-hook 'compilation-finish-functions 'my-report-compilation-finished))))
;; Tags
;;
;; Favour the common xref interface on newer Emacsen
;;
(if (version<= "25.1" emacs-version)
(use-package gxref
:ensure t
:config (add-to-list 'xref-backend-functions
'gxref-xref-backend))
(use-package counsel-gtags
:ensure t
:commands counsel-gtags-mode
:config
(add-hook 'c-mode-hook 'counsel-gtags-mode)
(add-hook 'c++-mode-hook 'counsel-gtags-mode)))
;; checkpatch
(use-package checkpatch-mode
:after magit
:load-path (lambda () (my-return-path-if-ok
"~/mysrc/checkpatch-mode.git"))
:bind (:map magit-commit-section-map
("C-x c" . checkpatch-run-from-magit)))
;; Coverage
(when have-melpa
(use-package cov
:ensure t))
;; shell modes
(use-package sh-mode
:mode ((".*\.sh$" . sh-mode)
(".*\.bbclass$" . sh-mode)
(".*\.bb$" . sh-mode)))
(use-package fish-mode
:mode (("config.fish" . fish-mode))
:ensure t)
(use-package fish-completion
:ensure t)
;; asm-mode
;; ;
;; We define some additional regexs to match ARM and TCG style assembler
;
; ldr q1, [x20, x0]
; eor v0.16b, v0.16b, v1.16b
; add_i64 tmp2,tmp2,tmp3
; movi_i64 tmp7,$0x8
;
(defvar arm-asm-register
(rx (: (in "," space) ; leading whitespace or separator
(group (in "qwvx") digit (zero-or-one digit) ;;
(opt ; vector type
"."
digit (zero-or-one digit)
(in "bwhsdq"))
)))
"Match against an ARM register.")
;; (font-lock-add-keywords 'asm-mode
;; '((arm-asm-register (1 'font-lock-variable-name-face))))
(use-package asm-mode
:if (not (featurep 'gas-mode))
:config (setq asm-comment-char ?\;))
;; YAML
(use-package yaml-mode
:ensure t)
;; Handle Makefile.blah
(use-package make-mode
:mode ((".*\.mak" . makefile-gmake-mode)
("Makefile\..*" . makefile-gmake-mode)))
(use-package meson-mode
:ensure t)
;; Handle expect files
(use-package tcl
:mode ("\\.expect\\'" . tcl-mode))
;; Markdown
;; Markdown sites
(use-package markdown-mode
:ensure t
:config
(progn
(setq markdown-reference-location 'end)))
;;
(use-package realgud
:commands (realgud:gdb realgud:gdb-pid realgud:ipdb))
;; Pairs and parenthesis
;;
;; I used to use smart-parens but it was too much. electric-pair-mode
;; and show-paren-mode seem to be enough for now.
;;
(use-package elec-pair
:ensure t
:config (electric-pair-mode))
(use-package paren
:ensure t
:config (show-paren-mode))
;; Docker is useful
(use-package dockerfile-mode
:mode ("\\.docker\\'" . dockerfile-mode)
:ensure t)
(provide 'my-devel)
;;; my-devel.el ends here