I think the problem is that save-buffers-kill-emacs
asks that yes-or-no question. When you're asked that you must either answer yes or no or use C-g
to quit (in this case, quit exiting).
You could advise or redefine save-buffers-kill-emacs
to accommodate what you want. Or you could just define a command that you use after using C-g
to quit exiting.
That command would iterate over the unsaved buffers, asking you whether you want to delete an auto-save file. (Or if you always want to delete auto-save files for all unsaved buffers, the command would just do that.)
But something like this is what I'd suggest doing:
(add-to-list 'kill-emacs-query-functions #'my-confirm-kill-emacs)
(defun my-confirm-kill-emacs ()
"Get confirmation..."
(let ((bufs (cl-remove-if-not (lambda (buf)
(and (buffer-file-name buf)
(buffer-modified-p buf)))
(buffer-list)))
autosave-name)
(and bufs
(dolist (buf bufs)
(setq autosave-name (with-current-buffer buf (make-auto-save-file-name)))
(when (and (file-exists-p autosave-name)
(y-or-n-p (format "Delete autosave file `%s' " autosave-name)))
(delete-file autosave-name)
(message "File `%s' deleted" autosave-name) (sit-for 0.5)))))
t) ; Return non-nil so Emacs can quit.
(Be sure to test any such code in an Emacs session with files you don't really care about. ;-))
save-buffers-kill-terminal
or looking for hooks which get triggered when a frame is deleted, but that would require checks to see if there any other frames left and whether Emacs is running as a daemon.M-x recover-session
, mark one or more sessions withd
, and thenx
to execute andy
to confirm. Not exactly what the question asked, but searches for it may lead here :)