1

I use Emacs 29.1.

When I open Emacsclient, I do it with the following command:

emacsclient -a -c --create-frame --no-wait

Then the situation: When I open Emacsclient, and visit a file foobar.txt. A buffer is created in the client.

To kill a Emacsclient window, I do it with 'M-x kill-frame' command.

But the buffer foobar.txt also disappear from the daemon. I want to retain the buffers, regardless of I close the frame or not. I want to remove buffers only with deleting buffers.

I want to keep the buffer foobar.txt, regardless if the client windows are open or not. The buffer foobar.txt should be staying in the Emacs daemon.

When looking for a solution, I found another this thread: Kill buffer when closing emacs with emacsclient

When checking server-kill-new-buffers, this is set on t.

I set this in Emacs client window on nil: enter image description here

Then I visit the file foobar.txt again, and close the Emacsclient.

When open another Emacsclient instance, I see the buffer foobar.txt is not saved in memory.

TLDR: How can I leave the buffers intact inside daemon, when closing the only Emacsclient window with kill-frame command?

I added a bounty to this question, because after 10 months this question doesn't still get solved.

5
  • stackoverflow.com/a/76968294/20212483 may help
    – shynur
    Commented Nov 13, 2023 at 4:43
  • Thanks for your comment. Unfortunately, this doesn't solve my issue since I open Emacsclient in other viewports than the current emacsclient, under a keybinding which opens a new Emacsclient window.
    – ReneFroger
    Commented Nov 13, 2023 at 12:33
  • I can't reproduce it: how do you see that the buffer is not saved in memory? BTW, you say "A buffer is created in the client": a buffer is never created in the client - it is always created in the running Emacs instance by the server. All the client does is send a command over - the rest is the server's business.
    – NickD
    Commented Oct 8 at 14:03
  • do you mean delete-frame? I don't see a kill-frame command
    – Tyler
    Commented Oct 9 at 18:20
  • I can't reproduce this problem either.
    – Tyler
    Commented Oct 9 at 18:23

2 Answers 2

1

We're still missing some details in your question. However, the command you're using:

emacsclient -a -c --create-frame --no-wait

Doesn't actually work as written. The -a flag requires an argument, which can be just "". And -c and --create-frame do the same thing, so you only need one of them. If you start Emacs this way:

emacsclient -a "" --create-frame --no-wait

when there's no emacs server/daemon already running a new one will be started (that's what -a "" does). The new server won't have any of the buffers from your last session available, since it's a fresh process.

If there is a running server, then the new client will have access to all the buffers in that server. But you note that you're killing client frames with kill-frame. There is no function named kill-frame. There is a function kill-emacs, which will kill not just the client frame, but the running server. If you use that command to kill your client, the next time you call emacsclient with the -a "" --create-frame arguments, you're actually starting a new server.

If that's the case, you should be able to resolve your problem by killing clients with delete-frame, which is bound to C-x 5 0 by default.

1
0

It turned out this behaviour was caused by Doom configuration, and not by Emacs ietself. I reported it here: https://github.com/doomemacs/doomemacs/issues/8150

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.