-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmy-aj-compilation.el
61 lines (48 loc) · 2.3 KB
/
my-aj-compilation.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
;; Compilation mode
;; Compilation ;;;;;;;;;;;;;;;;;;;;;;;;;
(setq compilation-scroll-output t)
(setq compilation-window-height 17)
(setq compilation-ask-about-save nil)
(setq compilation-save-buffers-predicate '(lambda () nil))
(defvar aj-exceptions-list (list "find" "perl" "ack")
"Exception commands for don't hide compilation window.")
(defvar aj-compilation-saved-window-configuration nil
"Previous window conf from before a compilation")
(defvar aj-compile-command ""
"The compile command used by compilation-start since
`compile-command' is only saved by `compile' command.")
;; Hide *compilation* buffer if compile didn't give errors
(defadvice compilation-start (before aj-compilation-save-window-configuration(command comint))
"Save window configuration before compilation in
`aj-compilation-saved-window-configuration'"
;; compile command is not saved in compilation-start function only in
;; compile function (rgrep only uses compilation-start)
(setq aj-compile-command command)
;; Save window configuration
(setq aj-compilation-saved-window-configuration
(current-window-configuration)))
(ad-activate 'compilation-start)
(defun aj-is-exception (ex-list aj-compile-command)
"Search through exceptions list `ex-list'.
Used to decide whether or not hide compilation window."
(if (> (length ex-list) 0)
(let* ((ex-position (string-match (car ex-list) aj-compile-command))
;; Not nil and not 0 means that command was "find" at
;; pos 0 which means that I don't want to restore the layout
(is-exception (and (integerp ex-position) (zerop ex-position))))
(if is-exception
t
(aj-is-exception (cdr ex-list) aj-compile-command)))
nil))
;; compilation-handle-exit returns (run-hook-with-args
;; 'compilation-finish-functions cur-buffer msg) Could use but it only
;; got a string describing status
(defadvice compilation-handle-exit
(after aj-compilation-exit-function(process-status exit-status msg))
"Hack to restore window conf"
(when (and (eq process-status 'exit)
(zerop exit-status)
(not (aj-is-exception aj-exceptions-list aj-compile-command)))
(set-window-configuration aj-compilation-saved-window-configuration)))
(ad-activate 'compilation-handle-exit)
(provide 'my-aj-compilation)