Note that when you use emacsclient to edit a file, Emacs tells you to use C-x # to tell the server when you've finished with the file. If you do that (rather than C-x k), you won't be asked the question.
–
philsJun 19 '14 at 22:18

I don't know if it's appropriate for me to upvote this answer, but to the best of my knowledge it's correct, so :-)
–
ShreevatsaRNov 6 '08 at 16:31

2

This won't work if emacs was started using emacsclient's "ALTERNATE_EDITOR" Behavior... in that case you can do (defun server-remove-kill-buffer-hook () (remove-hook 'kill-buffer-query-functions 'server-kill-buffer-query-function)) (add-hook 'server-visit-hook 'server-remove-kill-buffer-hook)
–
Woodrow DouglassJan 30 '13 at 15:00

4

What's up with the * in that code snippet.
–
TshepangMay 26 '13 at 8:55

1

I'd be a bit careful with removing the hook. From the file "server.el": 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.
–
mzutherJan 17 at 17:41

For whatever reason, I have to manually launch the remove-hook solution on emacs23, perhaps because certain parts of the server are loaded after the .emacs is loaded. Adding a dummy (server-start) line to my .emacs before the (remove-hook ...) did not help. So I have opted for the following, less principled solution:

You should be able to use (eval-after-load "server" '(remove-hook ...)) to handle load order issues (although if the server library had not yet loaded, then your alias should get clobbered once it loads, so perhaps something else was messing with the hook after you had??)
–
philsMay 28 '13 at 1:48

While this does not help with other ways of killing buffers (such as M-x list-buffers), it should be on the safe side by respecting the Emacs client behavior that some shell scripts expect.

Here is an excerpt from the file server.el in your Emacs distribution that might shed a little light on what I mean:

;; When you finish editing a Server buffer, again call server-edit
;; to mark that buffer as done for the client and switch to the next
;; Server buffer. When all the buffers for a client have been edited
;; and exited with server-edit, the client "editor" will return
;; to the program that invoked it.

Later on, there is an explicit warning that a buffer shouldn't be killed, but released (at least this is how I interpret it):

;; 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.