diff options
author | Vincent Ambo <mail@tazj.in> | 2021-11-29T09·44+0300 |
---|---|---|
committer | Vincent Ambo <mail@tazj.in> | 2021-11-29T14·33+0300 |
commit | e4c82c2a344a34c5cafd834d223eb7f50df28bb7 (patch) | |
tree | 2ebb4ee7acd1d9761d809152d1ae51a906db8deb /users | |
parent | 7843363225800f69610cdafd245aa6595e748962 (diff) |
feat(tazjin/russian): Exclude known words from random display r/3108
Adds a set of words that I consider "known" (but that should be in the most frequent word list anyways). This set can be populated by invoking `mark-last-russian-word-as-known` after display, and is automatically persisted. Right now there's nothing automatically loading it back in, just as there is nothing loading any of this automatically, that's for the future. Change-Id: I51ee4f37114c6b95925e8ad5bdc5dc9b8657bdad
Diffstat (limited to 'users')
-rw-r--r-- | users/tazjin/russian/russian.el | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/users/tazjin/russian/russian.el b/users/tazjin/russian/russian.el index 94245f07c123..5871b180b5c0 100644 --- a/users/tazjin/russian/russian.el +++ b/users/tazjin/russian/russian.el @@ -82,11 +82,39 @@ (defun display-random-russian-word () (interactive) - (let ((word (seq-random-elt (ht-values russian-words)))) + (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 5 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))) + (provide 'russian) |