2

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.

zstewart
  • 2,093
  • 12
  • 24

3 Answers3

1

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.

  • This causes it to open in an existing client if I already have one open. I still want it to open in the terminal that I'm actually in. – zstewart Aug 11 '15 at 22:27
  • Oh, I think you need -t for that. HTH – Josephine Moeller Aug 11 '15 at 22:37
  • `-t` retains the problem of buffers dying when I close the client. `-t` and `-n` are mutually exclusive, but each has *some* of the properties I want. I want creating new frames from `-t` and detachable buffers from `-n`. – zstewart Aug 11 '15 at 22:54
  • `M-x report-emacs-bug` ? You can use `-n -c` with GUI Emacs, so I would expect to be able to use `-n -t` with terminal Emacs. – phils Aug 12 '15 at 00:24
1

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.

zstewart
  • 2,093
  • 12
  • 24
1

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.

aplaice
  • 164
  • 2
  • 7