Emacs: re-run buffers from last session on startup?

Every day I run emacs and open the same files that I opened the day before. Is there something I can add to the init.el file so that it reopens all the buffers that I used when I last left emacs?

+66
emacs
Apr 29 '09 at 19:09
source share
7 answers

You can use the Emacs Desktop library :

You can save the desktop manually using the Mx desktop-save command. You can also let it automatically save when you exit Emacs and automatically restore the last saved desktop when you start Emacs: use the settings buffer (see Easy Settings) to set desktop-save-mode to t for future sessions or add this line to your File ~ / .emacs:

(desktop-save-mode 1) 
+89
Apr 29 '09 at 19:13
source share

Although I suspect that the question was looking for emacs desktop functionality (see answer above), the Lewap approach can be useful if the set of files that you use is really the same set of files. In fact, you can take another step and define β€œprofiles” if you have different sets of regularly used files ... Quickie example:

 (let ((profile (read-from-minibuffer "Choose a profile (acad,dist,lisp,comp,rpg): ") )) (cond ((string-match "acad" profile) (dired "/home/thomp/acad") (dired "/home/thomp/acad/papers") ) ((string-match "lisp" profile) (setup-slime) (lisp-miscellany) (open-lisp-dirs) ) ((string-match "rpg" profile) (find-file "/home/thomp/comp/lisp/rp-geneval/README") (dired "/home/thomp/comp/lisp/rp-geneval/rp-geneval") ... etc. 

If you find that during work you regularly switch between different sets of regularly used files, consider using a perspective and filling out each perspective with the right set of regularly used files.

+10
Jun 05 '09 at 20:28
source share

To store / restore buffers / tabs (in particular, screens): I use elscreen and a way to control the storage / restoration of a desktop session, and the elscreen tab setting is the following code in mine. emacs (the names used are self-explanatory, and if the save / restore functions should not be executed every time emacs starts just commenting the lines with "(push # 'elscreen-store kill-emacs-hook)" and "(elscreen -restore)" ):

 (defvar emacs-configuration-directory "~/.emacs.d/" "The directory where the emacs configuration files are stored.") (defvar elscreen-tab-configuration-store-filename (concat emacs-configuration-directory ".elscreen") "The file where the elscreen tab configuration is stored.") (defun elscreen-store () "Store the elscreen tab configuration." (interactive) (if (desktop-save emacs-configuration-directory) (with-temp-file elscreen-tab-configuration-store-filename (insert (prin1-to-string (elscreen-get-screen-to-name-alist)))))) (push #'elscreen-store kill-emacs-hook) (defun elscreen-restore () "Restore the elscreen tab configuration." (interactive) (if (desktop-read) (let ((screens (reverse (read (with-temp-buffer (insert-file-contents elscreen-tab-configuration-store-filename) (buffer-string)))))) (while screens (setq screen (car (car screens))) (setq buffers (split-string (cdr (car screens)) ":")) (if (eq screen 0) (switch-to-buffer (car buffers)) (elscreen-find-and-goto-by-buffer (car buffers) tt)) (while (cdr buffers) (switch-to-buffer-other-window (car (cdr buffers))) (setq buffers (cdr buffers))) (setq screens (cdr screens)))))) (elscreen-restore) 
+5
Dec 04
source share

You can open files in a .emacs file using the following function:

(find-file "/ home / me / path-to-file")

+2
Apr 29 '09 at 19:18
source share

There are useful improvements you can make to the main desktop feature. Particularly convenient (IMO) methods are to automatically save the desktop during a session, because otherwise, if your system crashes, you will be stuck with the desktop file from which you started this session - it is rather annoying if you are prone to Maintain Emacs for many days at a time.

http://www.emacswiki.org/emacs/DeskTop

The wiki also has useful information about persisting data between sessions in general:

http://www.emacswiki.org/emacs/SessionManagement

For desktop computers in particular, I thought Desktop Recover looked especially promising, however I haven't tried it yet.

+2
Jul 15 '10 at 22:15
source share
+1
Apr 29 '09 at 19:12
source share

(find-file-noselect "/my/file") will open it silently, i.e. without raising the buffer. Just saying it.

EDIT This command is not interactive; To verify this, you must evaluate the expression, for example, by positioning the cursor after the last bracket and pressing Cx Ce

Fine-tuning is not cool; this team is definitely working and is in the realm of question.

0
Dec 03 '11 at 2:27
source share



All Articles