I have a very modest init file for my Emacs configuration. Emacs is my main E-Mail client, my calendar, knowledge base, and it has a somewhat decent text editor as well. All of these features either needs to be configured, programmed, or be implemented with a pre-made package. I only have a handful of packages, and yet Emacs is taking longer and longer to start every time I want to do something with it.
For most users, myself included, this can become tedious if the intent is just to do a quick edit of a configuration file. I believe this leaves most users with a perpetually open Emacs instance running. However, are they unfortunate enough to close this instance, they will have to start the boot up process all over again.
Now, as some of you might already know, reading is a skill I have yet to master, so figuring out that all of this could be solved with a simple built-in solution was mind-boggling to me.
ENTER DAEMON
It turns out that Emacs can be run in what is called daemon mode. In other words, it runs as a server in the background, and the user then connects a client to that server. This turns out to be quite useful in more ways than one.
Example time:
To start Emacs in daemon mode, use the following command in a terminal:
# Starts the Emacs daemon.
emacs --daemon
You will see a bit of status text running through your terminal, and if all goes well you won't have any errors. So far, I have found out that as long as you can start Emacs regularly, this should go smoothly.
One thing you will notice though is that Emacs itself didn't show up. The terminal will have just reverted back to its regular prompt. So to connect to your Emacs server, you have to type in the following:
# Creates a new frame and connectes to the server.
emacsclient -nc
If you would rather use Emacs in the terminal:
# Connects to the server without using graphical resources.
emacsclient -nw
Blazingly fast!
There is another advantage to doing this. Usually when you close your instance of Emacs you would have to reopen all your buffers when you start Emacs again. With the daemon running in the background, your buffers will stay open the next time you connect.
Sometimes though, you need to restart Emacs completely. This could be for any number of reasons. Just use the command:
# In Emacs M-x
restart-emacs
Starting the daemon automatically when you log in is quite simple as well. Just stuff it into your profile, and it will attempt to start the daemon. If you attempt to start it more than once, it will simply tell you that another daemon is already running, but, to avoid going through the entire loading process you can check before you run:
# ~/.profile
if [ -n $(pgrep emacs) ] ; then
emacs --daemon
fi
I am one of those people who usually have an instance of Emacs running at all times, but now I am no longer afraid of closing it down in fear of the time it takes to start it up again. I hope you find this little tidbit as useful as I did.