I have a problem connecting to my emacs daemon. Here is the situation : I am on nixos I have an emacs-29.1 daemon running with "emacs-29.1 --daemon" as a user service. Here is the output of systemctl --user status emacs.service :

    ● emacs.service - Emacs: the extensible, self-documenting text editor
     Loaded: loaded (/etc/systemd/user/emacs.service; enabled; preset: enabled)
     Active: activating (start) since Wed 2023-10-18 13:40:34 CEST; 23s ago
      Cntrl PID: 38419 (emacs)
      Tasks: 2 (limit: 37048)
     Memory: 118.5M
        CPU: 2.811s
     CGroup: /user.slice/user-1000.slice/[email protected]/app.slice/emacs.service
             ├─38419 /nix/store/5y4cbsar66ajyqx69mi8a77sdm6zah02-emacs-29.1/bin/emacs --daemon
             └─38420 /nix/store/5y4cbsar66ajyqx69mi8a77sdm6zah02-emacs-29.1/bin/emacs --daemon
oct 18 13:40:34 VS-thinkpad systemd[1392]: Starting Emacs: the extensible, self-documenting text editor...
oct 18 13:40:36 VS-thinkpad bash[38420]: tsc-dyn-get: Using source :github (:loaded nil :recorded 0.18.0 :requested 0.18.0)
oct 18 13:40:36 VS-thinkpad bash[38420]: tsc-dyn-get: Recorded version already satifies requested -> loading
oct 18 13:40:36 VS-thinkpad bash[38420]: tree-sitter-langs: Grammar bundle v0.12.49 was already installed; skipped

This indicates me that the daemon is correctly running and in the correct version. I then try to connect with emacsclient -c but here is the output :

emacsclient: can't find socket; have you started the server?
emacsclient: To start the server in Emacs, type "M-x server-start".
emacsclient: No socket or alternate editor.  Please use:

--server-file      (or environment variable EMACS_SERVER_FILE)
--alternate-editor (or environment variable ALTERNATE_EDITOR)

Note that emacsclient --version outputs : emacsclient 29.1

I have tried to find the socket-name and found it with C-h v : server-socket-dir. I ran the emacsclient providing it with the socket but it does not exist when emacs is not running (with emacs).

Do you have any idea what could be the problem ?

EDIT : output of emacs --daemon in the terminal

tsc-dyn-get: Using source :github (:loaded nil :recorded 0.18.0 :requested 0.18.0)
tsc-dyn-get: Recorded version already satifies requested -> loading
tree-sitter-langs: Grammar bundle v0.12.49 was already installed; skipped

Note : even with emacs --daemon started, emacsclient -c cannot connect to it. I have the same output as above.

  • The daemon may have problems starting the server. What happens if you start an interactive emacs without --daemon and then try to start the server manually with M-x server-start? If there are problems with that, fix them and then try the daemon invocation again.
    – NickD
    Oct 18, 2023 at 12:42
  • @NickD it says "Restarting server" and then I can connect to the daemon with emacsclient -c and it works without any issues.
    – Virgil
    Oct 18, 2023 at 13:31
  • Try adding (server-start) at the end of your init file. That might convince the daemon to start it even if it had trouble initially. Ultimately you'll have to debug it to get to the root of the problem, but that might be a reasonable workaround for now.
    – NickD
    Oct 18, 2023 at 15:00
  • What output do you get when you invoke emacs --daemon from a terminal ? Oct 19, 2023 at 10:55
  • 1
    It appears that the command terminates properly. I had issues with Tree-sitter when I went from Emacs 28 to Emacs 29. The emacs --daemon command stopped when it reached the Tree-sitter config (maybe related to the fact that Tree-sitter became built-in). Try removing your Tree-sitter configuration to see if it is the culprit. Oct 19, 2023 at 12:30

1 Answer 1



Using tree-sitter in the config file caused the issue. Removing it fixed the problem.

EDIT : I believe I found how to use the built-in tree-sitter and not crashing the daemon thanks to the official page of the module (https://emacs-tree-sitter.github.io/) provided in the comments by @Tristan_Riehs

To enable tree-sitter without disturbing the daemon I use :

(add-hook 'tree-sitter-after-on-hook #'tree-sitter-hl-mode)
  • Can you elaborate on "using tree-sitter in the config file" please? That seems like you've narrowed the issue down further, but I think it's safe to say that people using tree-sitter shouldn't have the problem you were having.
    – phils
    Oct 20, 2023 at 1:51
  • If github.com/emacs-tree-sitter/elisp-tree-sitter is the tree-sitter support you were using, then it might be worth discussing it in their issue queue.
    – phils
    Oct 20, 2023 at 1:53
  • @phils the tree-sitter I was using is tree-sitter.el (which I believe is the native one)
    – Virgil
    Oct 20, 2023 at 12:24
  • @phils I am using doom emacs and even tho I can enable the tree-sitter module without problem in the init.el file. Configuring it in config.el (even adding hooks) was causing the issue.
    – Virgil
    Oct 20, 2023 at 12:26
  • Sounds more like github.com/emacs-tree-sitter/elisp-tree-sitter/tree/master/lisp -- but you can simply visit the library inside Emacs and see whether it's in your config or part of the core Emacs install.
    – phils
    Oct 20, 2023 at 12:53

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.