-
Notifications
You must be signed in to change notification settings - Fork 1
/
bury-successful-compilation.el
117 lines (98 loc) · 4.42 KB
/
bury-successful-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
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
;;; bury-successful-compilation.el --- Bury the *compilation* buffer after successful compilation
;; Version: 0.0.20140308
;; Copyright (C) 2015 Eric Crosson
;; Author: Eric Crosson <esc@ericcrosson.com>
;; Keywords: compilation
;; Package-Version: 0.1.2
;; This program is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;; This package provides a minor mode that will do two things
;; after a successful recompile:
;; 1) bury the *compilation* buffer, and
;; 2) restore your window configuration to how it looked when you
;; issued the last recompile, ignoring successive compilations to
;; squash bugs.
;; Commentary:
;;
;; `bury-successful-compilation' works by saving the current window
;; configuration to a register before each compilation. If a
;; compilation fails, the saved state is not restored until the build
;; succeeds again. This means after an attempted compilation, you can
;; thrash your window configuration to chase down the compile-time
;; issue, because when the build succeeds you will be popped up the
;; stack back to the saved window configuration, right before your
;; unsuccessful compilation attempt.
;;; Code:
(defgroup bury-successful-compilation nil
"Bury successful *compilation* buffers."
:group 'compilation :group 'programming)
(defcustom bury-successful-compilation-precompile-window-state nil
"Storage for `bury-successful-compilation' to restore
window configuration after a successful compilation."
:type 'boolean
:group 'bury-successful-compilation)
(defcustom bury-successful-compilation-save-windows t
"If nil, the user is attempting to recompile after a failed
attempt. What this means to advice
`bury-successful-compilation-save-window' is now is not
the time to save current-window configuration to variable
`bury-successful-compilation-precompile-window-state'."
:type 'boolean
:group 'bury-successful-compilation)
(defadvice compilation-start (before
bury-successful-compilation-save-windows
activate)
"Save window configuration to
`bury-successful-compilation-precompile-window-state' unless
`bury-successful-compilation-save-windows' is nil."
(when bury-successful-compilation-save-windows
(window-configuration-to-register
bury-successful-compilation-precompile-window-state)))
(defun bury-successful-compilation-buffer (buffer string)
"Bury the compilation BUFFER after a successful compile.
Argument STRING provided by compilation hooks."
(setq bury-successful-compilation-save-windows
(and
(equal 'compilation-mode major-mode)
(string-match "finished" string)
(not (search-forward "warning" nil t))))
(when bury-successful-compilation-save-windows
(ignore-errors
(jump-to-register
bury-successful-compilation-precompile-window-state))
(message "Compilation successful.")))
(defun bury-successful-compilation-turn-on ()
"Turn on function `bury-successful-compilation'."
(ad-enable-advice 'compilation-start 'before
'bury-successful-compilation-save-windows)
(add-hook 'compilation-finish-functions
'bury-successful-compilation-buffer))
(defun bury-successful-compilation-turn-off ()
"Turn off function `bury-successful-compilation'."
(setq bury-successful-compilation-precompile-window-state nil)
(ad-disable-advice 'compilation-start 'before
'bury-successful-compilation-save-windows)
(remove-hook 'compilation-finish-functions
'bury-successful-compilation-buffer))
;;;###autoload
(define-minor-mode bury-successful-compilation
"A minor mode to bury the *compilation* buffer upon successful
compilations."
:init-value t
:global t
:require 'bury-successful-compilation
:group 'bury-successful-compilation
(if bury-successful-compilation
(bury-successful-compilation-turn-on)
(bury-successful-compilation-turn-off)))
(provide 'bury-successful-compilation)
;;; bury-successful-compilation.el ends here