Emacsclient keep buffers after closing

1.4k Views Asked by At

In emacsclient, is there a way to open a file from the command line such that its buffer will remain open on the server after I close the client?

Alternatively, is there a command I can run from in a client to tell it to effectively detach from a buffer, so that the buffer does not get killed when the client exits?

Normally when closing emacsclient either with C-x C-c or C-x #, the buffer(s) associated with that client get killed, which is usually convenient behavior, but sometimes I would like for buffers to stay alive after closing. So far the only way I have found to accomplish this is to run the client without specifying any files, then visit them with C-x C-f, but I'm wondering if there's a better way to do this.

3

There are 3 best solutions below

0
On BEST ANSWER

So, one option is to use emacsclient's eval command line option to run a lisp command to find the file you want.

emacsclient -c -e '(find-file "my_file")'

Obviously this is a lot more to type than the command sequence emacsclient -c, C-x C-f, my_file, but it could pretty easily be wrapped in a script that takes an extra argument to tell it whether to just choose the file or use find-file.

Someone more well versed in elisp than I could probably just add the option directly into emacs.

4
On

You should be able to do this by using the -n option. That means that it won't wait for you to "finish" the buffer and it'll just stay in the buffer list. I use this with emacsclient myself.

0
On

According the info manual, if you never want to kill emacsclient buffers, when you're done with them, you can customise the server-kill-new-buffers variable (more information at C-h v server-kill-new-buffers).

For you use-case, depending on how often you want the buffers killed or not, you could set the above variable to nil and then manually kill the buffers that you do want killed.