-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit-compile.el
77 lines (63 loc) · 2.51 KB
/
init-compile.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
(setq compilation-read-command nil
compilation-scroll-output t)
(after-load 'compile
(require 'ansi-color)
(defun jester/colourise-compilation-buffer ()
(when (eq major-mode 'compilation-mode)
(ansi-color-apply-on-region compilation-filter-start (point-max))))
(add-hook 'compilation-filter-hook 'jester/colourise-compilation-buffer)
(add-hook 'compilation-mode-hook 'jester/set-shell-buffer-face)
(add-hook 'compilation-mode-hook (lambda () (setq truncate-lines nil))))
(require-package 'alert)
(setq alert-default-style (pcase window-system
('x 'x11)
('mac 'osx-notifier)
(_ 'message)))
(defun jester/alert-after-compilation-finish (buf result)
"Use `alert' to report compilation RESULT if BUF is hidden."
(when (buffer-live-p buf)
(unless (catch 'is-visible
(walk-windows (lambda (w)
(when (eq (window-buffer w) buf)
(throw 'is-visible t))))
nil)
(alert (concat "Compilation " result)
:buffer buf
:category 'compilation))))
(after-load 'compile
(add-hook 'compilation-finish-functions
'jester/alert-after-compilation-finish))
(defvar-local jester-run-command nil
"shell command to run the project.")
(defun jester/run-project ()
"Run it with `compile' and `jester-run-command'."
(interactive)
(if jester-run-command
(compile jester-run-command)
(user-error "no run command configured for this buffer, check mode hooks"))
;; switch to "*compilation*" buffer because it's configured not to show when `compile'
(switch-to-buffer "*compilation*"))
(defvar-local jester-test-command nil
"shell command to run the test.")
(defun jester/run-test ()
"Run it with `compile' and `jester-test-command'."
(interactive)
(if jester-test-command
(compile jester-test-command)
(user-error "no test command configured for this buffer, check mode hooks"))
;; switch to "*compilation*" buffer because it's configured not to show when `compile'
(switch-to-buffer "*compilation*"))
(jester/with-leader
;; TODO assign a key to "cargo check"?
"c i" 'compile ; "compile it!"
"b c" (lambda! (switch-to-buffer "*compilation*"))
"c r" 'jester/run-project
"c t" 'jester/run-test)
(general-define-key
:states '(motion)
:keymaps 'compilation-mode-map
"h" 'evil-backward-char
"f" 'link-hint-open-link
"g g" 'evil-goto-first-line
"r" 'recompile)
(provide 'init-compile)