-
Notifications
You must be signed in to change notification settings - Fork 1
/
compilation-always-kill.el
137 lines (109 loc) · 4.86 KB
/
compilation-always-kill.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
;;; compilation-always-kill.el --- kill compilation without prompting
;; Copyright 2008, 2009, 2010 Kevin Ryde
;; Author: Kevin Ryde <[email protected]>
;; Version: 5
;; Keywords: processes
;; EmacsWiki: CompilationMode
;; URL: http://user42.tuxfamily.org/compilation-always-kill/index.html
;; compilation-always-kill.el 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, or (at your
;; option) any later version.
;;
;; compilation-always-kill.el 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 can get a copy of the GNU General Public License online at
;; <http://www.gnu.org/licenses/>.
;;; Commentary:
;; `compilation-always-kill-mode' minor mode makes M-x compile kill any
;; existing compilation process without its normal `yes-or-no-p' query.
;; See the mode docstring below for more.
;;; Install:
;; Put compilation-always-kill.el in one of your `load-path' directories,
;; and in your .emacs add
;;
;; (autoload 'compilation-always-kill-mode "compilation-always-kill" nil t)
;;
;; and to enable it
;;
;; (compilation-always-kill-mode 1)
;;
;; or deferred until you actually compile something,
;;
;; (eval-after-load "compile" '(compilation-always-kill-mode 1))
;;
;; There's an autoload cookie for the mode, if you know how to use
;; `update-file-autoloads' and friends. You can M-x customize-variable
;; compilation-always-kill-mode to enable too, though that depends on either
;; those autoloads or a whole (require 'compilation-always-kill) in your
;; .emacs.
;;; Emacsen:
;; Designed for Emacs 22, works in Emacs 21 and XEmacs 21.
;;; History:
;; Version 1 - the first version
;; Version 2 - new home page
;; Version 3 - undo defadvice on unload-feature
;; Version 4 - defang defadvice for emacs21,xemacs21 unload-feature
;; Version 5 - express dependency on 'advice
;;; Code:
;; for `ad-find-advice' macro when running uncompiled
;; (don't unload 'advice before our -unload-function)
(require 'advice)
;;;###autoload
(define-minor-mode compilation-always-kill-mode
"Always kill an existing compilation process in M-x compile.
This minor mode makes `compile' kill any existing compilation
process when starting a new one, whereas normally it asks with
`yes-or-no-p'.
Interactively \\[compilation-always-kill-mode] toggles, likewise
with no argument from lisp code. Otherwise ARG t or non-zero
enables, or nil or 0 disables.
Whether you want `compile' to ask is a personal preference, a
choice between
- convenience of restarting a \"make\" etc when you've edited
something, without answering a question
- risk of killing a long running or important job you forgot
you had going
If you use automatic kill most of the time then you can always
turn it off with \\[compilation-always-kill-mode] while running
something important. Turning it off like that is the main reason
for a whole minor mode for what's otherwise two lines of code.
The query when exiting Emacs about \"running processes\" is not
changed. Have a look at quick-yes.el for answering that or
`compile' with less keys.
----
Incidentally the `compile' query is particularly annoying when
the time it takes you to think about killing is long enough for
it to finish anyway! It could be cute for `yes-or-no-p' to let
you just press return, or to abandon the question and just
continue, when that happens. A special Ret binding might be able
to do that, though ideally you'd want `compile' to somehow work
out the conditions where a query is no longer applicable."
:group 'compilation
:global t
:type 'boolean
:link '(url-link
:tag "compilation-always-kill.el home page"
"http://user42.tuxfamily.org/compilation-always-kill/index.html"))
(defadvice yes-or-no-p (around compilation-always-kill activate)
"Minor mode for `compile' to always kill existing compilation."
(if (and (boundp 'compilation-always-kill-mode) ;; in case `unload-feature'
compilation-always-kill-mode
(string-match "A compilation process is running; kill it\\?"
prompt))
(setq ad-return-value t)
ad-do-it))
;; `-unload-function' only runs in emacs22 up, so the defadvice is made
;; harmless when everything else unloaded in emacs21 and xemacs21.
;; Removing the advice is good as a cleanup though.
;;
(defun compilation-always-kill-unload-function ()
(when (ad-find-advice 'yes-or-no-p 'around 'compilation-always-kill)
(ad-remove-advice 'yes-or-no-p 'around 'compilation-always-kill)
(ad-activate 'yes-or-no-p))
nil) ;; and do normal unload-feature actions too
(provide 'compilation-always-kill)
;;; compilation-always-kill.el ends here