How to remove the prompt for killing emacsclient buffers?

放肆的年华 提交于 2019-12-20 09:36:17

问题


After I open something with emacsclient, when I kill that buffer (C-x k) I get a confirmation dialog:

Buffer `blah' still has clients; kill it? (yes or no)

But when I kill buffers opened directly from Emacs I don't. Is there a way not to get them when emacsclient opened them?


回答1:


This worked for me:

(remove-hook 'kill-buffer-query-functions 'server-kill-buffer-query-function)

There's more information on Using Emacsclient blog entry.




回答2:


The other option is to use the -n option with emacsclient so that it doesn't wait for the file to be edited before exiting.

For example:

emacsclient -n myfile.txt



回答3:


You may set the keyboard command C-x k so that it marks client buffers as done and kills normal buffers.

I shamelessly stole this code snippet from the Emacs Client entry in the Emacs Wiki:

(add-hook 'server-switch-hook
      (lambda ()
        (when (current-local-map)
          (use-local-map (copy-keymap (current-local-map))))
        (when server-buffer-clients
          (local-set-key (kbd "C-x k") 'server-edit))))

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.



回答4:


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:

(defalias 'server-kill-buffer-query-function '(lambda () t))


来源:https://stackoverflow.com/questions/268088/how-to-remove-the-prompt-for-killing-emacsclient-buffers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!