Aurebesh typing test for emacs

This entry is part 3 of 3 in the series Aurebesh

A few weeks ago, I posted the Aurebesh typing test. Since I’ve recently started learning elisp, I figured that I should implement the typing test as a feature for emacs.

The code below is terrible with bugs and problems, but heck, it’s my first elisp program after all. My goal is to improve the version over time and to add features such as logging results in a separate file and displaying a progress statistic. To use it, you’ll need to first install the Aurebesh font.

(setq correct 0)
(setq wrong 0)
(setq seconds-left 60)
(setq test-start t)

(require 'widget)

(defun aurebesh-typing-test ()
  "Aurebesh typing test"
  (get-buffer-create "*Aurebesh typing test*")

(defun custom/reset-aurebesh-typing-test-vars()
  (setq test-start t)
  (setq correct 0)
  (setq wrong 0)
  (setq seconds-left 60))

(defun custom/aurebesh-typing-test()
  (with-current-buffer "*Aurebesh typing test*"
    (insert "Correct / wrong answers: " (number-to-string correct) " / " (number-to-string wrong) " \n")

(defun custom/setup-buffer()
  (let ((inhibit-read-only t))

(defun custom/refresh-seconds()
    (goto-line 1)
    (insert "Seconds: " (number-to-string seconds-left) "\n")))

(defun custom/delete-line()
  (let ((beg (point)))
    (forward-line 1)
    (delete-region beg (point))))

(defun custom/create-line-with-widget()
  (if (> seconds-left 0)
      (setq randomChar (custom/get-random-char))
    (setq randomChar ""))
  (widget-insert randomChar)
  (widget-insert "\t")
  (widget-create 'editable-field
		 :size 15
		 :correct (string randomChar)
		 :notify 'custom/check-input-value)
  (widget-insert "\n"))

(defun custom/setup-widget()
  (use-local-map widget-keymap)
  (widget-forward 1))

(defun custom/set-aurebesh()
  "Sets the aurebesh font in current buffer"
  (setq buffer-face-mode-face '(:family "Aurebesh"))

(defun custom/check-input-value(widget &rest ignore)
  "Compare aurebesh input character with requested one."
     (widget-get widget :correct)
     (widget-value widget))
    (custom/correct-input widget))
   ((not(= (length (widget-value widget)) 0))

(defun custom/correct-input(widget)
  (if test-start
	(setq test-start nil)))
  (if (> seconds-left 0)
	(setq correct (+ correct 1))
	(custom/next-character widget))))

(defun custom/start-timer()
  "Start Aurebesh test"
  (setq seconds-left 60)
  (setq timer (run-with-timer 0 1 'custom/decrement-seconds)))

(defun custom/decrement-seconds()
  (with-current-buffer "*Aurebesh typing test*"
    (if (> seconds-left 0)
;	(progn
	  (setq seconds-left (- seconds-left 1))
;	  (custom/refresh-seconds)
;	  (widget-forward 1))

(defun custom/stop-aurebesh-typing-test()
  (with-current-buffer "*Aurebesh typing test*"
  (cancel-timer timer)

(defun custom/set-arial()
   "Sets the arial font in current buffer"
   (setq buffer-face-mode-face '(:family "Arial"))

(defun custom/next-character(widget)
  (with-current-buffer "*Aurebesh typing test*"
    (custom/fill-random-character widget)
    (widget-forward 1)

(defun custom/fill-random-character(widget)
    (goto-line 2))
  (delete-char 1)
  (if (> seconds-left 0)
      (setq randomChar (custom/get-random-char))
    (setq randomChar ""))
  (widget-insert randomChar)
  (widget-put widget :correct (string randomChar))
  (widget-value-set widget ""))

(defun custom/get-random-char ()
  "Insert a random alphanumeric character.."
  (let ((mycharset "abcdefghijklmnopqrstyvwxyz"))
    (elt mycharset (random (length mycharset)))))

(defun custom/fill-correct-wrong-answers()
    (goto-line 3))
  (insert "Correct / wrong answers: " (number-to-string correct) " / " (number-to-string wrong) " \n"))
(defun custom/wrong-input()
  (message "%s" (widget-get widget :correct))
  (widget-value-set widget "")
  (setq wrong (+ wrong 1)))
Series Navigation<< Aurebesh typing test

Leave a Reply

Your email address will not be published. Required fields are marked *