如何在emacs中自动关闭自动加密模式缓冲区?

时间:2013-03-06 18:24:01

标签: emacs gnupg

我将一些东西放在'XXX.gpg'文件中,我用emacs自动加密模式阅读和编辑。

在某些情况下,我忘了长时间关闭缓冲区,这是一种风险。

我想在一段时间(不活动)后自动保存和关闭缓冲区。

3 个答案:

答案 0 :(得分:2)

您可以使用run-with-idle-timer构建一个完全符合您想要的功能。

答案 1 :(得分:1)

这就是我使用的:

(defun dwim-kill-gpg-buffers ()
  (interactive)
  (let ((buffers-killed 0))
    (dolist (buffer (buffer-list))
      (with-current-buffer buffer
        (when (string-match ".*\.gpg$" (buffer-name buffer))
          (let ((current-time (second (current-time)))
                (last-displayed-time (second buffer-display-time)))
            (when (> (- current-time last-displayed-time)
                     60)
              (message "Auto killing .gpg buffer '%s'" (buffer-name buffer))
              (when (buffer-modified-p buffer)
                (save-buffer))
              (kill-buffer buffer)
              (incf buffers-killed))))))
    (unless (zerop buffers-killed)
      (message "%s .gpg buffers have been autosaved and killed" buffers-killed))))

(run-with-idle-timer 60 t 'dwim-kill-gpg-buffers)

它尝试不关闭最近显示的缓冲区,因此只要有视图切换活动,就会延迟杀死缓冲区。

答案 2 :(得分:0)

现在我在〜/ .emacs:

中使用它
(run-with-idle-timer 60 t (lambda ()
                         (let ((victim (get-buffer "XXX.gpg")))
                           (when victim (message "Killing buffer %s" (buffer-name victim)
                                                 (kill-buffer victim))))))