about summary refs log tree commit diff
diff options
context:
space:
mode:
authorVincent Ambo <mail@tazj.in>2021-12-03T11·14+0300
committertazjin <mail@tazj.in>2021-12-06T11·50+0000
commit28759b7d66b1bcf600b8a02e29fb6eba88e85975 (patch)
tree7c2256726e3b3bfa95ceaa4d6c02b98e96c00978
parent1b41e34e7935d37932ff4a62e4bf77164248461e (diff)
refactor(tazjin/russian): Use passively.el for Russian learning r/3143
Replaces the functionality previously implemented here with the now
generalised implementation in passively.el

Change-Id: Ibe7a1b7d512ddcb700bc330cbdf62811399c6cfe
-rw-r--r--users/tazjin/russian/russian.el50
1 files changed, 10 insertions, 40 deletions
diff --git a/users/tazjin/russian/russian.el b/users/tazjin/russian/russian.el
index 975201810ce3..95af5b0e10ba 100644
--- a/users/tazjin/russian/russian.el
+++ b/users/tazjin/russian/russian.el
@@ -63,7 +63,7 @@
 
   '(message "Defined %s unique words." (ht-size russian-words)))
 
-;; Helpers to train Russian words when Emacs is idling.
+;; Helpers to train Russian words through passively.
 
 (defun russian--format-word (word)
   "Format a Russian word suitable for echo display."
@@ -77,50 +77,20 @@
                 (when-let ((notes (russian-word-notes word)))
                   (list " (" (s-join "; " notes) ")"))))))
 
-(defvar russian--last-word nil
-  "Last randomly displayed Russian word")
-
-(defun display-random-russian-word ()
-  (interactive)
-  (let* ((word (seq-random-elt (ht-values russian-words))))
-    (while (ht-contains? russian--known-words (russian-word-word word))
-      (setq word (seq-random-elt (ht-values russian-words))))
-    (setq russian--last-word word)
-    (message (russian--format-word word))))
-
-(defvar russian--display-timer
-  (run-with-idle-timer 4 t #'display-random-russian-word))
-
-;; Ability to filter out known words
-
-(defvar russian--known-words (make-hash-table)
-  "Table of words that are already known.")
-
-(defun persist-known-russian-words ()
-  "Persist all known Russian words."
-  (let ((file "/persist/tazjin/known-russian-words.el"))
-    (with-temp-file file
-      (insert (prin1-to-string russian--known-words)))))
-
-(defun load-known-russian-words ()
-  "Load all known Russian words."
-  (let ((file "/persist/tazjin/known-russian-words.el"))
-    (with-temp-buffer
-      (insert-file-contents file)
-      (setq russian--known-words (read (current-buffer))))))
-
-(defun mark-last-russian-word-known ()
-  "Mark the last Russian word that appeared as known."
+(defun display-russian-words ()
+  "Convert Russian words to passively terms and start passively."
   (interactive)
-  (let ((word (russian-word-word russian--last-word)))
-    (ht-set russian--known-words word t)
-    (persist-known-russian-words)
-    (message "Marked '%s' as known" word)))
+  (setq passively-learn-terms (make-hash-table))
+  (ht-map
+   (lambda (k v)
+     (ht-set passively-learn-terms k (russian--format-word v)))
+   russian-words)
+  (passively-enable))
 
 (defun lookup-last-russian-word (in-eww)
   "Look up the last Russian word in Wiktionary"
   (interactive "P")
-  (let ((url (concat "https://ru.wiktionary.org/wiki/" (russian-word-word russian--last-word))))
+  (let ((url (concat "https://ru.wiktionary.org/wiki/" passively-last-displayed)))
     (if in-eww (eww url)
       (browse-url url))))