我使用emacsclient打开文件后,当我关闭这个buffer(C-x k)时,会弹出确认对话框:
Buffer `blah' still has clients; kill it? (yes or no)
但是,当我关闭直接从Emacs打开的缓冲区时,这种情况就不会发生。是否有一种方法可以在emacsclient打开它们时不获取它们?
我使用emacsclient打开文件后,当我关闭这个buffer(C-x k)时,会弹出确认对话框:
Buffer `blah' still has clients; kill it? (yes or no)
但是,当我关闭直接从Emacs打开的缓冲区时,这种情况就不会发生。是否有一种方法可以在emacsclient打开它们时不获取它们?
emacsclient
的-n
选项,这样它在退出之前不必等待文件被编辑。emacsclient -n myfile.txt
这个对我有用:
(remove-hook 'kill-buffer-query-functions 'server-kill-buffer-query-function)
在使用Emacsclient博客文章中有更多信息。
在杀死服务器缓冲区之前询问。有人建议释放其客户端,但我认为这很危险--客户端将继续使用该文件中磁盘上的任何内容。-- rms.
- mzuther(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))))
M-x list-buffers
),但它应该在尊重Emacs客户端行为方面保持安全,以满足一些shell脚本的期望。;; 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.
后面有一个明确的警告,不应该杀死缓冲区,而是释放它(至少我是这样理解的):
;; 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.
如果你正在使用C-x #
退出客户端返回终端,我有一些技巧可以避免提示:
(defun cxa/yes-never-no (&rest _args)
"Override `y-or-n-p' to always retrun t."
t)
(defun cxa/yes-then-restore (orig-fun &rest args)
"Make `y-or-n-p' always return t before ORIG-FUN, and restore after applied ARGS."
(advice-add 'y-or-n-p :override 'cxa/yes-never-no)
(apply orig-fun args)
(advice-remove 'y-or-n-p 'cxa/yes-never-no))
(advice-add 'server-done :around 'cxa/yes-then-restore)
(defalias 'server-kill-buffer-query-function '(lambda () t))
(eval-after-load "server" '(remove-hook ...))
来处理加载顺序问题(尽管如果服务器库尚未加载,则一旦它加载,您的别名就会被覆盖,因此可能是其他东西在您之后干扰了钩子?) - philsserver-start
期间添加,因此在库加载后无法立即删除。看起来您可以在server-start
上使用after-advice,或者使用server-visit-hook
(在这种情况下,代码可能会重复运行,但在这种情况下不是问题)。 - phils
C-x#
来告诉服务器您何时完成文件的编辑。如果您这样做(而不是使用C-x k
),则不会询问您是否要保存文件。 - phils