A more useful new feature that I'll discuss here, is emacs --daemon. Since many versions, you can set up emacs as an emacs-server. The idea is that you start one emacs instance (the 'server'), and you can then use emacsclient to quickly pop up a new emacs-frame (window). This new frame is not a new emacs instance, it's just a new frame (window) for the already-running emacs. The nice thing is that emacsclient is very quick - it doesn't need to parse all the startup packages or your 5000-line .emacs. You could activate it by putting (server-start) in your .emacs, or calling M-x server-start. I've been happily using that for years with mutt.
Those were happy years. Still, things could be better. Emacs-client/server had its limitations: first, an emacs could have graphical or console (tty) clients, but not both at the same time. Second, you always needed to start emacs in the foreground before you could use emacslient.
Both of these limitations have gone now -- hurray! You simply start emacs as:
$ emacs --daemonand it starts running in the background. After that, you can start emacs client frames (windows) using:
$ emacsclient -c. This will give you a graphical version when running X, or a terminal (console) version otherwise. If you want a terminal version even in windows-mode, use:
$ emacsclient -t. If you don't want the controlling terminal to wait for the emacsclient to finish, you can add the -n argument, so:
$ emacsclient -c -nand you can even specify an alternate editor if emacs is not yet running, so:
$ emacsclient -c -a nano # if all else fails...Of course, you can also start emacs itself as the 'alternate'.
Now, my new way to run emacs is a follows:
- I start emacs in the background (as daemon) when logging into X; this can be done automatically by adding to make emacs --daemon to your list of startup-programs. In GNOME, this can be set through the Preferences/Sessions/Startup Programs-menu. I am sure other environments have something similar. Alternatively, you could put emacs --daemon & in ~/.xinitrc.
- I fire up emacs frames (windows) with emacsclient -c (or emacsclient -t to run it in a console);
- That's it!
$ pkill -TERM -u $USER emacsMake sure you have no unsaved data, and no other emacsen running...
You also might want to set some influential environment variables in your .~/.bashrc, ~/.zshenv, ..., so other programs will automatically use an emacsclient when available; e.g.,
EDITOR="emacsclient -c" VISUAL="emacsclient -c"With emacs --daemon there's no longer any need to use vi for quick-editing some file. In other words: alias vi="emacsclient -c"...