Friday, June 17, 2011

Prevent accidental iconify of Emacs

It is sometimes the case that you may accidentally press Ctrl-z while in Emacs and the Emacs Window magically disappears. Ctrl-z is by default bound to iconify-frame which is another way of saying minimize the window. To make this feature more pleasant, introduce a yes or no confirmation when Ctrl-z is pressed. Add the following code to your .emacs file.

(defun smart-iconify-or-deiconify-frame()
  (interactive)
  (if (yes-or-no-p (format "Are you sure you want to iconify/deiconify Emacs? "))
      (iconify-frame))
  )

(global-set-key [?\C-z] 'smart-iconify-or-deiconify-frame)

3 comments:

perusio said...
This comment has been removed by the author.
perusio said...

Hello,

Ive added a test for the graphical environment and also rebind C-x C-z here.

tsengf said...

Great addition.