forked from purcell/emacs.d
-
Notifications
You must be signed in to change notification settings - Fork 0
/
init-compile.el
59 lines (47 loc) · 2.16 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
(setq-default compilation-scroll-output t)
(require-package 'alert)
;; Customize `alert-default-style' to get messages after compilation
(defun sanityinc/alert-after-compilation-finish (buf result)
"Use `alert' to report compilation RESULT if BUF is hidden."
(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
'sanityinc/alert-after-compilation-finish))
(defvar sanityinc/last-compilation-buffer nil
"The last buffer in which compilation took place.")
(after-load 'compile
(defadvice compilation-start (after sanityinc/save-compilation-buffer activate)
"Save the compilation buffer to find it later."
(setq sanityinc/last-compilation-buffer next-error-last-buffer))
(defadvice recompile (around sanityinc/find-prev-compilation (&optional edit-command) activate)
"Find the previous compilation buffer, if present, and recompile there."
(if (and (null edit-command)
(not (derived-mode-p 'compilation-mode))
sanityinc/last-compilation-buffer
(buffer-live-p (get-buffer sanityinc/last-compilation-buffer)))
(with-current-buffer sanityinc/last-compilation-buffer
ad-do-it)
ad-do-it)))
(global-set-key [f6] 'recompile)
(defadvice shell-command-on-region
(after sanityinc/shell-command-in-view-mode
(start end command &optional output-buffer replace error-buffer display-error-buffer)
activate)
"Put \"*Shell Command Output*\" buffers into view-mode."
(unless output-buffer
(with-current-buffer "*Shell Command Output*"
(view-mode 1))))
(after-load 'compile
(require 'ansi-color)
(defun sanityinc/colourise-compilation-buffer ()
(when (eq major-mode 'compilation-mode)
(ansi-color-apply-on-region compilation-filter-start (point-max))))
(add-hook 'compilation-filter-hook 'sanityinc/colourise-compilation-buffer))
(provide 'init-compile)