2

When running emacs in daemon with a client and I hit C-x k, it says: Emacs buffer still has clients. Are you sure you want to quit?

But when using C-x #, it exits immediately.

I don't understand the difference. Why doesn't C-x k just behave normally in the first place, if its in a client?

I found this snippet that's supposed to make C-x k behave properly but I don't understand the difference.

Furthermore, when an emacs client starts up, it starts with the previous buffer for a few seconds then opens up the new buffer. Isn't the point of emacs server to speed up the initial start up time? Why does it do this / how can I fix it? On initial load, it starts with scratch for a few seconds.

darksky
  • 20,411
  • 61
  • 165
  • 254
  • How long is "a few seconds"? I can't tell if you're exaggerating, or if you genuinely mean you're looking at the previous buffer for multiple seconds before you see the buffer you want. Are you starting GUI clients or terminal clients? Is either one faster than the other? Is the time delay significantly longer than it takes to load files from within Emacs? If you open a file in the client, close it with `C-x #` and then re-open the same file in a new client, is the second time faster than the first? – phils Jan 23 '14 at 22:23
  • And if you have the `*Messages*` buffer visible in one client window while you open a file in a new client, do you see any activity other than the message to type `C-x #` when you're done with the buffer? – phils Jan 23 '14 at 22:28
  • It almost sounds like you are not leaving one `emacs` process running to be the server. So whenever `emacsclient` launches it first needs to launch `emacs`. Am I wrong? Because whenever I invoke `emacsclient` the emacs process I have running has the buffer up and ready for me to use. This means I do _NOT_ get an editing session in the shell where I invoked `emacsclient`. – Sean Perry Jan 24 '14 at 21:40
  • @phils No, I am waiting 4 - 5 seconds for it to show up. When I re-open the same file, it opens quickly only if it was the last open file. If I had another buffer opened first, it will open that buffer, wait 3-4 seconds then switch to the new buffer that I want, making it as slow as regular emacs without the server/daemon/client. – darksky Jan 25 '14 at 20:28
  • It rather sounds like the delay is in *finding* the file. Is it also slow to use `C-x C-f` to find a file from a running Emacs instance? (If so, then your problem isn't with emacsclient). You should also check whether things are any different if you run `emacs -Q --daemon` – phils Sep 12 '14 at 09:01

2 Answers2

5

I can't write a better explanation of C-x# than Emacs already gives you. Just type C-hkC-x#

I assume that C-xk warns you because you're not using the mechanism for telling the client explicitly that you're done, and as you might be trying to kill the buffer from any Emacs frame (and unless you're running Emacs as a daemon, there are going to be non-client frames), it makes sure you're aware that the buffer is associated with a client somewhere.

The query itself comes from server-kill-buffer-query-function which is added to kill-buffer-query-functions, and probably has no way of telling where the kill was issued from. It has the following comments:

;; Ask before killing a server buffer.
;; It was suggested to release its client instead,
;; but I think that is dangerous--the client would proceed
;; using whatever is on disk in that file. -- rms.
phils
  • 71,335
  • 11
  • 153
  • 198
  • Got it. What about the `scratch` issue? With that, emacsclient takes as much time as emacs to load, making it useless. – darksky Jan 23 '14 at 21:16
2

Basically C-x k kills a buffer and C-x # notifies the emacs server that you are done editing and that the client may exit. Kind of like killing a process with kill or exiting it correctly.

Sean Perry
  • 3,776
  • 1
  • 19
  • 31
  • Got it. What about the `scratch` issue? With that, emacsclient takes as much time as emacs to load, making it useless. – darksky Jan 23 '14 at 20:25