我不止一次因为意外杀死 Emacs 中的临时缓冲区而失去工作。我可以设置 Emacs 在我终止与文件无关的缓冲区时给我一个警告吗?
jsulak
问问题
365 次
2 回答
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)
于 2008-09-17T20:07:39.860 回答
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)
于 2008-09-17T20:29:00.573 回答