----

Hi, a suggestion for this page.  Start with the big picture -- why would one want to run emacs in a daemon?  I landed on this page first in google trying to answer that question, and couldn't find it here.  I suggest putting an intro with something along the lines of:

http://devblog.avdi.org/2011/10/27/running-emacs-as-a-server-emacs-reboot-15/

Shawn 
shawn (at) weirdness (dot) com

-- realscrappy 2014-05-12 18:58 UTC


----

"After that, using emacsclient (or emacsclient -t) will automatically start an emacs in daemon mode and connect to it if one is not found running, and sane programs will know to run emacsclient to start an editor."

This point is debatable, and so makes the "Simple setup" misleading:

If the emacs daemon isn't started, either by `emacs --daemon`, or by `M-x server-start` in emacs, then plenty of sane programs -- for instance, most bash shells -- will not start an editor. They will output, `emacsclient: can't find socket; have you started the server?`.

-- joseph8th 2016-01-19 03:43 UTC


----

In the section ''[https://www.emacswiki.org/emacs/EmacsAsDaemon#toc3 Starting Emacs Daemon with systemd/CentOS]'', with

{{{
ExecStart=/usr/bin/emacs --daemon --user %u
...
User=%i
}}}

I get emacs running as ##emacs --daemon --user root##. If I replace ##ExecStart=/usr/bin/emacs --daemon --user %u## with ##ExecStart=/usr/bin/emacs --daemon --user %i## then I get ##emacs --daemon --user arch## as desired. Is it a typo on the wiki page or an issue with my configuration?

-- ArchStanton 2019-06-06 14:50 UTC


----

https://www.freedesktop.org/software/systemd/man/systemd.unit.html#Specifiers says 

{{{
"%i"	Instance name	For instantiated units this is the string between the first "@" character and the type suffix. Empty for non-instantiated units.
"%u"	User name	This is the name of the user running the service manager instance. In case of the system manager this resolves to "root".
}}}

So I'm guessing ##--user %i## is the right thing.

-- npostavs 2019-06-07 11:54 UTC


----

It seems that emacs built with gtk can not save things like recentf files when poweroff machine, see
https://emacs.stackexchange.com/questions/16567/emacs-cant-save-history-of-recent-visited-files-opened-in-current-session-befor
and
https://emacs.stackexchange.com/questions/55528/make-emacs-systemd-service-kill-when-logging-out-shutting-down/60754#60754
Solutions I have found is either
a. do the save manually.
b. add things like this to your .emacs 
(run-at-time (current-time) 300 'recentf-save-list)(from https://emacs.stackexchange.com/questions/55528/make-emacs-systemd-service-kill-when-logging-out-shutting-down/60754#60754)
c. don't bulid emacs with gtk.  As for me, on Gentoo, it is to enable useflag "motif" and disable useflag "athena" "gtk" "Xaw3d".

-- C-Entropy 2020-10-14 12:42 UTC


----

In the Stopping the Daemon, what does the `emacsclient -e '(client-save-kill-emacs)` do compared to running `emacsclient -c -e '(save-buffers-kill-emacs)'`.

As a newcomer a while back I was looking for something that did what `emacsclient -c -e '(save-buffers-kill-emacs)'` does but when I saw that function I thought I had best wait until I became more experienced.

In the mean time, I did `emacsclient -c` and ran `M-x save-buffers-kill-emacs RET`.

I feel `save-buffers-kill-emacs` would be worth mentioning on this page too.

-- [https://philippe-carphin.ca pcarphin] 2021-03-03 03:44 UTC


----

The following link is dead: http://cubiclemuses.com/cm/articles/2009/08/06/emacs-and-os-x-launchd/

-- Anonymous 2021-08-03 15:34 UTC


----

In the section '''Emacs daemon as a service on Wayland''', I would suggest to add at the end a third snippet, and/or replace in the text, the "Requires" by "Wants" to start the emacs server anyway.
This allow to merge both cases (KDE, GNome) with a single snippet, and show how to do it globally (in the emacs.service) with multiple compositors.
{{{
[Unit]
Wants=plasma-kwin_wayland.service
Wants=org.gnome.Shell@wayland.service
After=plasma-kwin_wayland.service org.gnome.Shell@wayland.service
}}}

-- Anonyme 2023-10-18 13:14 UTC


----

I think this is really what we want for a unified service unit:

<code>
[Unit]
After=plasma-kwin_wayland.service org.gnome.Shell@wayland.service
</code>

Otherwise, it will try to launch the whole graphical environment (unless you systemct isolate) when you try to login to a text tty, as emacs will start, and then try to launch the desktop environments (I suspect trying to launch both of them will lead to even more issues).

Just having the "After=" line makes it do the right thing in all three cases (including just starting in text mode if there is no graphics server available).

-- Anonymous 2024-01-05 22:25 UTC

