1

I've installed Emacs 26.2 using snap on Lubuntu 18.04. I'm trying to figure out how to get the server/client/daemon going.

I've done as instructed on EmacsWiki: "Emacs Client" by putting (server-start) in .emacs.el.

I've followed the examples on EmacsWiki: "Emacs as Daemon" by putting this in ~/.config/systemd/user/emacs.service:

[Unit]
Description=Emacs text editor
Documentation=info:emacs man:emacs(1) https://gnu.org/software/emacs/

[Service]
Type=forking
ExecStart=/usr/bin/emacs --daemon
ExecStop=/usr/bin/emacsclient --eval "(kill-emacs)"
Environment=SSH_AUTH_SOCK=%t/keyring/ssh
Restart=on-failure

[Install]
WantedBy=default.target

When I tried to enable the unit by running:

systemctl enable --user emacs
systemctl start --user emacs

I got an error message about where Emacs lives on my filesystem, so I substituted /usr/ with /snap/. I restarted my system (don't know if that was necessary, or if merely logging out and back in again would have been sufficient) and looked at my process list to see that /snap/emacs/45/usr/bin/emacs --daemon is indeed there, so I figure all is well. An entry for Emacs (Client) has appeared below the original Emacs one in my launcher (though not with the right icon, but that's trivial).

Crucial questions

  1. Is that pretty much all there is to it, or is there anything I should change?

  2. How do I actually run Emacs now? When I click on Emacs (Client) in the launcher, the pointer whirls for a bit and then stops. No window shows up.

Definitely not crucial, but just because I'm curious

  1. Where did the launcher get the actual text Emacs (Client) from?

  2. If I do decide to change the icon, how do I do so?


Responding to @alpaice

Freshly rebooted, ran htop and found two processes: /snap/emacs/45/usr/bin/emacs --daemon. I tried $ emacsclient -c .profile and it came up beautifully! I've tested couple of other things, like opening a file from the file browser (PCManFM) while an Emacs Client frame is already open. I discovered that I had to use "Open With..." once and choose "Emacs (Client)" which worked fine. I then right-clicked a different file and saw that PCManFM had added "Emacs (Client)" to the list (clever thing).

Unfortunately, this didn't work when there wasn't already an Emacs frame open. Much icon whirling, then nothing. I'm wondering if perhaps a bash script might be needed to determine if a frame is already open. My knowledge of bash is next to nothing, but I'm currently trying to learn it.

I didn't know about unsquashfs. Thanks, I'll add it to my reading list.

Thank you for your help!

1
  • I'm not certain how stackexchange comments notifications work exactly, so I'm not sure if you were notified about my edited comment or whether it worked.
    – aplaice
    Commented Jul 21, 2019 at 23:34

1 Answer 1

0

Only a partial answer.

1.

I don't think that there's anything else that you need to do. There are other ways of getting there (e.g. with export ALTERNTATE_EDITOR='' in your ~/.profile, which would mean that Emacs would only start when needed, not always on startup) but it should be sufficient.

2.

Does running, say, emacsclient -c foobar, in a terminal, open an emacs window? If that doesn't work, does /snap/bin/emacs in a terminal, start a new Emacs instance?

3. and 4.

Regarding the Emacs (Client) text, I have no idea — I downloaded the emacs snap with snap download emacs and "unsquashed it" with unsquashfs, but I can't find the text anywhere...

Does right-clicking on the entry and checking its properties help?


That seems to suggests that Emacs is correctly installed, but the .desktop file responsible for the "Emacs (Client)" item is incorrectly configured. The crucial question (which you already asked) is where that item came from.

In general, such menu items are governed by .desktop files. For instance, there should be a file at /usr/share/applications/pcmanfm.desktop (pcmanfm chosen semi-randomly because it's likely to be installed on a Lubuntu system). The format is relatively straightforward. There's a line stating the name of the application (Name=), another specifying the icon (Icon=), yet another one, usually much further down specifying what should be executed when the relevant program is "started" — e.g. with "Open with" or from the launcher — (Exec=). %u, %f etc. in the Exec= line represent the name of the file that's passed to the program when you use "Open with", in various formats.

Unfortunately, the only .desktop files that are bundled with the Emacs snap are:

/snap/emacs/current/meta/gui/emacs.desktop
/snap/emacs/current/usr/share/applications/emacs.desktop
/snap/emacs/current/usr/share/emacs/26.2/etc/emacs.desktop

and none of them contains a line of the form Name=Emacs (Client) or anything similar (they do contain Name=Emacs but that's not quite what we want). Hence, presumably something else created the emacs client .desktop file.

If you right-click on the "Emacs (Client)" item in your launcher (if it's the standard lubuntu launcher), and then click on "Properties", does it tell you what the "Target file" is? If you manage to find the target file, it probably has a line with something like Exec=emacslient %something (where something might be F or something else). If you change emacsclient to emacsclient -c then a new Emacs window ("frame") should be opened every time you use "Emacs (Client)". If that's annoying, you can, as you mentioned, write a bash script (e.g. see here) and use the location of that bash script in the Exec= line (remember to keep the %something at the end).

If right-clicking doesn't help, then you could try searching for the .desktop file. For example:

locate emacs | grep '\.desktop$' | xargs grep Client

(locate lists all paths containing the given string (here emacs), grep searches the text piped into it, for the given regular expression (here \.desktop$), and xargs grep searches the file paths piped into it for the given regular expression (here Client).

I didn't know about unsquashfs. Thanks, I'll add it to my reading list.

I used unsquashfs to inspect the contents of the "snap" without installing it (I prefer not to frequently install and uninstall software on my main system in the (very unlikely) case that it has some pre-/post-install hooks that might affect my system configuration.) Since you have the Emacs snap already installed, you don't need it — you can inspect the snap's files at /snap/emacs/current/.

2
  • (response appended to original post)
    – granti128
    Commented Jul 19, 2019 at 0:36
  • Added further answer (hope it helps).
    – aplaice
    Commented Jul 19, 2019 at 10:31

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.