如何在杀死Emacs中的临时缓冲区之前收到警告?

时间:2008-09-17 19:55:30

标签: emacs

我不止一次因意外杀死Emacs中的临时缓冲区而丢失了工作。当我杀死与文件无关的缓冲区时,我可以设置Emacs给我一个警告吗?

2 个答案:

答案 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)