From e4c82c2a344a34c5cafd834d223eb7f50df28bb7 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Mon, 29 Nov 2021 12:44:56 +0300 Subject: feat(tazjin/russian): Exclude known words from random display 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 --- users/tazjin/russian/russian.el | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) (limited to 'users') 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) -- cgit 1.4.1