From: Lars Ingebrigtsen Date: Sat, 12 Dec 2020 12:46:33 +0000 (+0100) Subject: Offer to save tutorial position on Emacs exit X-Git-Tag: emacs-28.0.90~4760 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=e005095e4130f43c36d75ceac4c3202534f02704;p=emacs.git Offer to save tutorial position on Emacs exit * lisp/tutorial.el (tutorial--buffer): New variable (bug#27998). (tutorial--save-on-kill): Use it. (help-with-tutorial): Set it and add new function to kill-emacs-query-functions. --- diff --git a/lisp/tutorial.el b/lisp/tutorial.el index d07737e3332..ca84f86f289 100644 --- a/lisp/tutorial.el +++ b/lisp/tutorial.el @@ -50,6 +50,9 @@ "Tutorial language.") (make-variable-buffer-local 'tutorial--lang) +(defvar tutorial--buffer nil + "The selected tutorial buffer.") + (defun tutorial--describe-nonstandard-key (value) "Give more information about a changed key binding. This is used in `help-with-tutorial'. The information includes @@ -655,6 +658,15 @@ with some explanatory links." (unless (eq prop-val 'key-sequence) (delete-region prop-start prop-end)))))) +(defun tutorial--save-on-kill () + "Query the user about saving the tutorial when killing Emacs." + (when (buffer-live-p tutorial--buffer) + (with-current-buffer tutorial--buffer + (if (y-or-n-p "Save your position in the tutorial? ") + (tutorial--save-tutorial-to (tutorial--saved-file)) + (message "Tutorial position not saved")))) + t) + (defun tutorial--save-tutorial () "Save the tutorial buffer. This saves the part of the tutorial before and after the area @@ -802,6 +814,7 @@ Run the Viper tutorial? ")) ;; (Re)build the tutorial buffer if it is not ok (unless old-tut-is-ok (switch-to-buffer (get-buffer-create tut-buf-name)) + (setq tutorial--buffer (current-buffer)) ;; (unless old-tut-buf (text-mode)) (unless lang (error "Variable lang is nil")) (setq tutorial--lang lang) @@ -814,6 +827,7 @@ Run the Viper tutorial? ")) ;; a hook to save it when the buffer is killed. (setq buffer-auto-save-file-name nil) (add-hook 'kill-buffer-hook 'tutorial--save-tutorial nil t) + (add-hook 'kill-emacs-query-functions 'tutorial--save-on-kill) ;; Insert the tutorial. First offer to resume last tutorial ;; editing session.