15

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)

AdrieanKhisbe
  • 3,899
  • 8
  • 37
  • 45
  • 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. – Randy Morris Sep 28 '13 at 20:46

6 Answers6

12

From the minibuffer, when emacsclient starts:

When done with a buffer, type C-x #

Robert Houghton
  • 1,202
  • 16
  • 28
Dolda2000
  • 25,216
  • 4
  • 51
  • 92
  • `C-x #` also kill the server when realised from the gui – AdrieanKhisbe Sep 28 '13 at 17:30
  • 4
    It certainly doesn't do that for me. – Dolda2000 Sep 28 '13 at 17:32
  • I know it's not supposed to. :/ What version are you using? – AdrieanKhisbe Sep 28 '13 at 17:33
  • Emacs 23.4.1 with Gtk (standard Debian version). – Dolda2000 Sep 28 '13 at 17:36
  • It works just as well with both `emacsclient -c` and `emacsclient -t`, by the way. – Dolda2000 Sep 28 '13 at 17:37
  • 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. – AdrieanKhisbe Sep 28 '13 at 17:41
  • Are you sure your server doesn't just segfault or something, rather than quits intentionally? – Dolda2000 Sep 28 '13 at 17:42
  • There is nothing on the stderr from the terminal I launched it (where are displayed init messages). Otherwise don't know how to check this – AdrieanKhisbe Sep 28 '13 at 17:47
  • 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). – Dolda2000 Sep 28 '13 at 17:49
  • after checking it's not a segfault, exitcode is 0. Also, nothing new with emacs24.3.1....either with or without config. – AdrieanKhisbe Sep 28 '13 at 18:17
  • Do you start your server by starting a regular Emacs process and then calling `server-start` in it, or with `emacs --daemon`? – Rörd Sep 28 '13 at 18:24
  • 2
    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. – Dolda2000 Sep 28 '13 at 19:24
  • 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... – AdrieanKhisbe Sep 28 '13 at 20:57
  • It sounds like you have some very specific bug or something and should ask on the Emacs mailing list or so instead. :) – Dolda2000 Sep 28 '13 at 22:25
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.

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.

Bleeding Fingers
  • 6,993
  • 7
  • 46
  • 74
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.

SamB
  • 9,039
  • 5
  • 49
  • 56
  • I even start it via systemd, as described at WikEmacs: http://wikemacs.org/wiki/Emacs_server#Adding_To_OS_Startup – MKesper Dec 15 '17 at 09:25
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.

Lei
  • 318
  • 1
  • 6
0

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

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

Jiacai Liu
  • 2,623
  • 2
  • 22
  • 42