Fix scope in package

This commit is contained in:
Andros Fenollosa 2024-01-02 17:32:15 +01:00
parent 2f30f0180e
commit 49e6e3e10c

View File

@ -11,10 +11,14 @@
;;; Code: ;;; Code:
(defun learning-irregular-verbs-in-English () ;; Imports
"Application to learn and review irregular verbs in English." (require 'widget)
(interactive) (eval-when-compile
(let* ((learning-irregular-verbs-in-English--verbs '( (require 'wid-edit))
;; Variables
(defvar learning-irregular-verbs-in-English--verbs '(
("beat" "beat" "beaten") ("beat" "beat" "beaten")
("become" "became" "become") ("become" "became" "become")
("begin" "began" "begun") ("begin" "began" "begun")
@ -114,82 +118,77 @@
("wear" "wore" "worn") ("wear" "wore" "worn")
("win" "won" "won") ("win" "won" "won")
("write" "wrote" "written"))) ("write" "wrote" "written")))
;; learning-irregular-verbs-in-English ;; learning-irregular-verbs-in-English
(learning-irregular-verbs-in-English--buffer-name "*Learning irregular verbs in English*") (defvar 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) (defvar 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) (defvar learning-irregular-verbs-in-English--verb-to-learn-infinitive nil)
(learning-irregular-verbs-in-English--verb-to-learn-simple-past nil) (defvar learning-irregular-verbs-in-English--verb-to-learn-simple-past nil)
(learning-irregular-verbs-in-English--verb-to-learn-past-participle nil) (defvar learning-irregular-verbs-in-English--verb-to-learn-past-participle nil)
(learning-irregular-verbs-in-English--emoji-valid "") (defvar learning-irregular-verbs-in-English--emoji-valid "")
(learning-irregular-verbs-in-English--emoji-error "👎") (defvar learning-irregular-verbs-in-English--emoji-error "👎")
(learning-irregular-verbs-in-English--widget-title nil) (defvar learning-irregular-verbs-in-English--widget-title nil)
(learning-irregular-verbs-in-English--text-title " 🧑‍🎓 Learning irregular verbs in English 🇬🇧") (defvar learning-irregular-verbs-in-English--text-title " 🧑‍🎓 Learning irregular verbs in English 🇬🇧")
(learning-irregular-verbs-in-English--widget-item-verb nil) (defvar learning-irregular-verbs-in-English--widget-item-verb nil)
(learning-irregular-verbs-in-English--widget-field-simple-past nil) (defvar learning-irregular-verbs-in-English--widget-field-simple-past nil)
(learning-irregular-verbs-in-English--widget-label-check-simple-past nil) (defvar learning-irregular-verbs-in-English--widget-label-check-simple-past nil)
(learning-irregular-verbs-in-English--widget-field-past-participle nil) (defvar learning-irregular-verbs-in-English--widget-field-past-participle nil)
(learning-irregular-verbs-in-English--widget-label-check-past-participle nil) (defvar learning-irregular-verbs-in-English--widget-label-check-past-participle nil)
(learning-irregular-verbs-in-English--text-button-check "Check") (defvar learning-irregular-verbs-in-English--text-button-check "Check")
(learning-irregular-verbs-in-English--widget-button-check nil) (defvar learning-irregular-verbs-in-English--widget-button-check nil)
(learning-irregular-verbs-in-English--widget-message-success nil) (defvar learning-irregular-verbs-in-English--widget-message-success nil)
(learning-irregular-verbs-in-English--widget-item-space-before-success nil) (defvar learning-irregular-verbs-in-English--widget-item-space-before-success nil)
(learning-irregular-verbs-in-English--text-success "Nice!") (defvar learning-irregular-verbs-in-English--text-success "Nice!")
(learning-irregular-verbs-in-English--widget-item-space-after-success nil) (defvar learning-irregular-verbs-in-English--widget-item-space-after-success nil)
(learning-irregular-verbs-in-English--widget-button-quit nil) (defvar learning-irregular-verbs-in-English--widget-button-quit nil)
(learning-irregular-verbs-in-English--text-button-quit "Quit") (defvar learning-irregular-verbs-in-English--text-button-quit "Quit")
(learning-irregular-verbs-in-English--widget-item-space-between-buttons nil) (defvar learning-irregular-verbs-in-English--widget-item-space-between-buttons nil)
(learning-irregular-verbs-in-English--widget-button-replay nil) (defvar learning-irregular-verbs-in-English--widget-button-replay nil)
(learning-irregular-verbs-in-English--text-button-replay "New challenge")) (defvar learning-irregular-verbs-in-English--text-button-replay "New challenge")
;; Imports
(require 'widget)
(eval-when-compile
(require 'wid-edit))
;; Functions ;; Functions
(defun kill-app () (defun learning-irregular-verbs-in-English--kill-app ()
"Kill the application." "Kill the application."
(interactive)
(kill-buffer learning-irregular-verbs-in-English--buffer-name)) (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) "")) (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) "")) (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." "Set the verb to learn."
(let ((verbs-random (nth (random (length learning-irregular-verbs-in-English--verbs)) learning-irregular-verbs-in-English--verbs))) (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-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-simple-past (nth 1 verbs-random))
(setq learning-irregular-verbs-in-English--verb-to-learn-past-participle (nth 2 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 the value of the infinitive."
(format "Infinitive ➡️ %s" learning-irregular-verbs-in-English--verb-to-learn-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." "Format the value of the simple past."
(if (eq learning-irregular-verbs-in-English--state 1) (if (eq learning-irregular-verbs-in-English--state 1)
"" ""
(format " %s" (if (format " %s" (if
(and (and
(string= (value-field-simple-past) learning-irregular-verbs-in-English--verb-to-learn-simple-past) (string= (learning-irregular-verbs-in-English--value-field-simple-past) learning-irregular-verbs-in-English--verb-to-learn-simple-past)
(not (string= (value-field-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)))) 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." "Format the value of the past participle."
(if (eq learning-irregular-verbs-in-English--state 1) (if (eq learning-irregular-verbs-in-English--state 1)
"" ""
(format " %s" (if (format " %s" (if
(and (and
(string= (value-field-past-participle) learning-irregular-verbs-in-English--verb-to-learn-past-participle) (string= (learning-irregular-verbs-in-English--value-field-past-participle) learning-irregular-verbs-in-English--verb-to-learn-past-participle)
(not (string= (value-field-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)))) 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." "Toggle the layout to success."
(if (eq learning-irregular-verbs-in-English--state 3) (if (eq learning-irregular-verbs-in-English--state 3)
(progn (progn
@ -219,7 +218,7 @@
(setq learning-irregular-verbs-in-English--widget-button-quit (widget-create 'push-button (setq learning-irregular-verbs-in-English--widget-button-quit (widget-create 'push-button
:size 20 :size 20
:notify (lambda (&rest ignore) :notify (lambda (&rest ignore)
(kill-app)) (learning-irregular-verbs-in-English--kill-app))
learning-irregular-verbs-in-English--text-button-quit)) learning-irregular-verbs-in-English--text-button-quit))
(widget-backward 2) (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)) (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." "Make the button check."
(setq learning-irregular-verbs-in-English--widget-button-check (widget-create 'push-button (setq learning-irregular-verbs-in-English--widget-button-check (widget-create 'push-button
:notify (lambda (&rest ignore) :notify (lambda (&rest ignore)
@ -240,17 +239,17 @@
learning-irregular-verbs-in-English--text-button-check))) learning-irregular-verbs-in-English--text-button-check)))
(defun start () (defun start ()
"Start o replay challenge." "Start o replay challenge."
(interactive) (interactive)
;; Set the learning-irregular-verbs-in-English--state ;; Set the learning-irregular-verbs-in-English--state
(setq learning-irregular-verbs-in-English--state 1) (setq learning-irregular-verbs-in-English--state 1)
;; Get a new verb ;; Get a new verb
(set-verb-to-learn) (learning-irregular-verbs-in-English--set-verb-to-learn)
;; Show the verb in infinitive ;; 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 ;; 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 ;; Clear the fields
(widget-value-set learning-irregular-verbs-in-English--widget-field-simple-past "") (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 "") (widget-value-set learning-irregular-verbs-in-English--widget-label-check-simple-past "")
@ -259,37 +258,37 @@
;; Update labels ;; Update labels
(update)) (update))
(defun replay () (defun replay ()
"Replay the challenge." "Replay the challenge."
(interactive) (interactive)
(start) (start)
(widget-backward 1)) (widget-backward 1))
(defun update () (defun update ()
"Check the answers." "Check the answers."
(interactive) (interactive)
;; Is playing? ;; Is playing?
(when (and (eq learning-irregular-verbs-in-English--state 1) (when (and (eq learning-irregular-verbs-in-English--state 1)
(or (or
(not (string= (value-field-simple-past) "")) (not (string= (learning-irregular-verbs-in-English--value-field-simple-past) ""))
(not (string= (value-field-past-participle) ""))) (not (string= (learning-irregular-verbs-in-English--value-field-past-participle) "")))
) )
(setq learning-irregular-verbs-in-English--state 2)) (setq learning-irregular-verbs-in-English--state 2))
;; Check the answers ;; Check the answers
(when (eq learning-irregular-verbs-in-English--state 2) (when (eq learning-irregular-verbs-in-English--state 2)
;; Is win? ;; Is win?
(when (and (when (and
(string= (value-field-simple-past) learning-irregular-verbs-in-English--verb-to-learn-simple-past) (string= (learning-irregular-verbs-in-English--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-past-participle) learning-irregular-verbs-in-English--verb-to-learn-past-participle))
;; Set the learning-irregular-verbs-in-English--state ;; Set the learning-irregular-verbs-in-English--state
(setq learning-irregular-verbs-in-English--state 3)) (setq learning-irregular-verbs-in-English--state 3))
;; Update the check labels ;; 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-simple-past (learning-irregular-verbs-in-English--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-past-participle (learning-irregular-verbs-in-English--format-check-past-participle)))
;; Update the success layout if needed ;; Update the success layout if needed
(toggle-layout-success)) (learning-irregular-verbs-in-English--toggle-layout-success))
(defun main-layout () (defun main-layout ()
"Make widgets for the main layout." "Make widgets for the main layout."
(interactive) (interactive)
;; Create the buffer ;; Create the buffer
@ -315,7 +314,7 @@
;; Label check ;; Label check
(insert " ") (insert " ")
(setq learning-irregular-verbs-in-English--widget-label-check-simple-past (widget-create 'item (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 ;; Separator
(insert "\nPast participle ➡️ ") (insert "\nPast participle ➡️ ")
;; Past participle ;; Past participle
@ -325,22 +324,25 @@
;; Label check ;; Label check
(insert " ") (insert " ")
(setq learning-irregular-verbs-in-English--widget-label-check-past-participle (widget-create 'item (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 ;; Separator
(insert "\n") (insert "\n")
;; Check button ;; Check button
(make-button-check) (learning-irregular-verbs-in-English--make-button-check)
;; Display the buffer ;; Display the buffer
(use-local-map widget-keymap) (use-local-map widget-keymap)
(widget-setup)) (widget-setup))
;; Keybindings ;; Keybindings
(define-key widget-keymap (kbd "q") 'kill-app) (define-key widget-keymap (kbd "q") 'learning-irregular-verbs-in-English--kill-app)
;; Init ;; Init
(defun learning-irregular-verbs-in-English ()
"Application to learn and review irregular verbs in English."
(interactive)
(main-layout) (main-layout)
(start) (start)
(widget-backward 1))) (widget-backward 1))
(provide 'learning-irregular-verbs-in-English) (provide 'learning-irregular-verbs-in-English)