summaryrefslogtreecommitdiff
path: root/org-fc-type-cloze.el
diff options
context:
space:
mode:
authorLeon Rische <leon.rische@me.com>2020-01-21 12:32:44 +0100
committerLeon Rische <leon.rische@me.com>2020-01-21 12:32:44 +0100
commitea52d77c440f246e4052f09451f264144eb1bc85 (patch)
treed9185e757e96e9ecaaa19e5253cd5193c3197a4b /org-fc-type-cloze.el
parent679ef13ad59ccbd65d4d571f7fb5680818ab494c (diff)
Show current cloze hole in bold
Diffstat (limited to 'org-fc-type-cloze.el')
-rw-r--r--org-fc-type-cloze.el39
1 files changed, 30 insertions, 9 deletions
diff --git a/org-fc-type-cloze.el b/org-fc-type-cloze.el
index 7b6cf5d..29f85c5 100644
--- a/org-fc-type-cloze.el
+++ b/org-fc-type-cloze.el
@@ -1,5 +1,15 @@
-(defvar org-fc-type-cloze-max-hole-property "FC_CLOZE_MAX")
-(defvar org-fc-type-cloze-type-property "FC_CLOZE_TYPE")
+;;; Configuration
+
+(defcustom org-fc-type-cloze-max-hole-property "FC_CLOZE_MAX"
+ "Name of the headline property to use for storing the max hole
+index."
+ :type 'string
+ :group 'org-fc)
+(defcustom org-fc-type-cloze-type-property "FC_CLOZE_TYPE"
+ "Name of the headline property to use for storing the cloze
+subtype."
+ :type 'string
+ :group 'org-fc)
;; NOTE: The context type is not implemented yet
(defvar org-fc-type-cloze-types
@@ -7,14 +17,18 @@
(defvar org-fc-type-cloze--overlays '())
-(defvar org-fc-type-cloze-context 1
- "Number of surrounding cards to show for 'context' type cards")
+(defcustom org-fc-type-cloze-context 1
+ "Number of surrounding cards to show for 'context' type cards"
+ :type 'number
+ :group 'org-fc)
(defface org-fc-type-cloze-hole-face
'((t (:bold t)))
"Face for org-fc cloze card holes."
:group 'org-fc)
+;;; Hole Regex
+
(defvar org-fc-type-cloze-hole-re
(rx
(seq
@@ -41,6 +55,8 @@
"}"))
"Regexp for a cloze hole with an id.")
+;;; Hole Parsing / Hiding
+
(defun org-fc-type-cloze-max-hole-id ()
(let ((max-id (org-entry-get (point) org-fc-type-cloze-max-hole-property)))
(if max-id
@@ -65,18 +81,22 @@
:text
(org-fc-hide-region (match-beginning 1) (match-end 1))
:separator
- (org-fc-hide-region (match-end 1) (match-beginning 2) "[...")
+ (org-fc-hide-region (match-end 1) (match-beginning 2)
+ "[..." 'org-fc-type-cloze-hole-face)
:hint
- (org-fc-overlay-region (match-beginning 2) (match-end 2))
+ (org-fc-overlay-region (match-beginning 2) (match-end 2)
+ 'org-fc-type-cloze-hole-face)
:after-hint
- (org-fc-hide-region (match-end 2) hole-end "]"))
+ (org-fc-hide-region (match-end 2) hole-end
+ "]" 'org-fc-type-cloze-hole-face))
(list
:before-text
(org-fc-hide-region hole-beg (match-beginning 1))
:text
(org-fc-hide-region (match-beginning 1) (match-end 1))
:hint
- (org-fc-hide-region (match-end 1) hole-end "[...]"))))
+ (org-fc-hide-region (match-end 1) hole-end
+ "[...]" 'org-fc-type-cloze-hole-face))))
(defun org-fc-type-cloze-hide-holes (hole type)
(save-excursion
@@ -110,6 +130,8 @@
(t (error "org-fc: Unknown cloze card type %s" type))))))
overlays)))
+;;; Setup / Flipping
+
(defun org-fc-type-cloze-flip ()
(if-let ((overlays org-fc-type-cloze--overlays))
(progn
@@ -118,7 +140,6 @@
(if (plist-member overlays :after-hint)
(org-fc-hide-overlay (plist-get overlays :after-hint)))
(org-fc-hide-overlay (plist-get overlays :hint))
- ;; (delete-overlay (plist-get overlays :text))
(org-fc-show-overlay
(plist-get overlays :text)
'org-fc-type-cloze-hole-face)))