A few years ago, I mentioned indirectly that I use emacs-server
. For some time, I just had (emacs-server)
in my init.el
. This, however, had an annoying side effect of giving an error when I started a second instance of Emacs. (I do this from time to time, e.g. when I fiddle with my config, to check whether the changes in init.el
made in the “main” instance of Emacs are working.) Then I changed it to
(ignore-errors (emacs-server))
which didn’t really matter, since what (emacs-server)
issues is a warning, not an error. Finally, I decided to do something better about it. I changed my invocation of emacs-server
to something like this.
(require 'server) (unless (server-running-p) (server-start))
Actually, this is not the whole story. In the rare case I have two Emacsen running at the same time, I usually treat one of them as temporary. Why not make this fact more prominent? At the same time, quitting the “temporary” one can (and should) be easier. So I installed this.
(require 'server) (if (server-running-p) (load-theme 'green-phosphor t) (setq confirm-kill-emacs #'yes-or-no-p) (server-start) (global-set-key (kbd "C-x C-3") 'server-edit))
I installed a second color theme just so the temporary Emacs can look very different, and I deliberately chose a venomous one. (Don’t get me wrong, I like green; when I play a boardgame, I choose green pieces whenever I can, since it’s my favorite color. But an intense green instead of something more subdued is probably not the best choice for your editor.) Also, I moved (setq confirm-kill-emacs #'yes-or-no-p)
and (global-set-key (kbd "C-x C-3") 'server-edit)
into the else-branch of the if
so that they are activated only in my main Emacs. (By the way, I’ve had a setup where Emacs is started automatically after I log in for quite a few years now. It doesn’t make much sense to turn on a computer without starting the OS, right? )