How to save current open sessions and buffers with Emacs?
(desktop-save-mode 1)
only saves if one opened buffer there
-
Could someone reconsider the presented link and the duplicated question? Reason: People landing here are probably willing to save all open files (i.e.: save all buffers), not necessarily willing to remember previously opened files. So, the link to the other answer is probably misleading. – Richard Gomes Jul 02 '17 at 21:16
-
Save all buffers: "C-x s" then press "!" – Richard Gomes Jul 02 '17 at 21:18
-
My answer here: https://stackoverflow.com/questions/44875692/how-do-i-save-all-files-or-save-all-buffers-in-emacs/44875693 – Richard Gomes Jul 02 '17 at 22:20
2 Answers
You could read more about it here: http://tsdh.wordpress.com/2006/11/26/conveniently-save-and-restore-frame-configuration/
In emacs you can split each frame in several windows. Such a configuration is called window configuration. The window configurations of all frames make a frame configuration. Here are some functions which let you save and restore such a frame configuration with only one key. First we define a register which will be used by default for saving the frame configuration:
(defparameter th-frame-config-register ?° "The register which is used for storing and restoring frame configurations by `th-save-frame-configuration' and `th-jump-to-register'.")
The next thing is the saving function. If you call it with a prefix arg you can choose a different register:
(defun th-save-frame-configuration (arg) "Stores the current frame configuration in register `th-frame-config-register'. If a prefix argument is given, you can choose which register to use." (interactive "P") (let ((register (if arg (read-char "Which register? ") th-frame-config-register))) (frame-configuration-to-register register) (message "Frame configuration saved in register '%c'." register)))
Now we need a function to restore a frame configuration. By default it uses th-frame-config-register, but with a prefix arg you can choose any register. (You can use this function not only for restoring frame configs, but for everything you can do with jump-to-register…)
(defun th-jump-to-register (arg) "Jumps to register `th-frame-config-register'. If a prefix argument is given, you can choose which register to jump to." (interactive "P") (let ((register (if arg (read-char "Which register? ") th-frame-config-register))) (jump-to-register register) (message "Jumped to register '%c'." register)))
Ok, the last thing we gotta do is create some key bindings. I chose F5 and F6:
(global-set-key (kbd "<F5>") 'th-save-frame-configuration) (global-set-key (kbd "<F6>") 'th-jump-to-register)
Now whenever you have a complex window/frame config press F5 to save it and press F6 to restore it.

- 3,260
- 5
- 33
- 57

- 20,643
- 17
- 103
- 160
Partial answer: to save all buffers run save-some-buffers (e.g. via the File menu "execute command" or more conveniently the M-x key combination) and then answer "!" to the first query (meaning save and don't ask again). If there's no such prompt then none of the buffers needed saving anyway.
As for "open sessions", if this means window layouts, split positions, etc then the question tripleee points to is useful. But that's doing more than the usual "save all" command in an editor.

- 882
- 8
- 18