Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Is it possible for M-f4 to first close the frames until there is only one frame left and them close emacs all together?

I did bind delete-frame to M-f4 but i keep forgetting that M-f4 doesn't close emacs, and I don't want to bind M-f4 to kill-emacs as I keep using M-f4 to close frames.

Thanks

share|improve this question

1 Answer 1

up vote 0 down vote accepted

This method, when bound to C-x C-c, allows you to close an emacs frame the same way, whether it's the sole window you have open, or whether it's a "child" frame of a "parent" frame. If you're like me, and use emacs in a windowing environment, you probably have lots of frames open at any given time. Well, it's a pain to remember to do Ctrl-x 5 0 to dispose of a child frame, and to remember to do C-x C-x to close the main frame (and if you're not careful, doing so will take all the child frames away with it). This is my solution to that: an intelligent close-frame operation that works in all cases (even in an emacs -nw session).

(defun intelligent-close ()
  "quit a frame the same way no matter what kind of frame you are on"
  (interactive)
  (if (eq (car (visible-frame-list)) (selected-frame))
      ;;for parent/master frame...
      (if (> (length (visible-frame-list)) 1)
          ;;close a parent with children present
   (delete-frame (selected-frame))
        ;;close a parent with no children present
 (save-buffers-kill-emacs))
    ;;close a child frame
    (delete-frame (selected-frame))))

http://www.dotemacs.de/dotfiles/BenjaminRutt.emacs.html

share|improve this answer
    
How is this better than (if (cdr (frame-list)) (delete-frame (selected-frame)) (save-buffers-kill-emacs)) (which I wrote at the time of Emacs 19, so it may miss out on later refinements)? –  Gilles Aug 13 '10 at 13:57
    
@Gilles I dunno. I don't actually know elisp so I can't judge which is better. I just found the above in that person's .emacs and since it works, I just took it. And since I havn't found any problems with it, I'm using it. –  Nathaniel Saxe Aug 13 '10 at 15:09

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.