How to close a emacsclient gui frame without killing the server
Asked Answered
N

6

16

How do you close an emacsclient frame without killing the server/daemon?

Doing C-x C-c or C-x 5 0 in the gui will exit both frame and server (and other clients), while this just quit the current frame when done from terminal.

(Ps: My emacs version is 24.2,gtk. I've tried without init-file to see if it was coming from my config, but results were the same)

Noiseless answered 28/9, 2013 at 17:16 Comment(1)
For a long time I had issues with the gtk builds of emacs and switched to another toolkit. The folks in the #emacs channel on freenode noted that this is a long standing bug somewhere in gtk that causes the server to crash. Try a build using the lucid toolkit.Triecious
I
12

From the minibuffer, when emacsclient starts:

When done with a buffer, type C-x #

Inwardly answered 28/9, 2013 at 17:19 Comment(14)
C-x # also kill the server when realised from the guiNoiseless
It certainly doesn't do that for me.Inwardly
I know it's not supposed to. :/ What version are you using?Noiseless
Emacs 23.4.1 with Gtk (standard Debian version).Inwardly
It works just as well with both emacsclient -c and emacsclient -t, by the way.Inwardly
it work perfectly with emacsclient -t, but not emacsclient -c. (was implying this with terminal/gui) Gonna try with the last version from ppa:cassou/emacs.Noiseless
Are you sure your server doesn't just segfault or something, rather than quits intentionally?Inwardly
There is nothing on the stderr from the terminal I launched it (where are displayed init messages). Otherwise don't know how to check thisNoiseless
A segfaulting program normally wouldn't print anything on stderr. However, most shells should normally inform you if a foreground process terminates on a signal (other than SIGINT, at least).Inwardly
after checking it's not a segfault, exitcode is 0. Also, nothing new with emacs24.3.1....either with or without config.Noiseless
Do you start your server by starting a regular Emacs process and then calling server-start in it, or with emacs --daemon?Acaulescent
By calling server-start in a regular process. However, it works just as well if I start a server with emacs --daemon. EDIT: In fact, even C-x C-c works for exiting just the client without terminating the daemon.Inwardly
after some testing, it happens that for some unknow reason, this will "work" if an other client is "visible" when closing the gui client. (in a tmux terminal). don't ask me why...Noiseless
It sounds like you have some very specific bug or something and should ask on the Emacs mailing list or so instead. :)Inwardly
H
6

I think the key point here is you need to start the server in daemon mode. If the server runs in an existing emacs process - for instance if you have (server-start) in your init file - the server dies with the emacs process.

There are a couple of ways of starting the server in daemon mode:

  • call emacs with the --daemon command line option
  • call emacsclient with the --alternate-editor="" command line option, which will in effect run emacs --daemon for you then attempt to connect to it

Once you have the server in daemon mode, you should be able to close any frames and the daemon will continue to sit and wait for further connections.

Heckman answered 1/11, 2013 at 14:1 Comment(0)
P
4

Starting the emacsclient with -n/--no-wait flag will:

Don't wait for the server to return

You won't need to close the client in that case.

And if you have to a close emacsclient just kill the buffer the server will remain intact.

Pero answered 28/9, 2013 at 17:29 Comment(0)
B
2

Because you ran (server-start) from an existing frame, that frame is not an emacsclient frame, and closing the last such frame evidently gets the same treatment as C-x C-c: it will exit Emacs.

If you used emacs --daemon, possibly using the ALTERNATE_EDITOR='' trick, you would not have this problem; you could just use emacsclient -n -c to open a GUI frame, and after closing it the daemon would just sit around waiting for you to open a new frame, whether graphical or terminal-based.

Botulinus answered 7/7, 2014 at 3:25 Comment(1)
I even start it via systemd, as described at WikEmacs: wikemacs.org/wiki/Emacs_server#Adding_To_OS_StartupUnselfish
E
1

I am using both Debian with i3, and OSX. I usually exit emacsclient GUI frame by the window manager's close window shortcut. For example, in OSX, I use "Command + w" to close the client GUI frame without killing the server, and in i3, I use "Super + Shift + q" (the default close window by i3) to exit the client frame.

Eamon answered 2/6, 2014 at 19:18 Comment(0)
S
0

In modern version GNU Emacs(27+), it says

When done with this frame, type C-x 5 0

Stayathome answered 6/11, 2021 at 1:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.