[comp.emacs] trap-kill-emacs

jgk@osc.COM (Joe Keane) (02/08/91)

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)"))))

sane@cs.uiuc.edu (Aamod Sane) (02/09/91)

I use this

(defun my-exit-from-emacs ()
  (interactive)
  (if (yes-or-no-p "Do you really want to exit? ")
      (save-buffers-kill-emacs)))

(global-set-key "\C-x\C-c" 'my-exit-from-emacs)

Cheers

Aamod
-- 
sane@cs.uiuc.edu
         ==         / \  
-----    ==    *    \_/     -|||- 
         ==     

marc@arnor.uucp (02/11/91)

I just put a prompt on it -

(defun ctrlxctrlc () "Careful exit from emacs"
  (interactive)
  (if (y-or-n-p "Do you really want to exit emacs? ")
      (save-buffers-kill-emacs)
    (message "")
    ))

(global-set-key "\C-x\C-c" 'ctrlxctrlc)

That has been good enough for me.
--


Marc Auslander       <marc@ibm.com>

jon@nucleus.mi.org (Jon Block) (02/12/91)

  isn't the kill-emacs-hook provided for this purpose

(setq-default kill-emacs-hook 'really-kill-emacs)

(defun really-kill-emacs ()
"verify killing is really intended."
	(interactive)
	(if (not (y-or-no-p "Really kill emacs: "))
		(keyboard-quit)))