From e5a9b268fe7534f0fc84d71207d885de2375a4f4 Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Fri, 19 Jan 2024 15:21:12 +0200 Subject: Refactor gnosis-review-note Simarly to gnosis-add-note recent changes, more extensible & flexible. This makes it easier to maintain & add new note types in the future. --- gnosis.el | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/gnosis.el b/gnosis.el index 83a0310..8dc05a5 100644 --- a/gnosis.el +++ b/gnosis.el @@ -998,18 +998,17 @@ Used to reveal all clozes left with `gnosis-face-cloze-unanswered' face." (defun gnosis-review-note (id) "Start review for note with value of id ID, if note is unsuspended." - (cond ((gnosis-suspended-p id) - (message "Note is suspended.")) - (t - (with-current-buffer (switch-to-buffer (get-buffer-create "*gnosis*")) - (let ((type (gnosis-get 'type 'notes `(= id ,id)))) - (gnosis-mode) - (pcase type - ("mcq" (gnosis-review-mcq id)) - ("basic" (gnosis-review-basic id)) - ("cloze" (gnosis-review-cloze id)) - ("y-or-n" (gnosis-review-y-or-n id)) - (_ (error "Malformed note type")))))))) + (when (gnosis-suspended-p id) + (message "Suspended note with id: %s" id) + (sit-for 0.3)) ;; this should only occur in testing/dev cases + (let* ((type (gnosis-get 'type 'notes `(= id ,id))) + (func-name (intern (format "gnosis-review-%s" (downcase type))))) + (if (fboundp func-name) + (progn + (with-current-buffer (switch-to-buffer (get-buffer-create "*gnosis*")) + (gnosis-mode) + (funcall func-name id))) + (error "Malformed note type: '%s'" type)))) (defun gnosis-review-commit (note-num) "Commit review session on git repository. -- cgit v1.2.3