DesktopAid for (X)Emacs
What is it?
I got tired of opening XEmacs frames and loading a bunch of files whenever I started XEmacs so I created this little aid. When installed it will save your editing session when you quit (X)Emacs and reload it when you start your favorite editor again.
A DesktopAid session is made up of a list of the files you have open and the cursor positions in the buffers visiting the files. It also contains the list of frames you are using and which files are being displayed in those frames. A third element in the session is the file name history, i.e. the history you get when pressing [C-x] [C-f].
Besides the automagic loading and saving of the session when starting and stopping (X)Emacs, it is also possible to save the session at any other moment in time. This will enable you to have multiple session configurations, one for each project your working on for instance. It will be very easy to switch from one project to another because you only have to load the corresponding session after which all your files will be present again and you can continue working from where you left off.
I have been using this code for a few years now with my XEmacs 21.1. Some changes have been made over that period of time to improve and fix some of the features. I haven't, however, tested this with a version of Emacs. So if you find any bugs or have any suggestions for things to add the just let me know. How do you use it?
To make sure that (X)Emacs can find the desktopaid.elc file, you will have to add the following lines in your .emacs or .xemacs/init.el file:
(setq load-path (cons "<path-to-desktopaid.elc>/" load-path))
(autoload 'dta-hook-up "desktopaid.elc" "Desktop Aid" t)
You have to substitute <path-to-desktopaid.elc> by the directory in which you installed the compiled DesktopAid code (desktopaid.elc). If, in addition, you want to enable the automatic loading and saving of your editing session you will also have to add the next line:
(dta-hook-up)
When you start (X)Emacs, you will get asked to specify which session you want to restore. By just pressing [Enter] the session that was saved when you last exited (X)Emacs will be restored. You can of course choose any other previously saved session.
If you want to save your session at an intermediate stage then just execute M-x dta-save-session. You will be prompted to specify a name for the session file that you want to use. This file will be saved in the DesktopAid directory. I suggest to always append a .conf extension to these files to easily identify them.
There is a similar command to load a session, just execute M-x dta-load-session. It has the same behaviour as the session restoring when you start (X)Emacs.
The dta-switch-session function is a small variation of the load function. It also loads a new session but first kills all existing buffers so you can start with a clean sheet. Configuration
Some configuration of DesktopAid is possible. All the customizable values can be found in the Environment|Desktopaid customization group.
dta-cfg-dir
The directory in which the session files will be saved. Its default value is ~/.desktopaid. dta-default-cfg
The name of the default session file. This file is used to save the session when you exit (X)Emacs. It is also the file that is used when you restore a session without selecting a file name. Its default value is desktopaid.conf. dta-default-auto
When this option is enabled, then the dta-default-cfg variable will be automatically changed (and saved to your ~/.emacs file) whenever you load or save a session configuration. When you switch sessions using the dta-switch-session command, the current session will first be saved before loading the new one if this option is enabled. Conclusion: this option will make sure that the default configuration file is always the last one you used. dta-max-history-length
This is the number of elements from the history that will be saved into the session. If this value is nil then all elements will be saved. Its default value is 10.
