Skip to content

Commit

Permalink
feat: Allow custom, per-card, cloze context value
Browse files Browse the repository at this point in the history
  • Loading branch information
cashpw committed Sep 19, 2022
1 parent 7825855 commit 142805e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 11 deletions.
5 changes: 0 additions & 5 deletions org-fc-core.el
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,6 @@ Used to generate absolute paths to the awk scripts.")
:type 'string
:group 'org-fc)

(defcustom org-fc-type-cloze-max-hole-property "FC_CLOZE_MAX"
"Name of the property to use for storing the max hole index."
:type 'string
:group 'org-fc)

(defcustom org-fc-suspended-tag "suspended"
"Tag for marking suspended cards."
:type 'string
Expand Down
36 changes: 30 additions & 6 deletions org-fc-type-cloze.el
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,20 @@
:type 'string
:group 'org-fc)

(defcustom org-fc-type-cloze-max-hole-property "FC_CLOZE_MAX"
"Name of the property to use for storing the max hole index."
:type 'string
:group 'org-fc)

(defcustom org-fc-type-cloze-context-count-property "FC_CLOZE_CONTEXT_COUNT"
"Number of contextual clozes to show in a `'context'-type card."
:type 'number
:group 'org-fc)

(defcustom org-fc-type-cloze-context 1
"Number of surrounding cards to show for 'context' type cards."
"Number of surrounding cards to show for 'context' type cards.
Use `org-fc-type-cloze-context-count-property' to set this value on a per-card basis."
:type 'number
:group 'org-fc)

Expand Down Expand Up @@ -88,14 +100,16 @@ the hole for the current position."
(setq current-index (1- (length holes))))))
(cons (reverse holes) current-index)))

(defun org-fc-type-cloze--hole-visible-p (type i current-index)
(defun org-fc-type-cloze--hole-visible-p (type i current-index context-count)
"Determine whether hole I of card TYPE should be visible based.
CURRENT-INDEX is the index of the current position in the list of all holes."
- CURRENT-INDEX is the index of the current position in the list of all holes.
- CONTEXT-COUNT is the number of contextual clozes to show."
(cl-case type
('enumeration (< i current-index))
('deletion t)
('single nil)
('context (<= (abs (- i current-index)) org-fc-type-cloze-context))
('context (<= (abs (- i current-index)) context-count))
(t (error "Org-fc: Unknown cloze card type %s" type))))

(defun org-fc-type-cloze--end ()
Expand All @@ -112,7 +126,12 @@ CURRENT-INDEX is the index of the current position in the list of all holes."
(end (1+ (org-fc-type-cloze--end)))
(holes-index (org-fc-type-cloze--parse-holes position end))
(holes (car holes-index))
(current-index (cdr holes-index)))
(current-index (cdr holes-index))
(context-count (or (ignore-errors
(string-to-number
(org-entry-get (point)
org-fc-type-cloze-context-count-property)))
org-fc-type-cloze-context)))
(cl-loop
for i below (length holes)
for (hole-beg hole-end text-beg text-end hint-beg hint-end) in holes
Expand Down Expand Up @@ -143,7 +162,7 @@ CURRENT-INDEX is the index of the current position in the list of all holes."
'face 'org-fc-type-cloze-hole-face))
;; If the text of another hole should be visible,
;; hide the hole markup and the hint
((org-fc-type-cloze--hole-visible-p type i current-index)
((org-fc-type-cloze--hole-visible-p type i current-index context-count)
(org-fc-hide-region hole-beg text-beg)
(org-fc-hide-region text-end hole-end))
;; If the text of another hole should not be visible,
Expand Down Expand Up @@ -188,6 +207,8 @@ Processes all holes in the card text."
"Update the review data & deletions of the current heading."
(let* ((end (org-fc-type-cloze--end))
(hole-id (1+ (org-fc-type-cloze-max-hole-id)))
(cloze-count (or (org-entry-get (point) org-fc-type-cloze-context-count-property)
org-fc-type-cloze-context))
ids)
(save-excursion
(while (re-search-forward org-fc-type-cloze-hole-re end t)
Expand All @@ -205,6 +226,9 @@ Processes all holes in the card text."
(org-set-property
org-fc-type-cloze-max-hole-property
(format "%s" (1- hole-id)))
(org-set-property
org-fc-type-cloze-context-count-property
(format "%s" cloze-count))
(org-fc-review-data-update (reverse ids))))

(org-fc-register-type
Expand Down

0 comments on commit 142805e

Please sign in to comment.