Skip to content

Commit 33a5b27

Browse files
committed
Add monkeytype-load-words-from-file
1 parent 9913958 commit 33a5b27

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

README.org

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ At this point you can either practice mistyped words with =monkeytype-mistyped-w
4949
- Practice mistyped words.
5050
- Practice troubling/hard key combinations/transitions (useful when practising with different keyboard layouts).
5151
- Mistyped words or hard transitions can be saved to =~/.monkeype/{words or transitions}= (see: =monkeytype-directory= =monkeytype-save-mistyped-words= =monkeytype-save-hard-transitions=).
52+
- Saved mistyped/transitions files (or any file but defaults to =~/.monkeytype/= dir) can be loaded with =monkeytyped-load-words-from-file=.
5253
- Visual representation of typed text including errors and retries/corrections.
5354
- UI customisation.
5455
- Optionally randomise practice words/transitions (see: =monkeytype-randomize=).
@@ -89,6 +90,7 @@ This can then be enabled with a hook in your =.emacs=:
8990
|-------------+------------------------------------|
9091
| | =monkeytype-region= |
9192
| | =monkeytype-buffer= |
93+
| | =monkeytype-load-words-from-file= |
9294
| | =monkeytype-region-as-words= |
9395
| C-c C-c f | =monkeytype-fortune= |
9496
| C-c C-c p | =monkeytype-pause= |

monkeytype.el

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,6 +1114,28 @@ This is unless the char isn't a valid word character in `monkeytype-word-regexp'
11141114
(with-temp-file path (insert transitions))
11151115
(message "Monkeytype: Transitions saved successfully to file: %s" path)))
11161116

1117+
;;;###autoload
1118+
(defun monkeytype-load-words-from-file ()
1119+
"Prompt user to enter words-file to use for typing.
1120+
1121+
Words will be randomized if `monkeytype-randomize' is set to true.
1122+
Words will be downcased if `monkeytype-downcase' is set to true.
1123+
Words special characters will get removed based on `monkeytype-word-regexp'.
1124+
Buffer will be filled with the vale of `fill-column' if `monkeytype-auto-fill'
1125+
is set to true.
1126+
1127+
\\[monkeytype-load-words-from-file]"
1128+
(interactive)
1129+
(let* ((file-path (read-file-name "Enter words file:" monkeytype-directory))
1130+
(words (with-temp-buffer
1131+
(insert-file-contents file-path)
1132+
(buffer-string)))
1133+
(words (split-string words monkeytype-word-regexp t))
1134+
(words (mapconcat
1135+
(lambda (word) (if monkeytype-downcase (downcase word) word))
1136+
(if monkeytype-randomize (monkeytype--utils-nshuffle words) words) " ")))
1137+
(monkeytype--init words)))
1138+
11171139
;;;###autoload
11181140
(defun monkeytype-region-as-words (start end)
11191141
"Put the marked region from START to END in typing buffer.

0 commit comments

Comments
 (0)