annotate lisp/emacs-lock.el @ 13894:eeee95f4d989

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