Mercurial > emacs
comparison lisp/emacs-lock.el @ 10240:72101c74e9e7
Initial revision
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Sat, 24 Dec 1994 16:49:59 +0000 |
parents | |
children | f225e4de23b4 |
comparison
equal
deleted
inserted
replaced
10239:52a1e5ef144c | 10240:72101c74e9e7 |
---|---|
1 ;; emacs-lock.el --- Prevents you from exiting emacs if a buffer is locked | |
2 ;; Copyright (C) 1994 Free Software Foundation, Inc | |
3 ;; | |
4 ;; Author: Tom Wurgler <twurgler@goodyear.com> | |
5 ;; Created: 12/8/94 | |
6 ;; Version: 1.3 | |
7 ;; Keywords: | |
8 ;; | |
9 ;; This program is free software; you can redistribute it and/or modify | |
10 ;; it under the terms of the GNU General Public License as published by | |
11 ;; the Free Software Foundation; either version 2 of the License, or | |
12 ;; (at your option) any later version. | |
13 ;; | |
14 ;; This program is distributed in the hope that it will be useful, | |
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 ;; GNU General Public License for more details. | |
18 ;; | |
19 ;; You should have received a copy of the GNU General Public License | |
20 ;; along with GNU Emacs; if not, write to the Free Software | |
21 ;; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
22 | |
23 ;;; Commentary: | |
24 ;; | |
25 ;; This code sets a buffer-local variable to t if toggle-emacs-lock is run, | |
26 ;; then if the user attempts to exit emacs, the locked buffer name will be | |
27 ;; displayed and the exit aborted. This is just a way of protecting | |
28 ;; yourself from yourself. For example, if you have a shell running a big | |
29 ;; program and exiting emacs would abort that program, you may want to lock | |
30 ;; that buffer, then if you forget about it after a while, you won't | |
31 ;; accidently exit emacs. To unlock the buffer, just goto the buffer and | |
32 ;; run toggle-emacs-lock again. | |
33 | |
34 (defvar lock-emacs-from-exiting nil | |
35 "Whether emacs is locked to prevent exiting. See `check-emacs-lock'.") | |
36 (make-variable-buffer-local 'lock-emacs-from-exiting) | |
37 | |
38 (defun check-emacs-lock () | |
39 "Check if variable `lock-emacs-from-exiting' is t for any buffer. | |
40 If any t is found, signal error and display the locked buffer name." | |
41 (let ((buffers (buffer-list))) | |
42 (save-excursion | |
43 (while buffers | |
44 (set-buffer (car buffers)) | |
45 (if lock-emacs-from-exiting | |
46 (error "Emacs is locked from exit due to buffer: %s" (buffer-name)) | |
47 (setq buffers (cdr buffers))))))) | |
48 | |
49 (defun toggle-emacs-lock () | |
50 "Toggle `lock-emacs-from-exiting' between t and nil for the current buffer. | |
51 See `check-emacs-lock'." | |
52 (interactive) | |
53 (if lock-emacs-from-exiting | |
54 (setq lock-emacs-from-exiting nil) | |
55 (setq lock-emacs-from-exiting t)) | |
56 (if lock-emacs-from-exiting | |
57 (message "Emacs is now locked from exiting.") | |
58 (message "Emacs is now unlocked."))) | |
59 | |
60 (add-hook 'kill-emacs-hook 'check-emacs-lock) | |
61 | |
62 ;; emacs-lock.el ends here |