From 306fd0da682986b4f3b5462f3da04cbae7facf86 Mon Sep 17 00:00:00 2001 From: TEC Date: Sun, 23 Jan 2022 02:04:26 +0800 Subject: [PATCH] feat(tutorial): make load-page more fully-featured It now displays more information, and calls doom-tutorial--complete when trying to display past the end. --- modules/config/tutorial/autoload/tutorial.el | 55 +++++++++++++++----- 1 file changed, 41 insertions(+), 14 deletions(-) diff --git a/modules/config/tutorial/autoload/tutorial.el b/modules/config/tutorial/autoload/tutorial.el index 78bfd3fe1..d1a5d3781 100644 --- a/modules/config/tutorial/autoload/tutorial.el +++ b/modules/config/tutorial/autoload/tutorial.el @@ -142,20 +142,47 @@ (defvar doom-tutorial--test nil) (defun doom-tutorial-load-page (name &optional page) - (let ((content (nth (or (and page - (doom-tutorial--set-page name page)) - (doom-tutorial--current-page name)) - (plist-get (cdr (assoc name doom-tutorial--registered)) - :pages)))) - (let ((instructions (plist-get content :instructions)) - (title (plist-get content :title))) - (with-current-buffer doom-tutorial--instructions-buffer-name - (with-silent-modifications - (erase-buffer) - (insert ?\n) - (insert (cond - ((stringp instructions) instructions) - ((functionp instructions) (funcall instructions))))))) + "Load page PAGE of the tutorial NAME." + (let* ((page (or (and page + (doom-tutorial--set-page name page)) + (doom-tutorial--current-page name))) + (pages (length + (plist-get (cdr (assoc name doom-tutorial--registered)) + :pages))) + (content (nth page + (plist-get (cdr (assoc name doom-tutorial--registered)) + :pages)))) + (if (>= page pages) + (doom-tutorial--complete name) + (let ((instructions (or (plist-get content :instructions) "")) + (title (or (plist-get content :title) ""))) + (with-current-buffer doom-tutorial--instructions-buffer-name + (setq-local header-line-format + (concat + (propertize + (format "Instructions (%s/%s) " + (1+ page) pages) + 'face '(bold org-document-title)) + (propertize title 'face '(bold org-document-info)))) + (setq-local doom-tutorial--name name) + (setq-local doom-tutorial--test (plist-get content :test)) + (with-silent-modifications + (erase-buffer) + (insert ?\n) + (insert + (cond ((stringp instructions) instructions) + ((functionp instructions) (funcall instructions)))))))))) + +(defun doom-tutorial--complete (name) + (with-current-buffer doom-tutorial--instructions-buffer-name + (setq-local header-line-format + (propertize "Finished!" 'face '(bold org-document-title)))) + (setq-local doom-tutorial--test nil) + (with-silent-modifications + (erase-buffer) + (insert ?\n + (format "You have completed the %s tutorial!" name)))) +(plist-put (cdr (assoc name doom-tutorial--progress)) :complete t)) (defun doom-tutorial-last-page () (let* ((name (buffer-local-value