* [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
* Re: [PATCH] Add feature to org-drill to auto pronounce word 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 0 siblings, 1 reply; 10+ messages in thread From: stardiviner @ 2019-01-24 14:25 UTC (permalink / raw) To: org-mode; +Cc: Nicolas Goaziou A gentle ping.. stardiviner <numbchild@gmail.com> writes: > 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. > > 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 -- [ 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 [flat|nested] 10+ messages in thread
* Re: [PATCH] Add feature to org-drill to auto pronounce word 2019-01-24 14:25 ` stardiviner @ 2019-01-26 11:40 ` Nicolas Goaziou 2019-01-27 2:50 ` stardiviner 0 siblings, 1 reply; 10+ messages in thread From: Nicolas Goaziou @ 2019-01-26 11:40 UTC (permalink / raw) To: stardiviner; +Cc: Paul Sexton, org-mode Hello, stardiviner <numbchild@gmail.com> writes: > A gentle ping.. I'm not sure "org-drill.el" is still actively maintained. I'm Cc'ing Paul Sexton. In the long run, I think this package could be packaged through ELPA instead. >> * etc/ORG-NEWS: mentioned this new feature. Changes to "contrib/" directory are usually not mentioned in this file. >> +(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 What are `org-drill-pronounce-command' and `org-drill-pronounce-command-args'? I don't see them defined anywhere. Also, please prefer `when' to one-armed `if'. >> + (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) Could it be more integrated? Using hook is usually for users. If you can modify the code, you probably can do better. Regards, -- Nicolas Goaziou ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] Add feature to org-drill to auto pronounce word 2019-01-26 11:40 ` Nicolas Goaziou @ 2019-01-27 2:50 ` stardiviner 2019-01-27 21:15 ` Nicolas Goaziou 0 siblings, 1 reply; 10+ messages in thread From: stardiviner @ 2019-01-27 2:50 UTC (permalink / raw) To: Nicolas Goaziou; +Cc: Paul Sexton, org-mode Nicolas Goaziou <mail@nicolasgoaziou.fr> writes: > Hello, > > stardiviner <numbchild@gmail.com> writes: > >> A gentle ping.. > > I'm not sure "org-drill.el" is still actively maintained. I'm Cc'ing > Paul Sexton. In the long run, I think this package could be packaged > through ELPA instead. It is indeed not actively maintained. But still has some user are using it. I found some recently used in Org Mode ML mentioned it. I will ping the author Paul Sexton, I would like to particited in maintain it. If he agree to publish it to MELPA, I could help. > >>> * etc/ORG-NEWS: mentioned this new feature. > > Changes to "contrib/" directory are usually not mentioned in this > file. Removed now. > >>> +(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 > > What are `org-drill-pronounce-command' and > `org-drill-pronounce-command-args'? I don't see them defined anywhere. > I missed that. Now added. > Also, please prefer `when' to one-armed `if'. Modified. > >>> + (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) > > Could it be more integrated? Using hook is usually for users. If you can > modify the code, you probably can do better. Modified now. Those two hooks I think is necessary for user to add custom actions. So keep them. > > Regards, Regards :) -- [ 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 [flat|nested] 10+ messages in thread
* Re: [PATCH] Add feature to org-drill to auto pronounce word 2019-01-27 2:50 ` stardiviner @ 2019-01-27 21:15 ` Nicolas Goaziou 2019-01-29 10:40 ` stardiviner 0 siblings, 1 reply; 10+ messages in thread From: Nicolas Goaziou @ 2019-01-27 21:15 UTC (permalink / raw) To: stardiviner; +Cc: Paul Sexton, org-mode Hello, stardiviner <numbchild@gmail.com> writes: > Nicolas Goaziou <mail@nicolasgoaziou.fr> writes: > >> Hello, >> >> stardiviner <numbchild@gmail.com> writes: >> >>> A gentle ping.. >> >> I'm not sure "org-drill.el" is still actively maintained. I'm Cc'ing >> Paul Sexton. In the long run, I think this package could be packaged >> through ELPA instead. > > It is indeed not actively maintained. But still has some user are using > it. I found some recently used in Org Mode ML mentioned it. > > I will ping the author Paul Sexton, I would like to particited in > maintain it. If he agree to publish it to MELPA, I could help. Did you forget to add the new patch? Or is it intentional? Regards, -- Nicolas Goaziou ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] Add feature to org-drill to auto pronounce word 2019-01-27 21:15 ` Nicolas Goaziou @ 2019-01-29 10:40 ` stardiviner 2019-01-30 21:59 ` Nicolas Goaziou 0 siblings, 1 reply; 10+ messages in thread From: stardiviner @ 2019-01-29 10:40 UTC (permalink / raw) To: Nicolas Goaziou; +Cc: Paul Sexton, org-mode [-- Attachment #1: Type: text/plain, Size: 806 bytes --] Nicolas Goaziou <mail@nicolasgoaziou.fr> writes: > Hello, > > stardiviner <numbchild@gmail.com> writes: > >> Nicolas Goaziou <mail@nicolasgoaziou.fr> writes: >> >>> Hello, >>> >>> stardiviner <numbchild@gmail.com> writes: >>> >>>> A gentle ping.. >>> >>> I'm not sure "org-drill.el" is still actively maintained. I'm Cc'ing >>> Paul Sexton. In the long run, I think this package could be packaged >>> through ELPA instead. >> >> It is indeed not actively maintained. But still has some user are using >> it. I found some recently used in Org Mode ML mentioned it. >> >> I will ping the author Paul Sexton, I would like to particited in >> maintain it. If he agree to publish it to MELPA, I could help. > > Did you forget to add the new patch? Or is it intentional? > > > Regards, Oh, sorry, seems yes. [-- 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: 3747 bytes --] From b95a90cbecdf4fa2f47079eed08d2395f2700d41 Mon Sep 17 00:00:00 2001 From: stardiviner <numbchild@gmail.com> 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 [-- 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
* Re: [PATCH] Add feature to org-drill to auto pronounce word 2019-01-29 10:40 ` stardiviner @ 2019-01-30 21:59 ` Nicolas Goaziou 2019-02-01 2:37 ` stardiviner 0 siblings, 1 reply; 10+ messages in thread From: Nicolas Goaziou @ 2019-01-30 21:59 UTC (permalink / raw) To: stardiviner; +Cc: Paul Sexton, org-mode Hello, stardiviner <numbchild@gmail.com> writes: > Oh, sorry, seems yes. OK. A couple of comments if you don't mind. > +(defcustom org-drill-pronounce-command "" > + "Org-drill pronounce command." > + :type 'string > + :safe #'stringp > + :group 'org-drill) This is clearly not a safe command. You can remove the :safe keyword, or put :safe nil > +(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))))))) Is there any reason to use `shell-command-to-string'? You don't seem to need the returned string anyway. Why not calling `start-process', or at least `async-shell-command'? Regards, -- Nicolas Goaziou ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] Add feature to org-drill to auto pronounce word 2019-01-30 21:59 ` Nicolas Goaziou @ 2019-02-01 2:37 ` stardiviner 2019-02-01 12:07 ` Stig Brautaset 0 siblings, 1 reply; 10+ messages in thread From: stardiviner @ 2019-02-01 2:37 UTC (permalink / raw) To: Nicolas Goaziou; +Cc: Paul Sexton, org-mode [-- Attachment #1: Type: text/plain, Size: 1283 bytes --] Nicolas Goaziou <mail@nicolasgoaziou.fr> writes: > Hello, > > stardiviner <numbchild@gmail.com> writes: > >> Oh, sorry, seems yes. > > OK. A couple of comments if you don't mind. >> +(defcustom org-drill-pronounce-command "" >> + "Org-drill pronounce command." >> + :type 'string >> + :safe #'stringp >> + :group 'org-drill) > > This is clearly not a safe command. You can remove the :safe keyword, or > put :safe nil Ok, I removed it. (I misunderstand it's functionality..) > >> +(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))))))) > > Is there any reason to use `shell-command-to-string'? You don't seem to > need the returned string anyway. Why not calling `start-process', or at > least `async-shell-command'? Changed to `start-process' now. > > Regards, Also I add some new functionality, which can pronounce at anytime when press the key [p] not just at start time. I almost forgot my patch. I pressed [C-g] to interrupt it. [-- 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: 7070 bytes --] From eeee73acb5177526f7bf5d621f45ca979ee7119c Mon Sep 17 00:00:00 2001 From: stardiviner <numbchild@gmail.com> 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 | 79 ++++++++++++++++++++++++++++++++------- 1 file changed, 66 insertions(+), 13 deletions(-) diff --git a/contrib/lisp/org-drill.el b/contrib/lisp/org-drill.el index c7f509bff..70d0dee4b 100644 --- a/contrib/lisp/org-drill.el +++ b/contrib/lisp/org-drill.el @@ -269,6 +269,9 @@ item.") (defvar org-drill--tags-key ?t "If this character is pressed during a drill session, edit the tags for the current item.") +(defvar org-drill--pronounce-key ?p + "If this character is pressed during a drill session, pronounce for +the current item.") (defcustom org-drill-card-type-alist @@ -532,6 +535,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 (executable-find "espeak") + "Org-drill pronounce command." + :type 'string + :group 'org-drill) + +(defcustom org-drill-pronounce-command-args + (if (string= org-drill-pronounce-command "/usr/bin/espeak") + "-v en") + "Org-drill pronounce command arguments." + :type 'string + :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 @@ -1364,8 +1396,9 @@ of QUALITY." (let ((ch nil) (input nil) (next-review-dates (org-drill-hypothetical-next-review-dates)) - (key-prompt (format "(0-5, %c=help, %c=edit, %c=tags, %c=quit)" + (key-prompt (format "(0-5, %c=help, %c=pronounce, %c=edit, %c=tags, %c=quit)" org-drill--help-key + org-drill--pronounce-key org-drill--edit-key org-drill--tags-key org-drill--quit-key))) @@ -1391,7 +1424,9 @@ How well did you do? %s" (round (nth 4 next-review-dates)) (round (nth 5 next-review-dates)) key-prompt) - (format "How well did you do? %s" key-prompt)))) + (format "How well did you do? %s" key-prompt)) + (if (eq ch org-drill--pronounce-key) + (org-drill-pronounce-word)))) (cond ((stringp input) (setq ch (elt input 0))) @@ -1486,7 +1521,7 @@ the current topic." (funcall test)) (hide-subtree)) (push (point) drill-sections))) - "" 'tree)) + nil 'tree)) (reverse drill-sections))) @@ -1511,7 +1546,8 @@ the current topic." (first fmt-and-args) (rest fmt-and-args)) (format (concat "Press key for answer, " - "%c=edit, %c=tags, %c=skip, %c=quit.") + "%c=pronounce, %c=edit, %c=tags, %c=skip, %c=quit.") + org-drill--pronounce-key org-drill--edit-key org-drill--tags-key org-drill--skip-key @@ -1561,19 +1597,21 @@ You seem to be having a lot of trouble memorising this item. Consider reformulating the item to make it easier to remember.\n" 'face '(:foreground "red")) prompt))) - (while (memq ch '(nil org-drill--tags-key)) + (while (memq ch '(nil org-drill--tags-key org-drill--pronounce-key)) (setq ch nil) (while (not (input-pending-p)) - (let ((elapsed (time-subtract (current-time) item-start-time))) - (message (concat (if (>= (time-to-seconds elapsed) (* 60 60)) - "++:++ " - (format-time-string "%M:%S " elapsed)) - prompt)) - (sit-for 1))) + (let ((elapsed (time-subtract (current-time) item-start-time))) + (message (concat (if (>= (time-to-seconds elapsed) (* 60 60)) + "++:++ " + (format-time-string "%M:%S " elapsed)) + prompt)) + (sit-for 1))) (setq input (read-key-sequence nil)) (if (stringp input) (setq ch (elt input 0))) (if (eql ch org-drill--tags-key) - (org-set-tags-command))) + (org-set-tags-command)) + (if (eql ch org-drill--pronounce-key) + (org-drill-pronounce-word))) (case ch (org-drill--quit-key nil) (org-drill--edit-key 'edit) @@ -2163,6 +2201,18 @@ 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." + (interactive) + (start-process-shell-command + "org-drill pronounce" + nil + org-drill-pronounce-command + (format "%s %s" + 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 +2252,8 @@ See `org-drill' for more details." 'org-drill-present-default-answer) present-empty-cards (third presentation-fn) presentation-fn (first presentation-fn))) + (when org-drill-auto-pronounce (org-drill-pronounce-word)) + (run-hook-with-args 'org-drill-entry-before-hook) (prog1 (cond ((null presentation-fn) @@ -2223,7 +2275,8 @@ See `org-drill' for more details." (save-excursion (funcall answer-fn (lambda () (org-drill-reschedule)))))))) - (org-remove-latex-fragment-image-overlays))))))) + (run-hook-with-args 'org-drill-entry-after-hook) + (org-remove-latex-fragment-image-overlays))))))) (defun org-drill-entries-pending-p () -- 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
* Re: [PATCH] Add feature to org-drill to auto pronounce word 2019-02-01 2:37 ` stardiviner @ 2019-02-01 12:07 ` Stig Brautaset 2019-02-03 13:52 ` Nicolas Goaziou 0 siblings, 1 reply; 10+ messages in thread From: Stig Brautaset @ 2019-02-01 12:07 UTC (permalink / raw) To: numbchild, Nicolas Goaziou; +Cc: Paul Sexton, org-mode stardiviner <numbchild@gmail.com> writes: [...] > @@ -1486,7 +1521,7 @@ the current topic." > (funcall test)) > (hide-subtree)) > (push (point) drill-sections))) > - "" 'tree)) > + nil 'tree)) > (reverse drill-sections))) Could we have this part of the patch applied separately? org-drill on Org 9.2 doesn't work for me without it. Other people have this problem too, as I found a reference to this fix here: https://emacs.stackexchange.com/a/46961/10625 Stig ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] Add feature to org-drill to auto pronounce word 2019-02-01 12:07 ` Stig Brautaset @ 2019-02-03 13:52 ` Nicolas Goaziou 0 siblings, 0 replies; 10+ messages in thread From: Nicolas Goaziou @ 2019-02-03 13:52 UTC (permalink / raw) To: Stig Brautaset; +Cc: Paul Sexton, org-mode Hello, Stig Brautaset <stig@brautaset.org> writes: > stardiviner <numbchild@gmail.com> writes: > > [...] > >> @@ -1486,7 +1521,7 @@ the current topic." >> (funcall test)) >> (hide-subtree)) >> (push (point) drill-sections))) >> - "" 'tree)) >> + nil 'tree)) >> (reverse drill-sections))) > > Could we have this part of the patch applied separately? org-drill on > Org 9.2 doesn't work for me without it. Other people have this problem > too, as I found a reference to this fix here: > https://emacs.stackexchange.com/a/46961/10625 I applied the whole thing (the fix plus the feature). Thank you. Regards, -- Nicolas Goaziou ^ permalink raw reply [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).