Commit | Line | Data |
---|---|---|
be010748 | 1 | ;;; emacs-lock.el --- prevents you from exiting emacs if a buffer is locked |
b578f267 | 2 | |
c9e2fc17 | 3 | ;; Copyright (C) 1994 Free Software Foundation, Inc |
b578f267 | 4 | |
c9e2fc17 RS |
5 | ;; Author: Tom Wurgler <twurgler@goodyear.com> |
6 | ;; Created: 12/8/94 | |
7 | ;; Version: 1.3 | |
8 | ;; Keywords: | |
b578f267 EN |
9 | |
10 | ;; This file is part of GNU Emacs. | |
11 | ||
12 | ;; GNU Emacs is free software; you can redistribute it and/or modify | |
c9e2fc17 | 13 | ;; it under the terms of the GNU General Public License as published by |
b578f267 EN |
14 | ;; the Free Software Foundation; either version 2, or (at your option) |
15 | ;; any later version. | |
16 | ||
17 | ;; GNU Emacs is distributed in the hope that it will be useful, | |
c9e2fc17 RS |
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. | |
b578f267 | 21 | |
c9e2fc17 | 22 | ;; You should have received a copy of the GNU General Public License |
b578f267 EN |
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. | |
c9e2fc17 RS |
26 | |
27 | ;;; Commentary: | |
b578f267 | 28 | |
c9e2fc17 RS |
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 | |
a7acbbe4 | 35 | ;; accidentally exit emacs. To unlock the buffer, just goto the buffer and |
c9e2fc17 RS |
36 | ;; run toggle-emacs-lock again. |
37 | ||
b578f267 EN |
38 | ;;; Code: |
39 | ||
c9e2fc17 RS |
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) | |
43 | ||
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))))))) | |
54 | ||
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."))) | |
65 | ||
66 | (add-hook 'kill-emacs-hook 'check-emacs-lock) | |
67 | ||
68 | ;; emacs-lock.el ends here |