2

I use emacsclient to open files from my webrowser (pdfs, text files etc). When I'm done with the file, I know I need to close it with C-x # (server-edit); if I use C-x k (kill-buffer) I get a warning that the buffer still has a client. This happens frequently, and I'm tempted to advise kill-buffer to check for, and close, clients for the current buffer when called.

This seems obvious enough that there's probably a reason it's not the default - am I overlooking a problem this will create? What bad things could happen if I automatically close clients when killing a buffer?

(motivated by discussion of my answer to a related question on stack overflow)

  • Are you using emacsclient with the -n switch? I find doing so obviates the issue of "closing client connection." Perhaps not the "proper" solution, but it lets me edit buffers without ever seeing this warning which I can't grok. – Daniel Dec 22 '15 at 18:53
  • @Daniel no, I haven't been. I just read the manual for that, and I don't understand what it does. – Tyler Dec 22 '15 at 18:59
  • I'll make an answer for this because I think it's what you will want. – Daniel Dec 22 '15 at 19:04
3

For me, using emacsclient with the '-n' switch prevents me from getting the "no client connection" warning.

Invoking emacsclient file from the command line will open file in the current Emacs session. The command line from which you ran emacsclient will be waiting for the file to be closed by the server, and then terminate. You won't be able to execute additional commands until it does so.

If you would like to be able to continue executing commands after opening file, then use emacsclient -n file which tells emacsclient, "don't wait" after opening file, and continue processing. Emacsclient has nothing else to do, and so terminates.

For reference, if you already have a running Emacs session, but would like to open file in a new frame (or Window in most GUI lingo) use the -c switch: emacsclient -c file.

Mutually exclusive with -c is the -t switch: open a new session, but do so in the current terminal rather than a new frame (Window). Note, if you are in a non-GUI terminal, then -c and -t are equivalent.

Note that -n may be used with -t as well as -c.

Because my Emacs usage is only a single session, I don't benefit from the differentiation of "C-x/C-k" and "C-x/#". If I had multiple Emacs sessions then this would be a relevant warning and my workflow with emacsclient would probably change.

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.