7

I am starting the emacs server using

systemctl --now --user enable emacs

That server is running, if I run

systemctl --user status emacs

I got

$ systemctl --user status emacs
● emacs.service - Emacs text editor
   Loaded: loaded (/usr/local/lib/systemd/user/emacs.service; enabled; vendor preset: enabled)
   Active: active (running) since Sat 2018-06-09 09:27:56 CDT; 2 days ago
     Docs: info:emacs
           man:emacs(1)
           https://gnu.org/software/emacs/
 Main PID: 17613 (emacs)
   CGroup: /user.slice/user-1000.slice/user@1000.service/emacs.service
           └─17613 /usr/local/bin/emacs --fg-daemon

But, when I try to connect using emacsclient -c some_file.py

I got

$ emacsclient -t .psqlrc
emacsclient: can't find socket; have you started the server?
To start the server in Emacs, type "M-x server-start".

What am I missing?

EDIT:

Following the advice of @Tobias I ran

$ sudo netstat -xauopen | grep emacs

And the result was the following:

unix  3      [ ]         STREAM     CONNECTED     61841    17982/emacs          
unix  3      [ ]         STREAM     CONNECTED     62269    17982/emacs          
unix  3      [ ]         STREAM     CONNECTED     62268    17982/emacs   

I was expecting see more information, but this doesn't seem right. What is happening?

  • Please add which emacs version you are running. – Tobias Jun 11 '18 at 22:34
  • GNU Emacs 27.0.50 – nanounanue Jun 12 '18 at 15:51
  • You also need to pass the --now option to systemctl --user enable emacs or you additionally need to run systemctl --user start emacs. But I assume that you already did something like that because of the run-status of emacs. – Tobias Jun 15 '18 at 13:38
  • Yup, but still I no luck connecting to it :( – nanounanue Jun 15 '18 at 17:11
  • I added --now to the options. – Tobias Jun 15 '18 at 17:21
1

I'm using 24-25 emacs version as daemon.

 cat /etc/systemd/user/emacs.service

 [Unit]
 Description=Emacs: the extensible, self-documenting text editor

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

 [Install]
 WantedBy=default.target

With 26.1+ add options --fg-daemon and --bg-daemon. Try old --daemon alias --bg-daemon fork unit. Maybe work.

Also add to emacsclient -a '' -t.

  • I tried the --bg and --fg options and no luck. See the comments thread in the question for more info – nanounanue Jun 19 '18 at 15:39
0

I'm having the same issue. I came up with a script to start emacsclient that is working fine for me:

#!/bin/sh

SOCKET=/tmp/emacs$UID/server
PARAMS="--socket-name=$SOCKET"

if [[ $TMUX || $SSH_CLIENT ]]
then
    PARAMS+=" -t"
else
    PARAMS+=" -c"
fi

exec /usr/bin/emacsclient $PARAMS "$@"

Unfortunately, this doesn't seem to be the best solution since it won't fix launching emacsclient directly (either in commandline or in the desktop file). However, I have a key shortcut to launch it using the script.

  • Alternatively, based on stackoverflow.com/a/28553846/1815486, you can use SOCKET=$(lsof -c emacs | grep $USER | grep server | grep STREAM | awk '{print $9}') to find it regardless of where it is (in case you've set it elsewhere) – aiguofer Nov 30 '18 at 17:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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