diff options
| author | Richard M. Stallman | 1994-12-24 16:49:59 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1994-12-24 16:49:59 +0000 |
| commit | c9e2fc17aa889b1c2f2f5ccb58662b3b8eabd3f1 (patch) | |
| tree | bddaede3f2e066fcfbe6870af73ae22938b3c6f0 | |
| parent | 2e6286be6c36aeaa7e3b74e3d56ae31bd17d696c (diff) | |
| download | emacs-c9e2fc17aa889b1c2f2f5ccb58662b3b8eabd3f1.tar.gz emacs-c9e2fc17aa889b1c2f2f5ccb58662b3b8eabd3f1.zip | |
Initial revision
| -rw-r--r-- | lisp/emacs-lock.el | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/lisp/emacs-lock.el b/lisp/emacs-lock.el new file mode 100644 index 00000000000..0026ca4dbe0 --- /dev/null +++ b/lisp/emacs-lock.el | |||
| @@ -0,0 +1,62 @@ | |||
| 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 | ||