commit:     ee79082103da7e8090136b6ef4867bff7ddf5521
Author:     Ulrich Müller <ulm <AT> gentoo <DOT> org>
AuthorDate: Fri Mar  7 17:12:24 2025 +0000
Commit:     Ulrich Müller <ulm <AT> gentoo <DOT> org>
CommitDate: Fri Mar  7 17:12:24 2025 +0000
URL:        https://gitweb.gentoo.org/proj/emacs-tools.git/commit/?id=ee790821

Add user initd file for OpenRC

* emacs.initd: New file. Merged version of the user initd file
attached to bug 950671 and emacs.rc from the emacs-daemon package.
Thanks to Anna (navi) Figueiredo Gomes.
* Makefile (DISTFILES): Add it.

Bug: https://bugs.gentoo.org/950671
Signed-off-by: Anna (navi) Figueiredo Gomes <navi <AT> vlhl.dev>
Signed-off-by: Ulrich Müller <ulm <AT> gentoo.org>

 ChangeLog   |  5 +++++
 Makefile    |  7 ++++---
 emacs.initd | 29 +++++++++++++++++++++++++++++
 3 files changed, 38 insertions(+), 3 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 565945f..53d2f73 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 2025-03-07  Ulrich Müller  <[email protected]>
 
+       * emacs.initd: New file. Merged version of the user initd file
+       attached to bug 950671 and emacs.rc from the emacs-daemon package.
+       Thanks to Anna (navi) Figueiredo Gomes.
+       * Makefile (DISTFILES): Add it.
+
        * emacsclient.desktop (MimeType): Add org-protocol, from Emacs 30.
        Bug 950674.
 

diff --git a/Makefile b/Makefile
index 65da9b7..9a4fbac 100644
--- a/Makefile
+++ b/Makefile
@@ -1,4 +1,4 @@
-# Copyright 2007-2023 Gentoo Authors
+# Copyright 2007-2025 Gentoo Authors
 # Distributed under the terms of the GNU General Public License v2 or later
 
 PN = emacs-common
@@ -14,8 +14,9 @@ ICONFILES = sink.png \
        emacs25_16.png emacs25_24.png emacs25_32.png emacs25_48.png \
        emacs25_128.png emacs25.svg
 GSCHEMAFILES = org.gnu.emacs.defaults.gschema.xml
-DISTFILES = site-start.el site-gentoo.el subdirs.el.in $(DESKTOPFILES) \
-       $(addprefix icons/,COPYRIGHT.icons $(ICONFILES)) $(GSCHEMAFILES)
+DISTFILES = site-start.el site-gentoo.el subdirs.el.in emacs.initd \
+       $(DESKTOPFILES) $(addprefix icons/,COPYRIGHT.icons $(ICONFILES)) \
+       $(GSCHEMAFILES)
 
 
 .PHONY: all dist clean $(DESKTOPFILES)

diff --git a/emacs.initd b/emacs.initd
new file mode 100644
index 0000000..f71b4c2
--- /dev/null
+++ b/emacs.initd
@@ -0,0 +1,29 @@
+#!/sbin/openrc-run
+# Copyright 2008-2025 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2 or later
+
+: ${EMACS:=/usr/bin/emacs}
+
+description="Start an Emacs server running in the background"
+
+supervisor=supervise-daemon
+command="${EMACS}"
+command_args="${EMACS_OPTS}"
+command_args_foreground="--fg-daemon"
+
+depend() {
+    after dbus
+}
+
+start_pre() {
+    # EMACS could be a microemacs variant that ignores the -batch option
+    # and would therefore hang, waiting for user interaction.
+    # Redirecting stdin and unsetting TERM and DISPLAY will cause most
+    # of them to exit with an error.
+    local has_daemon=$(unset TERM DISPLAY; ${EMACS} -batch -q --no-site-file \
+        --eval "(princ (fboundp 'daemonp))" </dev/null)
+    if [ "${has_daemon}" != t ]; then
+        eerror "${EMACS} does not support running as a daemon"
+        return 1
+    fi
+}

Reply via email to