I have a lot of frames always open in emacs. Like I use emacsclient (daemon) and almost never restart my computer, these frames are never close. I could close one with C-x k
but how to close all opened frames?
Asked
Active
Viewed 1,106 times
1

ppr
- 685
- 7
- 24
-
Do you mean buffers by any chance? Check `C-x C-b` or `list-buffers` – mike3996 Dec 15 '13 at 21:38
-
Also `C-x k` kills a buffer, not the associated frame. `C-x 5 0` kills the frame (but keeps the buffer). – tripleee Dec 16 '13 at 11:02
-
Why do you create so many frames in the first place, anyway? See http://stackoverflow.com/questions/9968740/create-or-reuse-existing-emacs-gui-frame – tripleee Dec 16 '13 at 11:04
2 Answers
3
Closing all frames is just quitting, is it not?
If you want to close all but one frame you can use delete-other-frames
with the key-sequence C-x 5 1.

Tobias
- 5,038
- 1
- 18
- 39
-
I want to avoid to close the window, then restart emacsclient and still have a lot of buffer opened. I want to quit emacsclient like I quit emacs (by closing every buffer). And when I start again emacsclient, I want a fresh emacs with no buffer opened. – ppr Dec 15 '13 at 22:24
-
If you want to quit emacs-client like emacs I do not understand why you use emacs-client at all. Then you could use emacs directly instead. – Tobias Dec 15 '13 at 23:04
-
I use emacsclient because the startup is a lot quicker than emacs. I'm on a very old computer... – ppr Dec 15 '13 at 23:09
-
But that is only the case when emacs is still running. Therefore, you have at least one frame with one window which shows a buffer. Maybe, the frame is iconified. – Tobias Dec 15 '13 at 23:30
-
No, I start `emacs --daemon` at the beginning of every session. I automatized this. – ppr Dec 15 '13 at 23:31
-
I don't think you can close the final frame without also quitting. If it's okay to leave one frame, then `C-x 5 1` is the ticket (perhaps with a wrapper to minimize and/or switch to the `*scratch*` buffer, or whatever). – tripleee Dec 16 '13 at 08:01
-
Closing the frames will not kill their associated buffers, though. Do you want to kill all file-visiting buffers as well? – tripleee Dec 16 '13 at 08:02
1
This seems to work acceptably. It will ask you if one of the buffers on the kill list has unsaved changes.
(defun close-all-other-buffers-and-frames ()
"Destroy all frames except this one, kill all buffers, display `*scratch*'."
(interactive)
(set-buffer "*scratch*")
(delete-other-frames)
(let ((l (buffer-list)) b)
(while l
(setq b (car l)
l (cdr l) )
(and (buffer-file-name b)
(kill-buffer b) ) ) ) )
I have a feeling the loop to kill buffers could be done more elegantly -- please suggest improvements!

tripleee
- 175,061
- 34
- 275
- 318
-
I have something similar in my edits (you can visit it and look if you want to adopt something from it). I dismissed it since I did not find a way to safely detect the last opened file which I wanted to keep open. (I wanted to call it in `find-file-hook`.) I also added `buffer-modified-p` and killed only buffers that were not modified. – Tobias Dec 16 '13 at 13:19