From: Peter Oliver <p.d.oliver@mavit.org.uk>
To: 49195@debbugs.gnu.org
Subject: bug#49195: Starting Emacs if required from emacsclient.desktop
Date: Wed, 23 Jun 2021 20:59:31 +0100 (BST) [thread overview]
Message-ID: <c7e5066-2818-cf15-8e3b-e4c6af9354f4@froglet.home.mavit.org.uk> (raw)
[-- Attachment #1: Type: text/plain, Size: 720 bytes --]
At present, we provide emacs.desktop (which starts a new instance of Emacs), and emacsclient.desktop (which connects to an existing instance of Emacs). This is problematic if a users wants to associate a particular file type with Emacs in their desktop file manager, because they can’t know in advance which will be correct.
Attached is a patch which enhances emacsclient.desktop so that it will start a new instance of Emacs if none is found to be running. Users who like to reuse an existing Emacs can then always use emacsclient.desktop.
There was some discussion of how far to go with this on emacs-devel recently, but, if I understand correctly, the parts in this patch were not controversial.
--
Peter Oliver
[-- Attachment #2: Type: text/plain, Size: 4017 bytes --]
From 374c2b202dd8276506eaf2ed51edc946beebefcd Mon Sep 17 00:00:00 2001
From: Peter Oliver <git@mavit.org.uk>
Date: Tue, 8 Jun 2021 16:04:17 +0100
Subject: [PATCH] From .desktop files, reuse a frame or start a new Emacs as
required
* doc/emacs/misc.texi: (Using Emacs as a Server) Explain emacsclient.desktop.
* etc/NEWS: (Emacs Server): Explain emacsclient.desktop.
* emacs-mail.desktop, etc/emacsclient.desktop: Automatically try to
reuse an existing frame, open a new frame, or start a new Emacs
daemon. Add actions for specific behaviours.
---
doc/emacs/misc.texi | 5 +++++
etc/NEWS | 5 +++++
etc/emacs-mail.desktop | 16 +++++++++++++---
etc/emacsclient.desktop | 11 ++++++++++-
4 files changed, 33 insertions(+), 4 deletions(-)
diff --git a/doc/emacs/misc.texi b/doc/emacs/misc.texi
index 027133cc3a..2beedd6f5a 100644
--- a/doc/emacs/misc.texi
+++ b/doc/emacs/misc.texi
@@ -1757,6 +1757,11 @@ Emacs Server
@code{3}. (If there is no server with that name, an error is
signaled.) Currently, this feature is mainly useful for developers.
+ If you launch Emacs from a desktop environment, you may use the
+@dfn{Emacs (Client)} menu entry to connect to an Emacs server with
+@command{emacsclient}. If the daemon is not already running, it will
+be started for you.
+
@menu
* TCP Emacs server:: Listening to a TCP socket.
* Invoking emacsclient:: Connecting to the Emacs server.
diff --git a/etc/NEWS b/etc/NEWS
index 64b39d737a..02473257e2 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -539,6 +539,11 @@ an edit instead of marking it as "Done" (which the 'C-x #' command
does). The 'emacsclient' program exits with an abnormal status as
result of this command.
++++
+*** New desktop integration for connecting to the server.
+You may use the "Emacs (Client)" menu entry to open files in an
+existing Emacs instance rather than starting a new one.
+
** Perl mode
---
diff --git a/etc/emacs-mail.desktop b/etc/emacs-mail.desktop
index 0c5fab1dd1..251afa100c 100644
--- a/etc/emacs-mail.desktop
+++ b/etc/emacs-mail.desktop
@@ -1,12 +1,22 @@
[Desktop Entry]
Categories=Network;Email;
Comment=GNU Emacs is an extensible, customizable text editor - and more
-Exec=emacs -f message-mailto %u
-# If you prefer to use emacsclient, use this instead
-#Exec=emacsclient -e '(message-mailto "%u")'
Icon=emacs
Name=Emacs (Mail)
MimeType=x-scheme-handler/mailto;
NoDisplay=false
Terminal=false
Type=Application
+
+Exec=emacs -f message-mailto %u
+# # If you prefer to use emacsclient, use this instead:
+# Exec=sh -c 'emacsclient --alternate-editor= --display="$DISPLAY" --eval "(message-mailto \"%u\")"'
+# Actions=new-window;new-instance;
+
+# [Desktop Action new-window]
+# Name=New Window
+# Exec=emacsclient --alternate-editor= --create-frame --eval '(message-mailto "%u")'
+
+# [Desktop Action new-instance]
+# Name=New Instance
+# Exec=emacs -f message-mailto %u
diff --git a/etc/emacsclient.desktop b/etc/emacsclient.desktop
index 3feb83c729..43f2c31ddd 100644
--- a/etc/emacsclient.desktop
+++ b/etc/emacsclient.desktop
@@ -3,10 +3,19 @@ Name=Emacs (Client)
GenericName=Text Editor
Comment=Edit text
MimeType=text/english;text/plain;text/x-makefile;text/x-c++hdr;text/x-c++src;text/x-chdr;text/x-csrc;text/x-java;text/x-moc;text/x-pascal;text/x-tcl;text/x-tex;application/x-shellscript;text/x-c;text/x-c++;
-Exec=emacsclient -c %F
+Exec=sh -c 'if [ -n "$*" ]; then exec emacsclient --alternate-editor= --display="$DISPLAY" "$@"; else exec emacsclient --alternate-editor= --create-frame; fi' placeholder %F
Icon=emacs
Type=Application
Terminal=false
Categories=Development;TextEditor;
StartupWMClass=Emacsd
Keywords=Text;Editor;
+Actions=new-window;new-instance;
+
+[Desktop Action new-instance]
+Name=New Window
+Exec=emacsclient --alternate-editor= --create-frame %F
+
+[Desktop Action new-instance]
+Name=New Instance
+Exec=emacs %F
--
2.31.1
next reply other threads:[~2021-06-23 19:59 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-06-23 19:59 Peter Oliver [this message]
2021-06-24 6:07 ` bug#49195: Starting Emacs if required from emacsclient.desktop Eli Zaretskii
2021-06-24 13:28 ` Peter Oliver
2021-06-24 14:22 ` Eli Zaretskii
2021-06-24 15:50 ` Peter Oliver
2021-06-30 13:12 ` Lars Ingebrigtsen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=c7e5066-2818-cf15-8e3b-e4c6af9354f4@froglet.home.mavit.org.uk \
--to=p.d.oliver@mavit.org.uk \
--cc=49195@debbugs.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.