summaryrefslogtreecommitdiff
path: root/modules/org-drill-config.el
blob: dff132e25e5b1382ef3fef4cf7726f41df1f7e56 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
;;; org-drill-config.el --- Org Drill Settings -*- lexical-binding: t; coding: utf-8; -*-
;; author: Craig Jennings <c@cjennings.net>
;;; Commentary:
;;
;; Notes: Org-Drill
;; Start out your org-drill with C-d s, then select your file.

;; Capture templates:
;; - "d" for web/EPUB drill captures (uses %i for selected text, %:link for source)
;; - "f" for PDF drill captures (uses special PDF region extraction)

;; The javascript bookmarklet for capturing from web to org-drill:
;; javascript:location.href='org-protocol://capture?template=d&url=%27+encodeURIComponent(location.href)+%27&title=%27+encodeURIComponent(document.title)+%27&body=%27+encodeURIComponent(window.getSelection());void(0);

;; Create a bookmark, add "Drill Entry" to the name field and the above snippet to the URL field.

;;; Code:

(eval-when-compile (defvar drill-dir))
(eval-when-compile (defvar cj/custom-keymap))

(defvar cj/drill-map)
(declare-function org-drill-resume "org-drill")
(declare-function cj/drill-map "org-drill-config")
(declare-function cj/drill-start "org-drill-config")
(declare-function cj/drill-edit "org-drill-config")
(declare-function cj/drill-capture "org-drill-config")
(declare-function cj/drill-refile "org-drill-config")

;; --------------------------------- Org Drill ---------------------------------

(use-package org-drill
  :after (org org-capture)
  :commands org-drill
  :config
  (setq org-drill-leech-failure-threshold 50)           ;; leech cards = 50 wrong anwers
  (setq org-drill-leech-method 'warn)                   ;; leech cards show warnings
  (setq org-drill-use-visible-cloze-face-p t)           ;; cloze text show up in a different font
  (setq org-drill-hide-item-headings-p t)               ;; don't show heading text
  (setq org-drill-maximum-items-per-session 1000)       ;; drill sessions end after 1000 cards
  (setq org-drill-maximum-duration 60)                  ;; each drill session can last up to a an hour
  (setq org-drill-add-random-noise-to-intervals-p t)    ;; slightly vary number of days to repetition

  (defun cj/drill-start ()
	"Prompt user to pick a drill org file, then start an org-drill session."
	(interactive)
	(let* ((choices (directory-files drill-dir nil "^[^.].*\\.org$"))
		   (chosen-drill-file (completing-read "Choose Flashcard File:" choices)))
	  (find-file (concat drill-dir chosen-drill-file))
      (org-drill)))

  (defun cj/drill-edit ()
	"Prompts the user to pick a drill org file, then opens it for editing."
	(interactive)
	(let* ((choices (directory-files drill-dir nil "^[^.].*\\.org$"))
		   (chosen-drill-file (completing-read "Choose Flashcard File:" choices)))
	  (find-file (concat drill-dir chosen-drill-file))))

  (defun cj/drill-capture ()
	"Quickly capture a drill question."
	(interactive)
	(org-capture nil "d"))

  (defun cj/drill-refile ()
	"Refile to a drill file."
	(interactive)
	(setq org-refile-targets '((nil :maxlevel . 1)
							   (drill-dir :maxlevel . 1)))
	(call-interactively 'org-refile))

  ;; ------------------------------ Org Drill Keymap -----------------------------

  ;; Buffer & file operations prefix and keymap
  (define-prefix-command 'cj/drill-map nil
						 "Keymap for org-drill.")
  (keymap-set cj/custom-keymap "D" #'cj/drill-map)
  (keymap-set cj/drill-map "s" #'cj/drill-start)
  (keymap-set cj/drill-map "e" #'cj/drill-edit)
  (keymap-set cj/drill-map "c" #'cj/drill-capture)
  (keymap-set cj/drill-map "r" #'cj/drill-refile)
  (keymap-set cj/drill-map "R" #'org-drill-resume))

(provide 'org-drill-config)
;;; org-drill-config.el ends here.