I run Emacs through the

emacs --daemon

command, which sets up a socket file /tmp/emacs100/server for emacsclient to communicate through. When I kill the server as:

emacsclient --eval "(kill-emacs)"

the socket file remains, preventing me from running emacs --daemon again. The same thing happens when I try M-x kill-emacs from inside Emacs. Alternatively, when I try:

M-x server-force-delete

From within Emacs, I get a message saying:

No connection file "/tmp/emacs1000/server

Any ideas what is going wrong? How do I start and shut down the emacs server smoothly?

  • What version of emacs, on what operating system? Do you have the same problem if you start Emacs with emacs -q --daemon? – Gilles 'SO- stop being evil' Aug 16 '10 at 8:19
  • This is version 23.1.1, on Ubuntu 10.04. I don't have this problem when working with emacs -q, I just noticed. I'll need to check my init files again. Thanks for the heads up! – Karthik Aug 20 '10 at 4:04
  • I have the same problem. I've traced the problem to a line in server force delete that calls (delete-file "/tmp/emacs1000/server"). D'oh. I just realized that I have set delete-by-moving-to-trash to true, which means that it is trying and failing to put the server socket file in my trash bin, because it's not a regular file. If this is the same problem as you are having, I will post a solution shortly that will allow you to keep trash mode on but avoid this problem. – Ryan C. Thompson Feb 5 '11 at 20:30

i encountered the same problem, apparently

(setq delete-by-moving-to-trash nil)

fix this...

  • Thank you, this works. It makes no sense, but it works! – Karthik Oct 1 '10 at 12:37

I'm running emacs 23.1.1 and I simply have this line in my .emacs

;; Start Emacs server

and I have never had a problem with sticky socket files.

And emacsclient works nicely.


You don't have to disable the trash globally. Just disable it inside each command that might delete the server file. First define a macro as a shortcut for disabling trash inside a function:

(defmacro bypass-trash-in-function (fun)
  "Set FUN to always use normal deletion, and never trash.

Specifically, the value of `delete-by-moving-to-trash' will be
set to nil inside FUN, so any deletions that happen inside FUN or
any functions called by it will bypass the trash."
  `(defadvice ,fun (around no-trash activate)
     "Ignore `delete-by-moving-to-trash' inside this function.

See `bypass-trash-in-function' for more information."
     (let (delete-by-moving-to-trash)

Then apply that macro to each of the three server functions that have delete-file anywhere in their body:

;; Any server function that may delete the server file should never
;; move it to trash instead.
(mapc (lambda (fun) (eval `(bypass-trash-in-function ,fun)))
      '(server-start server-sentinel server-force-delete))

Now you can set delete-by-moving-to-trash to anything you like.

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.