Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!wuarchive!uunet!decwrl!asylum!osc!jgk From: jgk@osc.COM (Joe Keane) Newsgroups: comp.emacs Subject: trap-kill-emacs Message-ID: <4485@osc.COM> Date: 8 Feb 91 02:53:20 GMT Organization: Object Sciences Corp., Menlo Park, CA Lines: 37 If you're like me, you start up Emacs once and leave it running for weeks until you have to reboot your machine. This is really convenient because you have all these buffers lying around. Unfortunately, eventually you'll hit C-x C-c and kill it by accident. You could rebind the key, but i think this is better. ;; trapped in Emacs! (or (boundp 'kill-emacs-subr) (let ((s (symbol-function 'kill-emacs))) (or (subrp s) (error "Can't find kill-emacs subr")) (defvar kill-emacs-subr s "A variable containing the kill-emacs subr object."))) (defun trap-kill-emacs () "Redefine kill-emacs so it's difficult to leave Emacs." (interactive) (if (not (subrp (symbol-function 'kill-emacs))) (message "kill-emacs is already trapped") (fset 'kill-emacs (function (lambda nil (message (substitute-command-keys "kill-emacs is trapped (use \\[untrap-kill-emacs] to untrap it)"))))) (message (substitute-command-keys "kill-emacs is now trapped (use \\[untrap-kill-emacs] to untrap it)")))) (defun untrap-kill-emacs () "Undo the effect of trap-kill-emacs." (interactive) (if (subrp (symbol-function 'kill-emacs)) (message "kill-emacs is already not trapped") (fset 'kill-emacs kill-emacs-subr) (message (substitute-command-keys "kill-emacs is now not trapped (use \\[trap-kill-emacs] to trap it)"))))