Merge branch 'branweb/fix-cram-mode' into 'master'
Allow Creating New Session in Cram Mode
See merge request phillord/org-drill!9
Phillip Lord
4 years ago
3 | 3 | /elpa |
4 | 4 | /makefile-local |
5 | 5 | /robot/Makefile |
6 | /robot/main-test-copy.org | |
7 | 6 | /robot/failure.txt |
8 | 7 | /robot/messages.txt |
9 | /robot/main-test-copy.org~ | |
10 | /robot/main-test-interactive-copy.org | |
11 | /robot/all-card-copy.org | |
12 | /robot/basic-run-copy.org | |
13 | /robot/leitner-run-copy.org | |
14 | /robot/spanish-robot-copy.org | |
15 | /robot/explainer-run-copy.org | |
8 | /robot/*-copy.org | |
9 |
2854 | 2854 | (setf (oref session warned-about-id-creation) t)) |
2855 | 2855 | (org-id-get-create)) |
2856 | 2856 | |
2857 | (defun org-drill (&optional scope drill-match resume-p) | |
2857 | (defun org-drill (&optional scope drill-match resume-p cram) | |
2858 | 2858 | "Begin an interactive 'drill session'. The user is asked to |
2859 | 2859 | review a series of topics (headers). Each topic is initially |
2860 | 2860 | presented as a 'question', often with part of the topic content |
2887 | 2887 | It accepts the same values as `org-drill-match', which see. |
2888 | 2888 | |
2889 | 2889 | If RESUME-P is non-nil, resume a suspended drill session rather |
2890 | than starting a new one." | |
2890 | than starting a new one. | |
2891 | ||
2892 | CRAM, if non-nil, will start a new session in cram mode. If | |
2893 | resuming a suspended session, this parameter is ignored." | |
2891 | 2894 | |
2892 | 2895 | (interactive) |
2893 | 2896 | ;; Check org version. Org 7.9.3f introduced a backwards-incompatible change |
2908 | 2911 | (cl-block org-drill |
2909 | 2912 | (unless resume-p |
2910 | 2913 | (org-drill-free-markers session t) |
2911 | (setf (oref session current-item) nil | |
2914 | (setf (oref session cram-mode) cram | |
2915 | (oref session current-item) nil | |
2912 | 2916 | (oref session done-entries) nil |
2913 | 2917 | (oref session dormant-entry-count) 0 |
2914 | 2918 | (oref session due-entry-count) 0 |
2979 | 2983 | have been reviewed within the last `org-drill-cram-hours' |
2980 | 2984 | hours." |
2981 | 2985 | (interactive) |
2982 | (setq (oref session cram-mode) t) | |
2983 | (org-drill scope drill-match)) | |
2986 | (org-drill scope drill-match nil t)) | |
2984 | 2987 | |
2985 | 2988 | (defun org-drill-cram-tree () |
2986 | 2989 | "Run an interactive drill session in 'cram mode' using subtree at point. |
0 | (load-file "robot/robot.el") | |
1 | (load-file "org-drill.el") | |
2 | ||
3 | ;; setup | |
4 | (copy "basic-run.org" "cram-run-copy.org") | |
5 | ||
6 | ;; normal run | |
7 | (find "cram-run-copy.org") | |
8 | (org-drill) | |
9 | (set-buffer-modified-p nil) | |
10 | (kill-buffer) | |
11 | (robot-check-cards-seen 3) | |
12 | ||
13 | ;; cram run with all cards reviewed less than `org-drill-cram-hours` | |
14 | ;; ago, so we expect no new cards to be seen | |
15 | (find "cram-run-copy.org") | |
16 | (org-drill-cram) | |
17 | (robot-check-cards-seen 3) | |
18 | ||
19 | ;; cram run that should include all cards, so we expect seen cards to | |
20 | ;; double | |
21 | (setq org-drill-cram-hours 0) | |
22 | (org-drill-cram) | |
23 | (robot-check-cards-seen-and-die 6) |
0 | #!/usr/bin/env bash | |
1 | ||
2 | set -e | |
3 | ||
4 | this_dir="$(dirname "$0")" | |
5 | source ${this_dir}/robot.sh | |
6 | ||
7 | card_no=3 | |
8 | ||
9 | # cram mode doesn't modify the buffer so there is no save prompt | |
10 | function run_drill_no_save { | |
11 | sleep_small | |
12 | ||
13 | for i in `seq 1 ${card_no}`; | |
14 | do | |
15 | echo Answer: "$i" | |
16 | send_answer | |
17 | done | |
18 | ||
19 | echo press any key to continue | |
20 | retn | |
21 | } | |
22 | ||
23 | function run_drill { | |
24 | run_drill_no_save | |
25 | echo Save file | |
26 | key y | |
27 | } | |
28 | ||
29 | ||
30 | launch_emacs ${this_dir}/cram-run.el | |
31 | ||
32 | { | |
33 | find_bot | |
34 | run_drill | |
35 | retn | |
36 | run_drill_no_save | |
37 | wait_emacs | |
38 | } || cat robot/failure.txt |
54 | 54 | |
55 | 55 | (run-with-timer 1 1 #'robot-dump-messages) |
56 | 56 | |
57 | (defun robot-check-cards-seen-and-die (n) | |
57 | (defun robot-check-cards-seen (n) | |
58 | "N is number of cards we expect to have seen this session. | |
59 | Returns a number representing an exit status code" | |
58 | 60 | (if (= n org-drill-cards-in-this-emacs) |
59 | 61 | (progn |
60 | 62 | (princ |
61 | 63 | (format "Succeeded: Saw %s cards as expected\n" n) |
62 | 64 | 'external-debugging-output) |
63 | (kill-emacs 0)) | |
64 | (princ | |
65 | (format "Failed: Saw %s cards, expecting %s\n" | |
66 | org-drill-cards-in-this-emacs n) | |
67 | 'external-debugging-output) | |
68 | (kill-emacs -1))) | |
65 | 0) | |
66 | (progn | |
67 | (princ | |
68 | (format "Failed: Saw %s cards, expecting %s\n" | |
69 | org-drill-cards-in-this-emacs n) | |
70 | 'external-debugging-output) | |
71 | -1))) | |
72 | ||
73 | (defun robot-check-cards-seen-and-die (n) | |
74 | "N is number of cards we expect to have seen this session." | |
75 | (kill-emacs (robot-check-cards-seen n))) | |
69 | 76 | |
70 | 77 | ;; Move the package-user-dir somewhere local |
71 | 78 | (require 'package) |