我不止一次因意外杀死Emacs中的临时缓冲区而丢失了工作.当我杀死与文件无关的缓冲区时,我可以设置Emacs给我一个警告吗?
创建一个函数,询问您是否确定缓冲区何时被编辑且与文件无关.然后将该函数添加到列表中kill-buffer-query-functions
.
查看缓冲区文件名的文档,您了解:
当且仅当变量buffer-file-name
为nil时,缓冲区才访问文件
使用该洞察力来编写函数:
(defun maybe-kill-buffer ()
(if (and (not buffer-file-name)
(buffer-modified-p))
;; buffer is not visiting a file
(y-or-n-p "This buffer is not visiting a file but has been edited. Kill it anyway? ")
t))
然后将函数添加到钩子中,如下所示:
(add-to-list 'kill-buffer-query-functions 'maybe-kill-buffer)