Add defgroup; use defcustom for user vars.
[emacs.git] / lisp / emacs-lock.el
blob724fa034429b7baf4d8b8d9e8b1ba55b62c72059
1 ;;; emacs-lock.el --- prevents you from exiting emacs if a buffer is locked
3 ;; Copyright (C) 1994 Free Software Foundation, Inc
5 ;; Author: Tom Wurgler <twurgler@goodyear.com>
6 ;; Created: 12/8/94
7 ;; Version: 1.3
8 ;; Keywords:
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; any later version.
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
25 ;; Boston, MA 02111-1307, USA.
27 ;;; Commentary:
29 ;; This code sets a buffer-local variable to t if toggle-emacs-lock is run,
30 ;; then if the user attempts to exit emacs, the locked buffer name will be
31 ;; displayed and the exit aborted. This is just a way of protecting
32 ;; yourself from yourself. For example, if you have a shell running a big
33 ;; program and exiting emacs would abort that program, you may want to lock
34 ;; that buffer, then if you forget about it after a while, you won't
35 ;; accidentally exit emacs. To unlock the buffer, just goto the buffer and
36 ;; run toggle-emacs-lock again.
38 ;;; Code:
40 (defvar lock-emacs-from-exiting nil
41 "Whether emacs is locked to prevent exiting. See `check-emacs-lock'.")
42 (make-variable-buffer-local 'lock-emacs-from-exiting)
44 (defun check-emacs-lock ()
45 "Check if variable `lock-emacs-from-exiting' is t for any buffer.
46 If any t is found, signal error and display the locked buffer name."
47 (let ((buffers (buffer-list)))
48 (save-excursion
49 (while buffers
50 (set-buffer (car buffers))
51 (if lock-emacs-from-exiting
52 (error "Emacs is locked from exit due to buffer: %s" (buffer-name))
53 (setq buffers (cdr buffers)))))))
55 (defun toggle-emacs-lock ()
56 "Toggle `lock-emacs-from-exiting' between t and nil for the current buffer.
57 See `check-emacs-lock'."
58 (interactive)
59 (if lock-emacs-from-exiting
60 (setq lock-emacs-from-exiting nil)
61 (setq lock-emacs-from-exiting t))
62 (if lock-emacs-from-exiting
63 (message "Emacs is now locked from exiting.")
64 (message "Emacs is now unlocked.")))
66 (add-hook 'kill-emacs-hook 'check-emacs-lock)
68 ;; emacs-lock.el ends here