Skip to content

Commit

Permalink
Make speed-type-complete public and interactive
Browse files Browse the repository at this point in the history
Workaround for #9
  • Loading branch information
dakra committed Aug 15, 2022
1 parent a3540c3 commit 1327c3a
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions speed-type.el
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,6 @@
"Practice touch-typing in Emacs."
:group 'games)

(define-derived-mode speed-type-mode fundamental-mode "SpeedType"
"Major mode for practicing touch typing."
:group "speed-type")

(defcustom speed-type-min-chars 200
"The minimum number of chars to type required when the text is picked randomly."
:group 'speed-type
Expand Down Expand Up @@ -149,6 +145,16 @@ Total errors: %d
(define-key map (kbd "n") 'speed-type--play-next)
map))

(defvar speed-type-mode-map
(let ((keymap (make-sparse-keymap)))
(define-key keymap (kbd "C-c C-k") #'speed-type-complete)
keymap)
"Keymap for `speed-type-mode'.")

(define-derived-mode speed-type-mode fundamental-mode "SpeedType"
"Major mode for practicing touch typing."
:group "speed-type")

;; buffer local internal variables

(defvar-local speed-type--start-time nil)
Expand Down Expand Up @@ -314,8 +320,9 @@ Accuracy is computed as (CORRECT-ENTRIES - CORRECTIONS) / TOTAL-ENTRIES."
(kill-this-buffer)
(funcall fn))))

(defun speed-type--handle-complete ()
(defun speed-type-complete ()
"Remove typing hooks from the buffer and print statistics."
(interactive)
(remove-hook 'after-change-functions 'speed-type--change)
(remove-hook 'first-change-hook 'speed-type--first-change)
(goto-char (point-max))
Expand Down Expand Up @@ -381,7 +388,7 @@ are color coded and stats are gathered about the typing performance."
(speed-type--diff orig new-text start end)
(goto-char end)
(when (= speed-type--remaining 0)
(speed-type--handle-complete))))))
(speed-type-complete))))))

(defun speed-type--first-change ()
"Start the timer."
Expand Down

0 comments on commit 1327c3a

Please sign in to comment.