I use Emacs as server instance.

When I start EMacs Client, he will check if the file .emacs.d/server/server exists. If not so, then he will initiating a Emacs server instance, and my Emacs configuration files will be loaded.

Then I start a new Emacs Client. He checks that the server-file already exists. The Emacs configuration will not be loaded again, but it will create a new frame instead, connected with the Emacs server instance. It loads really fast.

If I close the Emacs instance properly, the file server will be deleted. But sometimes my Emacs crashes (it happens a lot, because I configure my Emacs like a crazy, believe me).

Then I start Emacs client again, after killing it in Windows. He sees the Emacs server file already exists, but he cannot find the Emacs instance server, to create a frame from it.

So I decided to automatically delete the server-file, every time that Emacs file is being loaded (it's being loaded only when Emacs starts as server instance).

So I created the following:

(add-hook before-init-hook '(shell-command "c:/Dropbox/Sys/autohotkey/delete-server-file-emacs.ahk"))
(require 'server)
(unless (server-running-p)

This is an AHK-script, that deletes the server file every time when the Emacs configuration is being read.

When I start the Emacs instance, while the server file still in the folder, he still tries to read the server-file first, before execute the autohotkey script.

I stil got the message that there no connection from emacsclient could be made, because the target machine actively refused it. So that means he is reading the server file, that means that there is a Emacs instance as server to connect with it.

Any suggestion, in order to solve this?

  • Not sure about how it works on Windows, but on Unix systems, a file is often used in this way to back up a socket connection. I.e. programs use socket interface to read and write into some buffer, and that buffer is stored in a file. This is how databases typically work and other systems which need to secure the state of their communication even between crashes. So, if that file serves this purpose, instead of deleting it, I'd be looking into restarting the server, so that it could pick up from where it crashed instead.
    – wvxvw
    Commented Jun 6, 2015 at 10:24


Your Answer

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

Browse other questions tagged or ask your own question.