3

I often use Emacs with Linux Manjaro and Gnome. I need straightforward access to Emacs from desktop. Therefore, I have pinned the Emacs icon to dash so I can launch Emacs by clicking the Emacs icon.

However, the Emacs icon does not activate (has no dot below) while an activated Emacsclient icon pops up in the dash.

screen copy

I don't like this. How to make Emacs run from a single icon just like any desktop application?

Emacs does run:

alba@mac2011-manjaro% ps -u alba|tail -5
  19713 ?        00:00:00 python3
  19754 ?        00:00:00 obexd
  20336 ?        00:00:01 emacs
  20377 pts/1    00:00:00 ps
  20378 pts/1    00:00:00 tail

Emacsclient does not run:

alba@mac2011-manjaro% ps -u alba|grep client

(empty output)

Files corresponding to the desktop icons:

alba@mac2011-manjaro% cat /usr/share/applications/emacs.desktop
[Desktop Entry]
Name=Emacs
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=emacs %F
Icon=emacs
Type=Application
Terminal=false
Categories=Development;TextEditor;
StartupNotify=true
StartupWMClass=Emacs
alba@mac2011-manjaro% cat /usr/share/applications/emacsclient.desktop
[Desktop Entry]
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=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;
StartupNotify=true
StartupWMClass=Emacs
Keywords=emacsclient;
Actions=new-window;new-instance;

[Desktop Action new-window]
Name=New Window
Exec=/usr/bin/emacsclient --alternate-editor= --create-frame %F

[Desktop Action new-instance]
Name=New Instance
Exec=emacs %F
5
  • Did you compile your own emacs or was it installed via your distros packages?
    – g-gundam
    Commented Mar 3, 2023 at 1:18
  • 1
    I don't use emacsclient, but in some Linux flavors it is possible to create a custom desktop launcher file with either a command line, or a path to a script. For example, in Debian or Ubuntu, the file would be created at /usr/share/applications/my_custom_emacs_launcher.desktop. If there is a command-line that works for you, then perhaps you could create a custom launcher that does what you want. The Exec portion of the desktop file is what controls the custom command line or path to a script containing whatever is desired. And, of course, you can set the path to the desired icon.
    – lawlist
    Commented Mar 3, 2023 at 2:52
  • 1
    (1) Please remove the last paragraph. One problem per post, please. (2) Please make the title more specific: "Just like any desktop application" is unclear and too general. Thx.
    – Drew
    Commented Mar 3, 2023 at 4:52
  • This Emacs is a Manjaro package. I have tried also Emacs from Flatpak, it does not have this problem but has other problems. Commented Mar 4, 2023 at 15:10
  • Yes, one problem per post. So I have removed the other problem. Let me keep as comment that I tried to use only the emacsclient icon. It almosts works, except that emacsclient does not load my init file. Commented Mar 4, 2023 at 15:18

2 Answers 2

2

I have a solution based on comments. Since for some unclear reason starting Emacs activates the Emacsclient icon, an idea was to use directly the Emacsclient icon, with the difficulty that Emacsclient does not load the init file.

Emacsclient can be forced to load the init file by preventing it from connecting to any existing Emacs process that can be used as server.

Kill all Emacs processes:

alba@mac2011-manjaro% ps -u alba|grep emacs
   3121 ?        00:00:01 emacs
alba@mac2011-manjaro% kill -9 3121

If Emacs runs as a systemd service, systemd will create a new Emacs automatically. (Check if the Emacs service is on with systemctl --user status emacs.service.)

Stop the Emacs service:

alba@mac2011-manjaro% systemctl --user stop emacs.service

(This choice can be made persistent across session with systemctl --user disable emacs.service.)

A command that works (starts Emacsclient and loads the init file) is emacsclient --alternate-editor=emacs --create-frame: as Emacsclient does not find a server (for all the previous killing), it calls emacs, which loads the init file.

Copy /usr/share/applications/emacsclient.desktop to ~/.local/share/aplications and add emacs after each occurence of --alternate-editor=.

(To check that the newly created ~/.local/share/aplications/emacsclient.desktop is effective, change the icon name to some absurd value like Icon=emacssss and, after a dew seconds, no need to relog, the Emacsclient gnu icon is replaced by a generic icon.)

Use Emacsclient instead of Emacs.

1

Just like this:

sudo rm /usr/share/applications/emacsclient.desktop

(Tested today with Emacs from the Ubuntuhandbook PPA, Ubuntu 22.04.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.