I'm on MS Windows, if that makes a difference.

My desired behavior:

  1. There is only one frame visible at any time.
  2. Visiting a file should use an existing window in that frame.

(This is the default behavior for Notepad++ as well as most browsers, though with tabs instead of buffers.)

To accomplish this using Emacs' client-server mode, I have this in my .emacs:

(require 'server)
(unless (server-running-p) (server-start)) 

And I have an Edit with Emacs context menu item that uses a registry key with this value:

"C:\Users\FriendOfFred\emacs-26.2-x86_64\bin\emacsclientw.exe" "%1"

That worked fine yesterday. Today, after a system restart, emacsclientw opens a new frame whenever I open a file from Windows Explorer or the command line, along with a message about the desktop file already being in use.

Last time I had an issue like this, as I recall, it was because the desktop file was too old, and restarting Emacs refreshed it. That doesn't seem to be the issue now.

What are some other possible causes of this issue? How can I figure out what's going on?

1 Answer 1


along with a message about the desktop file already being in use

Emacsclient does not attempt to process the desktop file, so you are clearly starting a new instance of Emacs.

If emacsclient can't connect to the server, but you either passed it -a '' or --alternate-editor='' or else have the ALTERNATE_EDITOR environment variable set to an empty string, then it would try to start a new server and connect to that; so this is a potential explanation.

  • My ALTERNATE_EDITOR is set to runemacs.exe. When I run emacsclientw -a "", it still opens a new frame, now with the message "When done with a buffer, type C-x #" - and this new frame now works as expected, i.e. all new emacsclientw commands target it. Commented Sep 15, 2019 at 19:41
  • Oh, well that makes sense. ALTERNATE_EDITOR=runemacs.exe means "If there is no server, start a new non-daemon instance of Emacs". It will not make another attempt to connect a client in that scenario (there's no reason why it should expect that to be a valid course of action), so the behaviour you describe is exactly as expected.
    – phils
    Commented Sep 15, 2019 at 21:54
  • That doesn't explain why emacsclient isn't connecting to the server in the first place, though... Commented Sep 16, 2019 at 2:31
  • I'm assuming that's because no server is running. (Or if it's definitely running, make sure you haven't set a non-default server-name).
    – phils
    Commented Sep 16, 2019 at 3:12

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.