aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJuanma Barranquero2012-04-14 05:11:18 +0200
committerJuanma Barranquero2012-04-14 05:11:18 +0200
commitd5e6342ed5e408014019c478ce16a47a2aad418b (patch)
treea788615f61d7944aecadbaafcc2f883a2cb6ef0f
parentab036cd7bdd7b087047d241ffb5607d14942179e (diff)
downloademacs-d5e6342ed5e408014019c478ce16a47a2aad418b.tar.gz
emacs-d5e6342ed5e408014019c478ce16a47a2aad418b.zip
* lisp/emacs-lock.el (emacs-lock-locked-buffer-functions): New hook.
(emacs-lock--exit-locked-buffer): Return the locked buffer. Doc fix. (emacs-lock--kill-emacs-hook, emacs-lock--kill-emacs-query-functions) (emacs-lock--kill-buffer-query-functions): Run new hook. Fixes: debbugs:11017
-rw-r--r--lisp/ChangeLog7
-rw-r--r--lisp/emacs-lock.el40
2 files changed, 33 insertions, 14 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 858c4285c7a..1974a7a5af1 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,10 @@
12012-04-14 Juanma Barranquero <lekktu@gmail.com>
2
3 * emacs-lock.el (emacs-lock-locked-buffer-functions): New hook.
4 (emacs-lock--exit-locked-buffer): Return the locked buffer. Doc fix.
5 (emacs-lock--kill-emacs-hook, emacs-lock--kill-emacs-query-functions)
6 (emacs-lock--kill-buffer-query-functions): Run new hook. (Bug#11017)
7
12012-04-14 Stefan Monnier <monnier@iro.umontreal.ca> 82012-04-14 Stefan Monnier <monnier@iro.umontreal.ca>
2 9
3 * progmodes/which-func.el (which-func-modes): Change default. 10 * progmodes/which-func.el (which-func-modes): Change default.
diff --git a/lisp/emacs-lock.el b/lisp/emacs-lock.el
index 743b828326c..f5954564a2f 100644
--- a/lisp/emacs-lock.el
+++ b/lisp/emacs-lock.el
@@ -81,6 +81,13 @@ for both actions (NOT RECOMMENDED)."
81 :group 'emacs-lock 81 :group 'emacs-lock
82 :version "24.1") 82 :version "24.1")
83 83
84(defcustom emacs-lock-locked-buffer-functions nil
85 "Abnormal hook run when Emacs Lock prevents exiting Emacs, or killing a buffer.
86The functions get one argument, the first locked buffer found."
87 :type 'hook
88 :group 'emacs-lock
89 :version "24.2")
90
84(defvar emacs-lock-mode nil 91(defvar emacs-lock-mode nil
85 "If non-nil, the current buffer is locked. 92 "If non-nil, the current buffer is locked.
86It can be one of the following values: 93It can be one of the following values:
@@ -119,40 +126,45 @@ See `emacs-lock-unlockable-modes'."
119 (or (eq unlock 'all) (eq unlock action)))))) 126 (or (eq unlock 'all) (eq unlock action))))))
120 127
121(defun emacs-lock--exit-locked-buffer () 128(defun emacs-lock--exit-locked-buffer ()
122 "Return the name of the first exit-locked buffer found." 129 "Return the first exit-locked buffer found."
123 (save-current-buffer 130 (save-current-buffer
124 (catch :found 131 (catch :found
125 (dolist (buffer (buffer-list)) 132 (dolist (buffer (buffer-list))
126 (set-buffer buffer) 133 (set-buffer buffer)
127 (unless (or (emacs-lock--can-auto-unlock 'exit) 134 (unless (or (emacs-lock--can-auto-unlock 'exit)
128 (memq emacs-lock-mode '(nil kill))) 135 (memq emacs-lock-mode '(nil kill)))
129 (throw :found (buffer-name)))) 136 (throw :found buffer)))
130 nil))) 137 nil)))
131 138
132(defun emacs-lock--kill-emacs-hook () 139(defun emacs-lock--kill-emacs-hook ()
133 "Signal an error if any buffer is exit-locked. 140 "Signal an error if any buffer is exit-locked.
134Used from `kill-emacs-hook' (which see)." 141Used from `kill-emacs-hook' (which see)."
135 (let ((buffer-name (emacs-lock--exit-locked-buffer))) 142 (let ((locked (emacs-lock--exit-locked-buffer)))
136 (when buffer-name 143 (when locked
137 (error "Emacs cannot exit because buffer %S is locked" buffer-name)))) 144 (run-hook-with-args 'emacs-lock-locked-buffer-functions locked)
145 (error "Emacs cannot exit because buffer %S is locked"
146 (buffer-name locked)))))
138 147
139(defun emacs-lock--kill-emacs-query-functions () 148(defun emacs-lock--kill-emacs-query-functions ()
140 "Display a message if any buffer is exit-locked. 149 "Display a message if any buffer is exit-locked.
141Return a value appropriate for `kill-emacs-query-functions' (which see)." 150Return a value appropriate for `kill-emacs-query-functions' (which see)."
142 (let ((locked (emacs-lock--exit-locked-buffer))) 151 (let ((locked (emacs-lock--exit-locked-buffer)))
143 (or (not locked) 152 (if (not locked)
144 (progn 153 t
145 (message "Emacs cannot exit because buffer %S is locked" locked) 154 (run-hook-with-args 'emacs-lock-locked-buffer-functions locked)
146 nil)))) 155 (message "Emacs cannot exit because buffer %S is locked"
156 (buffer-name locked))
157 nil)))
147 158
148(defun emacs-lock--kill-buffer-query-functions () 159(defun emacs-lock--kill-buffer-query-functions ()
149 "Display a message if the current buffer is kill-locked. 160 "Display a message if the current buffer is kill-locked.
150Return a value appropriate for `kill-buffer-query-functions' (which see)." 161Return a value appropriate for `kill-buffer-query-functions' (which see)."
151 (or (emacs-lock--can-auto-unlock 'kill) 162 (if (or (emacs-lock--can-auto-unlock 'kill)
152 (memq emacs-lock-mode '(nil exit)) 163 (memq emacs-lock-mode '(nil exit)))
153 (progn 164 t
154 (message "Buffer %S is locked and cannot be killed" (buffer-name)) 165 (run-hook-with-args 'emacs-lock-locked-buffer-functions (current-buffer))
155 nil))) 166 (message "Buffer %S is locked and cannot be killed" (buffer-name))
167 nil))
156 168
157(defun emacs-lock--set-mode (mode arg) 169(defun emacs-lock--set-mode (mode arg)
158 "Setter function for `emacs-lock-mode'." 170 "Setter function for `emacs-lock-mode'."