emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH] Add feature to org-drill to auto pronounce word
@ 2019-01-09  8:44 stardiviner
  2019-01-24 14:25 ` stardiviner
  0 siblings, 1 reply; 10+ messages in thread
From: stardiviner @ 2019-01-09  8:44 UTC (permalink / raw)
  To: org-mode

[-- Attachment #1: Type: text/plain, Size: 205 bytes --]

I spend a little time to check out org-drill source code, to find out
where I can insert hook to run function when presenting word.

Then I finally found the place in ~org-drill-entry~. Here is my patch.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-org-drill.el-Add-feature-let-org-drill-auto-pronounc.patch --]
[-- Type: text/x-patch, Size: 3622 bytes --]

From 81765e9395f5c0bec21d44aeaf16919d35a39eee Mon Sep 17 00:00:00 2001
From: stardiviner <numbchild@gmail.com>
Date: Wed, 9 Jan 2019 16:25:38 +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-word): The real function to pronounce word.
  (org-drill-hide-subheadings-if): fix issue in Org 9.2 version.

* etc/ORG-NEWS: mentioned this new feature.
---
 contrib/lisp/org-drill.el | 31 ++++++++++++++++++++++++++++++-
 etc/ORG-NEWS              |  3 +++
 2 files changed, 33 insertions(+), 1 deletion(-)

diff --git a/contrib/lisp/org-drill.el b/contrib/lisp/org-drill.el
index c7f509bff..29a0cd8c9 100644
--- a/contrib/lisp/org-drill.el
+++ b/contrib/lisp/org-drill.el
@@ -1486,7 +1486,7 @@ the current topic."
                         (funcall test))
              (hide-subtree))
            (push (point) drill-sections)))
-       "" 'tree))
+       nil 'tree))
     (reverse drill-sections)))
 
 
@@ -2163,6 +2163,33 @@ 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)))))
 
+(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)
+
+(defun org-drill-pronounce-word ()
+  "Pronounce word after querying."
+  (if 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)))))))
+
+(add-hook 'org-drill-entry-after-hook #'org-drill-pronounce-word)
 
 (defun org-drill-entry ()
   "Present the current topic for interactive review, as in `org-drill'.
@@ -2202,6 +2229,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,6 +2251,7 @@ See `org-drill' for more details."
                   (save-excursion
                     (funcall answer-fn
                              (lambda () (org-drill-reschedule))))))))
+	    (run-hook-with-args 'org-drill-entry-after-hook)
             (org-remove-latex-fragment-image-overlays)))))))
 
 
diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index e06d0c09b..1bb485ad1 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -49,6 +49,9 @@ alternative was removed and there is no more a :use-xcolor options
 since now it's implicitly always true.
 
 ** New features
+*** Org-drill support auto pronounce word
+You can set option ~org-drill-auto-pronounce~ to ~t~ to enable it
+(This is default). You can disable it by setting it to ~nil~.
 *** Add a dispatcher command to insert dynamic blocks
 
 You can add dynamic block into ~org-dynamic-block-alist~ with function
-- 
2.20.1


[-- Attachment #3: Type: text/plain, Size: 255 bytes --]



-- 
[ stardiviner ]
       I try to make every word tell the meaning what I want to express.

       Blog: https://stardiviner.github.io/
       IRC(freenode): stardiviner, Matrix: stardiviner
       GPG: F09F650D7D674819892591401B5DF1C95AE89AC3
      

^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2019-02-03 13:52 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-01-09  8:44 [PATCH] Add feature to org-drill to auto pronounce word stardiviner
2019-01-24 14:25 ` stardiviner
2019-01-26 11:40   ` Nicolas Goaziou
2019-01-27  2:50     ` stardiviner
2019-01-27 21:15       ` Nicolas Goaziou
2019-01-29 10:40         ` stardiviner
2019-01-30 21:59           ` Nicolas Goaziou
2019-02-01  2:37             ` stardiviner
2019-02-01 12:07               ` Stig Brautaset
2019-02-03 13:52                 ` Nicolas Goaziou

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).