我不止一次因意外杀死Emacs中的临时缓冲区而丢失了工作。当我杀死与文件无关的缓冲区时,我可以设置Emacs给我一个警告吗?
答案 0 :(得分:10)
创建一个函数,询问您是否确定缓冲区何时被编辑且与文件无关。然后将该函数添加到列表kill-buffer-query-functions
。
查看您了解的Buffer File Name文档:
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)
答案 1 :(得分:1)
(defun maybe-kill-buffer ()
(if (and (not buffer-file-name)
(buffer-modified-p))
;; buffer is not visiting a file
(y-or-n-p (format "Buffer %s has been edited. Kill it anyway? "
(buffer-name)))
t))
(add-to-list 'kill-buffer-query-functions 'maybe-kill-buffer)