の使用を追加するために編集されましたbuffers-offer-save
。注: この変数はEmacsを終了buffer-offer-save
するときにのみ使用されます。
このコードから始めて、必要に応じてカスタマイズできます。
(add-to-list 'kill-buffer-query-functions 'ask-me-first)
(defun ask-me-first ()
"prompt when killing a buffer"
(if (or buffer-offer-save
(eq this-command 'kill-this-buffer)
(and (buffer-modified-p) (not (buffer-file-name))))
(y-or-n-p (format "Do you want to kill %s without saving? " (buffer-name)))
t))
さらによく考えてみると、これは少し面倒です。なぜなら、削除されたすべてのバッファーについてプロンプトが表示され、Emacs が使用する一時バッファーが大量にあることがよくあるからです。(ファイルに関連付けられていない) バッファーを対話的に削除しようとしたときにプロンプトを表示したい場合。
対話的にバッファーを強制終了しようとしているときにのみ表示されるこのアドバイスを使用できます。
(defadvice kill-buffer (around kill-buffer-ask-first activate)
"if called interactively, prompt before killing"
(if (and (or buffer-offer-save (interactive-p))
(buffer-modified-p)
(not (buffer-file-name)))
(let ((answ (completing-read
(format "Buffer '%s' modified and not associated with a file, what do you want to do? (k)ill (s)ave (a)bort? " (buffer-name))
'("k" "s" "a")
nil
t)))
(when (cond ((string-match answ "k")
;; kill
t)
((string-match answ "s")
;; write then kill
(call-interactively 'write-file)
t)
(nil))
ad-do-it)
t)
;; not prompting, just do it
ad-do-it))