How to remove the prompt for killing emacsclient buffers?

后端 未结 4 745
借酒劲吻你
借酒劲吻你 2021-02-01 17:53

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)


        
相关标签:
4条回答
  • 2021-02-01 18:23

    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))
    
    0 讨论(0)
  • 2021-02-01 18:30

    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.
    
    0 讨论(0)
  • 2021-02-01 18:33

    This worked for me:

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

    There's more information on Using Emacsclient blog entry.

    0 讨论(0)
  • 2021-02-01 18:37

    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
    
    0 讨论(0)
提交回复
热议问题