refactor(tazjin/russian): Use passively.el for Russian learning
Replaces the functionality previously implemented here with the now generalised implementation in passively.el Change-Id: Ibe7a1b7d512ddcb700bc330cbdf62811399c6cfe
This commit is contained in:
parent
1b41e34e79
commit
28759b7d66
1 changed files with 10 additions and 40 deletions
|
@ -63,7 +63,7 @@
|
||||||
|
|
||||||
'(message "Defined %s unique words." (ht-size russian-words)))
|
'(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)
|
(defun russian--format-word (word)
|
||||||
"Format a Russian word suitable for echo display."
|
"Format a Russian word suitable for echo display."
|
||||||
|
@ -77,50 +77,20 @@
|
||||||
(when-let ((notes (russian-word-notes word)))
|
(when-let ((notes (russian-word-notes word)))
|
||||||
(list " (" (s-join "; " notes) ")"))))))
|
(list " (" (s-join "; " notes) ")"))))))
|
||||||
|
|
||||||
(defvar russian--last-word nil
|
(defun display-russian-words ()
|
||||||
"Last randomly displayed Russian word")
|
"Convert Russian words to passively terms and start passively."
|
||||||
|
|
||||||
(defun display-random-russian-word ()
|
|
||||||
(interactive)
|
(interactive)
|
||||||
(let* ((word (seq-random-elt (ht-values russian-words))))
|
(setq passively-learn-terms (make-hash-table))
|
||||||
(while (ht-contains? russian--known-words (russian-word-word word))
|
(ht-map
|
||||||
(setq word (seq-random-elt (ht-values russian-words))))
|
(lambda (k v)
|
||||||
(setq russian--last-word word)
|
(ht-set passively-learn-terms k (russian--format-word v)))
|
||||||
(message (russian--format-word word))))
|
russian-words)
|
||||||
|
(passively-enable))
|
||||||
(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."
|
|
||||||
(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)))
|
|
||||||
|
|
||||||
(defun lookup-last-russian-word (in-eww)
|
(defun lookup-last-russian-word (in-eww)
|
||||||
"Look up the last Russian word in Wiktionary"
|
"Look up the last Russian word in Wiktionary"
|
||||||
(interactive "P")
|
(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)
|
(if in-eww (eww url)
|
||||||
(browse-url url))))
|
(browse-url url))))
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue