>From b95a90cbecdf4fa2f47079eed08d2395f2700d41 Mon Sep 17 00:00:00 2001 From: stardiviner Date: Sun, 27 Jan 2019 10:43:37 +0800 Subject: [PATCH] org-drill.el: Add feature let org-drill auto pronounce * contrib/lisp/org-drill.el (org-drill-entry, org-drill-entry-before-hook, org-drill-entry-after-hook): Add two hooks around ~org-drill-entry~. (org-drill-auto-pronounce): option to toggle this functionality. (org-drill-pronounce-command,org-drill-pronounce-command-args): option to specify the pronounce command and arguments. (org-drill-pronounce-word): The real function to pronounce word. (org-drill-hide-subheadings-if): fix issue in Org 9.2 version. --- contrib/lisp/org-drill.el | 45 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/contrib/lisp/org-drill.el b/contrib/lisp/org-drill.el index c7f509bff..39785e7e3 100644 --- a/contrib/lisp/org-drill.el +++ b/contrib/lisp/org-drill.el @@ -532,6 +532,35 @@ exponential effect on inter-repetition spacing." :type 'float) +(defcustom org-drill-entry-before-hook nil + "A hook to run functions when every org-drill entry." + :type 'hook + :group 'org-drill) + +(defcustom org-drill-entry-after-hook nil + "A hook to run functions when every org-drill entry." + :type 'hook + :group 'org-drill) + +(defcustom org-drill-auto-pronounce t + "Auto pronounce org-drill word if non-nil." + :type 'boolean + :safe #'booleanp + :group 'org-drill) + +(defcustom org-drill-pronounce-command "" + "Org-drill pronounce command." + :type 'string + :safe #'stringp + :group 'org-drill) + +(defcustom org-drill-pronounce-command-args "" + "Org-drill pronounce command arguments." + :type 'string + :safe #'stringp + :group 'org-drill) + + (defvar drill-answer nil "Global variable that can be bound to a correct answer when an item is being presented. If this variable is non-nil, the default @@ -1486,7 +1515,7 @@ the current topic." (funcall test)) (hide-subtree)) (push (point) drill-sections))) - "" 'tree)) + nil 'tree)) (reverse drill-sections))) @@ -2163,6 +2192,15 @@ If ANSWER is supplied, set the global variable `drill-answer' to its value." (prog1 (org-drill-presentation-prompt) (org-drill-hide-subheadings-if 'org-drill-entry-p))))) +(defun org-drill-pronounce-word () + "Pronounce word after querying." + (when org-drill-auto-pronounce + (shell-command-to-string + (format "%s %s %s &" + org-drill-pronounce-command org-drill-pronounce-command-args + (shell-quote-argument + (substring-no-properties + (org-get-heading 'no-tags 'no-todo 'no-priority 'no-comment))))))) (defun org-drill-entry () "Present the current topic for interactive review, as in `org-drill'. @@ -2202,6 +2240,7 @@ See `org-drill' for more details." 'org-drill-present-default-answer) present-empty-cards (third presentation-fn) presentation-fn (first presentation-fn))) + (run-hook-with-args 'org-drill-entry-before-hook) (prog1 (cond ((null presentation-fn) @@ -2223,7 +2262,9 @@ See `org-drill' for more details." (save-excursion (funcall answer-fn (lambda () (org-drill-reschedule)))))))) - (org-remove-latex-fragment-image-overlays))))))) + (when org-drill-auto-pronounce org-drill-pronounce-word) + (run-hook-with-args 'org-drill-entry-after-hook) + (org-remove-latex-fragment-image-overlays))))))) (defun org-drill-entries-pending-p () -- 2.20.1