lirve.el/learning-irregular-verbs-in-English.el

348 lines
11 KiB
EmacsLisp
Raw Normal View History

2023-12-31 10:00:33 +01:00
;;; learning-irregular-verbs-in-English.el --- Application to learn and review irregular verbs in English. -*- lexical-binding: t;
;;
;; Copyright © 2024 Andros Fenollosa
;; Authors: Andros Fenollosa <andros@fenollosa.email>
;; URL: https://github.com/tanrax/learning-irregular-verbs-in-English.el
;; Version: 1.0.0
;; SPDX-License-Identifier: GPL-3.0-or-later
;;; Commentary:
;; Application to learn and review irregular verbs in English.
;;; Code:
(defun learning-irregular-verbs-in-English ()
"Application to learn and review irregular verbs in English."
(interactive)
2024-01-02 16:18:41 +01:00
(let ((learning-irregular-verbs-in-English--verbs '(("be" "was/were" "been")
2023-12-31 10:00:33 +01:00
("beat" "beat" "beaten")
("become" "became" "become")
("begin" "began" "begun")
("bend" "bent" "bent")
("bet" "bet" "bet")
("bite" "bit" "bitten")
2024-01-02 16:18:41 +01:00
("bleed" "bled" "bled")
2023-12-31 10:00:33 +01:00
("blow" "blew" "blown")
("break" "broke" "broken")
("bring" "brought" "brought")
("build" "built" "built")
("burn" "burnt" "burnt")
("buy" "bought" "bought")
("catch" "caught" "caught")
("choose" "chose" "chosen")
("come" "came" "come")
("cost" "cost" "cost")
("cut" "cut" "cut")
("dig" "dug" "dug")
("do" "did" "done")
("draw" "drew" "drawn")
("dream" "dreamt" "dreamt")
("drink" "drank" "drunk")
("drive" "drove" "driven")
("eat" "ate" "eaten")
("fall" "fell" "fallen")
("feed" "fed" "fed")
("feel" "felt" "felt")
("fight" "fought" "fought")
("find" "found" "found")
("fly" "flew" "flown")
("forget" "forgot" "forgotten")
("forgive" "forgave" "forgiven")
("freeze" "froze" "frozen")
("get" "got" "got")
("give" "gave" "given")
("go" "went" "gone")
("grow" "grew" "grown")
("hang" "hung" "hung")
("have" "had" "had")
("hear" "heard" "heard")
("hide" "hid" "hidden")
2024-01-01 13:10:45 +01:00
("hit" "hit" "hit")
2024-01-02 16:18:41 +01:00
("hold" "held" "held")
("hurt" "hurt" "hurt")
("keep" "kept" "kept")
("know" "knew" "known")
("lay" "laid" "laid")
("lead" "led" "led")
("learn" "learnt" "learnt")
("leave" "left" "left")
("lend" "lent" "lent")
("let" "let" "let")
("lie" "lay" "lain")
("light" "lit" "lit")
("lose" "lost" "lost")
("make" "made" "made")
("mean" "meant" "meant")
("meet" "met" "met")
("pay" "paid" "paid")
("put" "put" "put")
("read" "read" "read")
("ride" "rode" "ridden")
("ring" "rang" "rung")
("rise" "rose" "risen")
("run" "ran" "run")
("say" "said" "said")
("see" "saw" "seen")
("sell" "sold" "sold")
("send" "sent" "sent")
("set" "set" "set")
("shake" "shook" "shaken")
("shine" "shone" "shone")
("shoot" "shot" "shot")
("show" "showed" "shown")
("shut" "shut" "shut")
("sing" "sang" "sung")
("sink" "sank" "sunk")
("sit" "sat" "sat")
("sleep" "slept" "slept")
("smell" "smelt" "smelt")
("speak" "spoke" "spoken")
("spend" "spent" "spent")
("spill" "spelt" "spelt")
("spit" "spit" "spit")
("stand" "stood" "stood")
("steal" "stole" "stolen")
("swim" "swam" "swum")
("take" "took" "taken")
("teach" "taught" "taught")
("tear" "tore" "torn")
("tell" "told" "told")
("think" "thought" "thought")
("throw" "threw" "thrown")
("understand" "understood" "understood")
("wake" "woke" "woken")
("wear" "wore" "worn")
("win" "won" "won")
("write" "wrote" "written")))
2023-12-31 15:39:31 +01:00
(buffer-name "*Learning irregular verbs in English*")
2024-01-02 16:18:41 +01:00
(state 1) ;; 1: start, 2: playing (before first check), 3: win (show success layout)
2023-12-31 15:39:31 +01:00
(verb-to-learn-infinitive nil)
(verb-to-learn-simple-past nil)
(verb-to-learn-past-participle nil)
2023-12-31 10:16:21 +01:00
(emoji-valid "")
(emoji-error "👎")
(widget-title nil)
2023-12-31 15:39:31 +01:00
(text-title " 🧑‍🎓 Learning irregular verbs in English 🇬🇧")
(widget-item-verb nil)
(widget-field-simple-past nil)
2024-01-01 13:10:45 +01:00
(widget-label-check-simple-past nil)
2023-12-31 15:39:31 +01:00
(widget-field-past-participle nil)
2024-01-01 13:10:45 +01:00
(widget-label-check-past-participle nil)
2023-12-31 10:16:21 +01:00
(text-button-check "Check")
2024-01-01 20:39:40 +01:00
(widget-button-check nil)
2023-12-31 10:16:21 +01:00
(widget-message-success nil)
2024-01-01 20:39:40 +01:00
(widget-item-space-before-success nil)
2024-01-01 13:10:45 +01:00
(text-success "Nice!")
2024-01-01 20:39:40 +01:00
(widget-item-space-after-success nil)
2023-12-31 10:16:21 +01:00
(widget-button-quit nil)
(text-button-quit "Quit")
2024-01-01 20:39:40 +01:00
(widget-item-space-between-buttons nil)
2023-12-31 10:16:21 +01:00
(widget-button-replay nil)
2024-01-02 16:18:41 +01:00
(text-button-replay "New challenge"))
2023-12-31 15:39:31 +01:00
;; Imports
(require 'widget)
(eval-when-compile
(require 'wid-edit))
;; Functions
2024-01-01 20:39:40 +01:00
(defun kill-app ()
"Kill the application."
(interactive)
(kill-buffer buffer-name))
2024-01-02 16:18:41 +01:00
(defun value-field-simple-past ()
(if (not (eq widget-field-simple-past nil)) (widget-value widget-field-simple-past) ""))
(defun value-field-past-participle ()
(if (not (eq widget-field-past-participle nil)) (widget-value widget-field-past-participle) ""))
2023-12-31 15:39:31 +01:00
(defun set-verb-to-learn ()
"Set the verb to learn."
2024-01-02 16:18:41 +01:00
(let ((verbs-random (nth (random (length learning-irregular-verbs-in-English--verbs)) learning-irregular-verbs-in-English--verbs)))
2023-12-31 15:39:31 +01:00
(setq verb-to-learn-infinitive (nth 0 verbs-random))
(setq verb-to-learn-simple-past (nth 1 verbs-random))
(setq verb-to-learn-past-participle (nth 2 verbs-random))))
2024-01-01 13:10:45 +01:00
(defun format-value-infinitive ()
2023-12-31 15:39:31 +01:00
"Format the value of the infinitive."
2024-01-01 13:10:45 +01:00
(format "Infinitive ➡️ %s" verb-to-learn-infinitive))
2023-12-31 15:39:31 +01:00
2024-01-01 13:10:45 +01:00
(defun format-check-simple-past ()
2023-12-31 15:39:31 +01:00
"Format the value of the simple past."
2024-01-01 13:10:45 +01:00
(if (eq state 1)
""
(format " %s" (if
(and
2024-01-02 16:18:41 +01:00
(string= (value-field-simple-past) verb-to-learn-simple-past)
(not (string= (value-field-simple-past) "")))
2024-01-01 13:10:45 +01:00
emoji-valid emoji-error))))
(defun format-check-past-participle ()
"Format the value of the past participle."
(if (eq state 1)
""
(format " %s" (if
(and
2024-01-02 16:18:41 +01:00
(string= (value-field-past-participle) verb-to-learn-past-participle)
(not (string= (value-field-past-participle) "")))
2024-01-01 13:10:45 +01:00
emoji-valid emoji-error))))
(defun toggle-layout-success ()
"Toggle the layout to success."
2024-01-01 20:39:40 +01:00
(if (eq state 3)
(progn
;; Cursor to end
(goto-char (point-max))
;; Remove check button
(widget-delete widget-button-check)
(setq widget-button-check nil)
;; Text success
(setq widget-item-space-before-success (widget-create 'item
""))
(setq widget-message-success (widget-create 'item
text-success
))
(setq widget-item-space-after-success (widget-create 'item
"\n"))
;; Replay button
(setq widget-button-replay (widget-create 'push-button
:size 20
:notify (lambda (&rest ignore)
(replay))
text-button-replay))
;; Space
(setq widget-item-space-between-buttons (widget-create 'item
"\n"))
;; Quit button
(setq widget-button-quit (widget-create 'push-button
:size 20
:notify (lambda (&rest ignore)
(kill-app))
text-button-quit))
(widget-backward 2)
)
(progn
(when (not (eq widget-item-space-before-success nil)) (widget-delete widget-item-space-before-success))
(when (not (eq widget-message-success nil)) (widget-delete widget-message-success))
(when (not (eq widget-item-space-after-success nil)) (widget-delete widget-item-space-after-success))
(when (not (eq widget-button-replay nil)) (widget-delete widget-button-replay))
(when (not (eq widget-item-space-between-buttons nil)) (widget-delete widget-item-space-between-buttons))
(when (not (eq widget-button-quit nil)) (widget-delete widget-button-quit))
)))
(defun make-button-check ()
"Make the button check."
(setq widget-button-check (widget-create 'push-button
:notify (lambda (&rest ignore)
(update))
text-button-check)))
2024-01-01 13:10:45 +01:00
2023-12-31 15:39:31 +01:00
2024-01-01 13:10:45 +01:00
(defun start ()
2023-12-31 15:39:31 +01:00
"Start o replay challenge."
(interactive)
2024-01-01 13:10:45 +01:00
;; Set the state
(setq state 1)
2023-12-31 15:39:31 +01:00
;; Get a new verb
(set-verb-to-learn)
;; Show the verb in infinitive
2024-01-01 13:10:45 +01:00
(widget-value-set widget-item-verb (format-value-infinitive))
2024-01-01 20:39:40 +01:00
;; Reset button check
(when (eq widget-button-check nil) (make-button-check))
;; Clear the fields
(widget-value-set widget-field-simple-past "")
(widget-value-set widget-label-check-simple-past "")
(widget-value-set widget-field-past-participle "")
(widget-value-set widget-label-check-past-participle "")
2024-01-01 13:10:45 +01:00
;; Update labels
2024-01-01 20:39:40 +01:00
(update))
(defun replay ()
"Replay the challenge."
(interactive)
(start)
(widget-backward 1))
2023-12-31 15:39:31 +01:00
2024-01-01 13:10:45 +01:00
(defun update ()
"Check the answers."
(interactive)
;; Is playing?
(when (and (eq state 1)
(or
2024-01-02 16:18:41 +01:00
(not (string= (value-field-simple-past) ""))
(not (string= (value-field-past-participle) "")))
2024-01-01 13:10:45 +01:00
)
(setq state 2))
;; Check the answers
(when (eq state 2)
;; Is win?
(when (and
2024-01-02 16:18:41 +01:00
(string= (value-field-simple-past) verb-to-learn-simple-past)
(string= (value-field-past-participle) verb-to-learn-past-participle))
2024-01-01 13:10:45 +01:00
;; Set the state
(setq state 3))
;; Update the check labels
(widget-value-set widget-label-check-simple-past (format-check-simple-past))
2024-01-02 16:18:41 +01:00
(widget-value-set widget-label-check-past-participle (format-check-past-participle)))
2024-01-01 20:39:40 +01:00
;; Update the success layout if needed
(toggle-layout-success))
2023-12-31 15:39:31 +01:00
(defun main-layout ()
"Make widgets for the main layout."
(interactive)
;; Create the buffer
(switch-to-buffer buffer-name)
;; Clear the buffer
(kill-all-local-variables)
(let ((inhibit-read-only t))
(erase-buffer))
(remove-overlays)
;; Create the widgets
;; Title
(insert (propertize (format "\n%s\n\n" text-title) 'face '(:height 1.2 :weight bold)))
;; Verb in infinitive
(setq widget-item-verb (widget-create 'item
:value ""))
;; Separator
(insert "\nSimple past ➡️ ")
;; Simple past
(setq widget-field-simple-past (widget-create 'editable-field
:size 8
:help-echo "Type a Simple past"
))
2024-01-01 13:10:45 +01:00
;; Label check
(insert " ")
(setq widget-label-check-simple-past (widget-create 'item
(format-check-simple-past)))
2023-12-31 15:39:31 +01:00
;; Separator
2024-01-01 13:10:45 +01:00
(insert "\nPast participle ➡️ ")
2023-12-31 15:39:31 +01:00
;; Past participle
(setq widget-field-past-participle (widget-create 'editable-field
:size 8
:help-echo "Type a Past participle"))
2024-01-01 13:10:45 +01:00
;; Label check
(insert " ")
(setq widget-label-check-past-participle (widget-create 'item
(format-check-past-participle)))
2023-12-31 15:39:31 +01:00
;; Separator
2024-01-01 20:39:40 +01:00
(insert "\n")
2023-12-31 15:39:31 +01:00
;; Check button
2024-01-01 20:39:40 +01:00
(make-button-check)
2023-12-31 15:39:31 +01:00
;; Display the buffer
(use-local-map widget-keymap)
(widget-setup))
;; Keybindings
(define-key widget-keymap (kbd "q") 'kill-app)
;; Init
(main-layout)
2024-01-01 13:10:45 +01:00
(start)
2024-01-02 16:18:41 +01:00
(widget-backward 1)))
2023-12-31 10:00:33 +01:00
(provide 'learning-irregular-verbs-in-English)
;;; learning-irregular-verbs-in-English.el ends here
2023-12-31 15:39:31 +01:00
(learning-irregular-verbs-in-English)