mirror of
https://github.com/tanrax/lirve.el.git
synced 2024-11-09 23:35:42 +01:00
Fix scope in package
This commit is contained in:
parent
2f30f0180e
commit
49e6e3e10c
@ -11,10 +11,14 @@
|
||||
|
||||
;;; Code:
|
||||
|
||||
(defun learning-irregular-verbs-in-English ()
|
||||
"Application to learn and review irregular verbs in English."
|
||||
(interactive)
|
||||
(let* ((learning-irregular-verbs-in-English--verbs '(
|
||||
;; Imports
|
||||
(require 'widget)
|
||||
(eval-when-compile
|
||||
(require 'wid-edit))
|
||||
|
||||
;; Variables
|
||||
|
||||
(defvar learning-irregular-verbs-in-English--verbs '(
|
||||
("beat" "beat" "beaten")
|
||||
("become" "became" "become")
|
||||
("begin" "began" "begun")
|
||||
@ -115,81 +119,76 @@
|
||||
("win" "won" "won")
|
||||
("write" "wrote" "written")))
|
||||
;; learning-irregular-verbs-in-English
|
||||
(learning-irregular-verbs-in-English--buffer-name "*Learning irregular verbs in English*")
|
||||
(learning-irregular-verbs-in-English--state 1) ;; 1: start, 2: playing (before first check), 3: win (show success layout)
|
||||
(learning-irregular-verbs-in-English--verb-to-learn-infinitive nil)
|
||||
(learning-irregular-verbs-in-English--verb-to-learn-simple-past nil)
|
||||
(learning-irregular-verbs-in-English--verb-to-learn-past-participle nil)
|
||||
(learning-irregular-verbs-in-English--emoji-valid "✅")
|
||||
(learning-irregular-verbs-in-English--emoji-error "👎")
|
||||
(learning-irregular-verbs-in-English--widget-title nil)
|
||||
(learning-irregular-verbs-in-English--text-title " 🧑🎓 Learning irregular verbs in English 🇬🇧")
|
||||
(learning-irregular-verbs-in-English--widget-item-verb nil)
|
||||
(learning-irregular-verbs-in-English--widget-field-simple-past nil)
|
||||
(learning-irregular-verbs-in-English--widget-label-check-simple-past nil)
|
||||
(learning-irregular-verbs-in-English--widget-field-past-participle nil)
|
||||
(learning-irregular-verbs-in-English--widget-label-check-past-participle nil)
|
||||
(learning-irregular-verbs-in-English--text-button-check "Check")
|
||||
(learning-irregular-verbs-in-English--widget-button-check nil)
|
||||
(learning-irregular-verbs-in-English--widget-message-success nil)
|
||||
(learning-irregular-verbs-in-English--widget-item-space-before-success nil)
|
||||
(learning-irregular-verbs-in-English--text-success "Nice!")
|
||||
(learning-irregular-verbs-in-English--widget-item-space-after-success nil)
|
||||
(learning-irregular-verbs-in-English--widget-button-quit nil)
|
||||
(learning-irregular-verbs-in-English--text-button-quit "Quit")
|
||||
(learning-irregular-verbs-in-English--widget-item-space-between-buttons nil)
|
||||
(learning-irregular-verbs-in-English--widget-button-replay nil)
|
||||
(learning-irregular-verbs-in-English--text-button-replay "New challenge"))
|
||||
;; Imports
|
||||
(require 'widget)
|
||||
(eval-when-compile
|
||||
(require 'wid-edit))
|
||||
(defvar learning-irregular-verbs-in-English--buffer-name "*Learning irregular verbs in English*")
|
||||
(defvar learning-irregular-verbs-in-English--state 1) ;; 1: start, 2: playing (before first check), 3: win (show success layout)
|
||||
(defvar learning-irregular-verbs-in-English--verb-to-learn-infinitive nil)
|
||||
(defvar learning-irregular-verbs-in-English--verb-to-learn-simple-past nil)
|
||||
(defvar learning-irregular-verbs-in-English--verb-to-learn-past-participle nil)
|
||||
(defvar learning-irregular-verbs-in-English--emoji-valid "✅")
|
||||
(defvar learning-irregular-verbs-in-English--emoji-error "👎")
|
||||
(defvar learning-irregular-verbs-in-English--widget-title nil)
|
||||
(defvar learning-irregular-verbs-in-English--text-title " 🧑🎓 Learning irregular verbs in English 🇬🇧")
|
||||
(defvar learning-irregular-verbs-in-English--widget-item-verb nil)
|
||||
(defvar learning-irregular-verbs-in-English--widget-field-simple-past nil)
|
||||
(defvar learning-irregular-verbs-in-English--widget-label-check-simple-past nil)
|
||||
(defvar learning-irregular-verbs-in-English--widget-field-past-participle nil)
|
||||
(defvar learning-irregular-verbs-in-English--widget-label-check-past-participle nil)
|
||||
(defvar learning-irregular-verbs-in-English--text-button-check "Check")
|
||||
(defvar learning-irregular-verbs-in-English--widget-button-check nil)
|
||||
(defvar learning-irregular-verbs-in-English--widget-message-success nil)
|
||||
(defvar learning-irregular-verbs-in-English--widget-item-space-before-success nil)
|
||||
(defvar learning-irregular-verbs-in-English--text-success "Nice!")
|
||||
(defvar learning-irregular-verbs-in-English--widget-item-space-after-success nil)
|
||||
(defvar learning-irregular-verbs-in-English--widget-button-quit nil)
|
||||
(defvar learning-irregular-verbs-in-English--text-button-quit "Quit")
|
||||
(defvar learning-irregular-verbs-in-English--widget-item-space-between-buttons nil)
|
||||
(defvar learning-irregular-verbs-in-English--widget-button-replay nil)
|
||||
(defvar learning-irregular-verbs-in-English--text-button-replay "New challenge")
|
||||
|
||||
;; Functions
|
||||
|
||||
(defun kill-app ()
|
||||
(defun learning-irregular-verbs-in-English--kill-app ()
|
||||
"Kill the application."
|
||||
(interactive)
|
||||
(kill-buffer learning-irregular-verbs-in-English--buffer-name))
|
||||
|
||||
(defun value-field-simple-past ()
|
||||
(defun learning-irregular-verbs-in-English--value-field-simple-past ()
|
||||
(if (not (eq learning-irregular-verbs-in-English--widget-field-simple-past nil)) (widget-value learning-irregular-verbs-in-English--widget-field-simple-past) ""))
|
||||
|
||||
(defun value-field-past-participle ()
|
||||
(defun learning-irregular-verbs-in-English--value-field-past-participle ()
|
||||
(if (not (eq learning-irregular-verbs-in-English--widget-field-past-participle nil)) (widget-value learning-irregular-verbs-in-English--widget-field-past-participle) ""))
|
||||
|
||||
(defun set-verb-to-learn ()
|
||||
(defun learning-irregular-verbs-in-English--set-verb-to-learn ()
|
||||
"Set the verb to learn."
|
||||
(let ((verbs-random (nth (random (length learning-irregular-verbs-in-English--verbs)) learning-irregular-verbs-in-English--verbs)))
|
||||
(setq learning-irregular-verbs-in-English--verb-to-learn-infinitive (nth 0 verbs-random))
|
||||
(setq learning-irregular-verbs-in-English--verb-to-learn-simple-past (nth 1 verbs-random))
|
||||
(setq learning-irregular-verbs-in-English--verb-to-learn-past-participle (nth 2 verbs-random))))
|
||||
|
||||
(defun format-value-infinitive ()
|
||||
(defun learning-irregular-verbs-in-English--format-value-infinitive ()
|
||||
"Format the value of the infinitive."
|
||||
(format "Infinitive ➡️ %s" learning-irregular-verbs-in-English--verb-to-learn-infinitive))
|
||||
|
||||
(defun format-check-simple-past ()
|
||||
(defun learning-irregular-verbs-in-English--format-check-simple-past ()
|
||||
"Format the value of the simple past."
|
||||
(if (eq learning-irregular-verbs-in-English--state 1)
|
||||
""
|
||||
(format " %s" (if
|
||||
(and
|
||||
(string= (value-field-simple-past) learning-irregular-verbs-in-English--verb-to-learn-simple-past)
|
||||
(not (string= (value-field-simple-past) "")))
|
||||
(string= (learning-irregular-verbs-in-English--value-field-simple-past) learning-irregular-verbs-in-English--verb-to-learn-simple-past)
|
||||
(not (string= (learning-irregular-verbs-in-English--value-field-simple-past) "")))
|
||||
learning-irregular-verbs-in-English--emoji-valid learning-irregular-verbs-in-English--emoji-error))))
|
||||
|
||||
(defun format-check-past-participle ()
|
||||
(defun learning-irregular-verbs-in-English--format-check-past-participle ()
|
||||
"Format the value of the past participle."
|
||||
(if (eq learning-irregular-verbs-in-English--state 1)
|
||||
""
|
||||
(format " %s" (if
|
||||
(and
|
||||
(string= (value-field-past-participle) learning-irregular-verbs-in-English--verb-to-learn-past-participle)
|
||||
(not (string= (value-field-past-participle) "")))
|
||||
(string= (learning-irregular-verbs-in-English--value-field-past-participle) learning-irregular-verbs-in-English--verb-to-learn-past-participle)
|
||||
(not (string= (learning-irregular-verbs-in-English--value-field-past-participle) "")))
|
||||
learning-irregular-verbs-in-English--emoji-valid learning-irregular-verbs-in-English--emoji-error))))
|
||||
|
||||
(defun toggle-layout-success ()
|
||||
(defun learning-irregular-verbs-in-English--toggle-layout-success ()
|
||||
"Toggle the layout to success."
|
||||
(if (eq learning-irregular-verbs-in-English--state 3)
|
||||
(progn
|
||||
@ -219,7 +218,7 @@
|
||||
(setq learning-irregular-verbs-in-English--widget-button-quit (widget-create 'push-button
|
||||
:size 20
|
||||
:notify (lambda (&rest ignore)
|
||||
(kill-app))
|
||||
(learning-irregular-verbs-in-English--kill-app))
|
||||
learning-irregular-verbs-in-English--text-button-quit))
|
||||
(widget-backward 2)
|
||||
)
|
||||
@ -232,7 +231,7 @@
|
||||
(when (not (eq learning-irregular-verbs-in-English--widget-button-quit nil)) (widget-delete learning-irregular-verbs-in-English--widget-button-quit))
|
||||
)))
|
||||
|
||||
(defun make-button-check ()
|
||||
(defun learning-irregular-verbs-in-English--make-button-check ()
|
||||
"Make the button check."
|
||||
(setq learning-irregular-verbs-in-English--widget-button-check (widget-create 'push-button
|
||||
:notify (lambda (&rest ignore)
|
||||
@ -246,11 +245,11 @@
|
||||
;; Set the learning-irregular-verbs-in-English--state
|
||||
(setq learning-irregular-verbs-in-English--state 1)
|
||||
;; Get a new verb
|
||||
(set-verb-to-learn)
|
||||
(learning-irregular-verbs-in-English--set-verb-to-learn)
|
||||
;; Show the verb in infinitive
|
||||
(widget-value-set learning-irregular-verbs-in-English--widget-item-verb (format-value-infinitive))
|
||||
(widget-value-set learning-irregular-verbs-in-English--widget-item-verb (learning-irregular-verbs-in-English--format-value-infinitive))
|
||||
;; Reset button check
|
||||
(when (eq learning-irregular-verbs-in-English--widget-button-check nil) (make-button-check))
|
||||
(when (eq learning-irregular-verbs-in-English--widget-button-check nil) (learning-irregular-verbs-in-English--make-button-check))
|
||||
;; Clear the fields
|
||||
(widget-value-set learning-irregular-verbs-in-English--widget-field-simple-past "")
|
||||
(widget-value-set learning-irregular-verbs-in-English--widget-label-check-simple-past "")
|
||||
@ -271,23 +270,23 @@
|
||||
;; Is playing?
|
||||
(when (and (eq learning-irregular-verbs-in-English--state 1)
|
||||
(or
|
||||
(not (string= (value-field-simple-past) ""))
|
||||
(not (string= (value-field-past-participle) "")))
|
||||
(not (string= (learning-irregular-verbs-in-English--value-field-simple-past) ""))
|
||||
(not (string= (learning-irregular-verbs-in-English--value-field-past-participle) "")))
|
||||
)
|
||||
(setq learning-irregular-verbs-in-English--state 2))
|
||||
;; Check the answers
|
||||
(when (eq learning-irregular-verbs-in-English--state 2)
|
||||
;; Is win?
|
||||
(when (and
|
||||
(string= (value-field-simple-past) learning-irregular-verbs-in-English--verb-to-learn-simple-past)
|
||||
(string= (value-field-past-participle) learning-irregular-verbs-in-English--verb-to-learn-past-participle))
|
||||
(string= (learning-irregular-verbs-in-English--value-field-simple-past) learning-irregular-verbs-in-English--verb-to-learn-simple-past)
|
||||
(string= (learning-irregular-verbs-in-English--value-field-past-participle) learning-irregular-verbs-in-English--verb-to-learn-past-participle))
|
||||
;; Set the learning-irregular-verbs-in-English--state
|
||||
(setq learning-irregular-verbs-in-English--state 3))
|
||||
;; Update the check labels
|
||||
(widget-value-set learning-irregular-verbs-in-English--widget-label-check-simple-past (format-check-simple-past))
|
||||
(widget-value-set learning-irregular-verbs-in-English--widget-label-check-past-participle (format-check-past-participle)))
|
||||
(widget-value-set learning-irregular-verbs-in-English--widget-label-check-simple-past (learning-irregular-verbs-in-English--format-check-simple-past))
|
||||
(widget-value-set learning-irregular-verbs-in-English--widget-label-check-past-participle (learning-irregular-verbs-in-English--format-check-past-participle)))
|
||||
;; Update the success layout if needed
|
||||
(toggle-layout-success))
|
||||
(learning-irregular-verbs-in-English--toggle-layout-success))
|
||||
|
||||
(defun main-layout ()
|
||||
"Make widgets for the main layout."
|
||||
@ -315,7 +314,7 @@
|
||||
;; Label check
|
||||
(insert " ")
|
||||
(setq learning-irregular-verbs-in-English--widget-label-check-simple-past (widget-create 'item
|
||||
(format-check-simple-past)))
|
||||
(learning-irregular-verbs-in-English--format-check-simple-past)))
|
||||
;; Separator
|
||||
(insert "\nPast participle ➡️ ")
|
||||
;; Past participle
|
||||
@ -325,22 +324,25 @@
|
||||
;; Label check
|
||||
(insert " ")
|
||||
(setq learning-irregular-verbs-in-English--widget-label-check-past-participle (widget-create 'item
|
||||
(format-check-past-participle)))
|
||||
(learning-irregular-verbs-in-English--format-check-past-participle)))
|
||||
;; Separator
|
||||
(insert "\n")
|
||||
;; Check button
|
||||
(make-button-check)
|
||||
(learning-irregular-verbs-in-English--make-button-check)
|
||||
;; Display the buffer
|
||||
(use-local-map widget-keymap)
|
||||
(widget-setup))
|
||||
|
||||
;; Keybindings
|
||||
(define-key widget-keymap (kbd "q") 'kill-app)
|
||||
(define-key widget-keymap (kbd "q") 'learning-irregular-verbs-in-English--kill-app)
|
||||
|
||||
;; Init
|
||||
(defun learning-irregular-verbs-in-English ()
|
||||
"Application to learn and review irregular verbs in English."
|
||||
(interactive)
|
||||
(main-layout)
|
||||
(start)
|
||||
(widget-backward 1)))
|
||||
(widget-backward 1))
|
||||
|
||||
(provide 'learning-irregular-verbs-in-English)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user