feat(tutorial): add progress save/loading

This commit is contained in:
TEC 2022-01-23 00:27:11 +08:00 committed by Jeetaditya Chatterjee
parent 474d7d4212
commit 18046fa543
No known key found for this signature in database
GPG key ID: 4A1E5568BA34D124

View file

@ -1,5 +1,36 @@
;;; config/tutorial/autoload/tutorial.el -*- lexical-binding: t; -*-
(defvar doom-tutorial-hist-file
(expand-file-name "tutorial-progress.el" doom-cache-dir)
"Directory where tutorial progress information is saved.")
(defvar doom-tutorial--progress
(when (file-exists-p doom-tutorial-hist-file)
(with-temp-buffer
(insert-file-contents doom-tutorial-hist-file)
(read (current-buffer))))
"An alist of tutorials and progress information.")
(defun doom-tutorial--save-progress ()
"Write `doom-tutorial--progress' to `doom-tutorial-hist-file'."
(with-temp-buffer
(insert
";; -*- mode: emacs-lisp -*-\n"
";; Tutorial progress file, automatically generated by `doom-tutorial--save-progress'.\n"
"\n")
(let ((print-length nil)
(print-level nil)
(print-quoted t))
(prin1 doom-tutorial--progress
(current-buffer)))
(insert ?\n)
(condition-case err
(write-region (point-min) (point-max) doom-tutorial-hist-file nil
(unless (called-interactively-p 'interactive) 'quiet))
(file-error
(lwarn '(doom-tutorial-hist-file) :warning "Error writing `%s': %s"
doom-tutorial-hist-file (caddr err))))))
;;;###autoload
(defun take-the-tutorial! ()
"Tutorial entry point."