Skip to content

Commit 15d7176

Browse files
authored
Merge pull request #99 from dakra/tests-refactoring
66 Improve Testing, Refactoring and Documentation
2 parents b3f59f0 + 047bbf7 commit 15d7176

File tree

5 files changed

+998
-463
lines changed

5 files changed

+998
-463
lines changed

README.md

Lines changed: 142 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,26 +34,44 @@ happens automatically, the clock starts on the first character typed and ends
3434
with the last. Statistics like characters typed, words-per-minute, and total
3535
time will be shown as soon as the last character is entered.
3636

37-
You can use any buffer or part of it to run speed-type. `M-x speed-type-region`
38-
and `M-x speed-type-buffer` will do the same thing as speed-type-text, except they
39-
take the text sample you've picked.
40-
This works for programming code buffers/regions as well.
37+
Random samples are taken from [Project Gutenberg](https://www.gutenberg.org/).
38+
A small number of books will be downloaded on demand and stored in
39+
`~/emacs.d/speed-type`. They will only be downloaded once.
40+
41+
You can configure a language (var `speed-type-default-lang`) which
42+
will pick books of this language. Beaware that gutenberg does not have
43+
hundreds of books for all supported languages.
4144

42-
`speed-type-buffer` by default will only take a random portion of the buffer - If
43-
you want the whole buffer, use `C-u speed-type-buffer`.
45+
If you'd like to type a book from start to finish while saving your
46+
progress you can set `speed-type-randomize` to `nil`.
47+
48+
You can use any buffer or part of it to run speed-type. `M-x speed-type-region` and `M-x speed-type-buffer` will do the same thing
49+
as `speed-type-text`, except they take the text sample you've picked.
50+
This works for programming code buffers/regions as well.
4451

45-
Random samples are taken from Project Gutenberg. A small number of books will be
46-
downloaded on demand and stored in "~/emacs.d/speed-type". They will only be
47-
downloaded once.
52+
`speed-type-buffer` by default will only take a random portion of the
53+
buffer - If you want the whole buffer, use `C-u speed-type-buffer`.
54+
You can also call `speed-type-buffer-top-x` which will calculate a
55+
frequency list of the current buffer and assemble text from the top
56+
words.
4857

4958
`speed-type-region` will start a speed-type session with the text from
5059
the selected region.
5160

5261
`speed-type-top-x` (or -100/-1000) lets you practice the top X words
53-
for the selected language.
62+
for the selected language. If your language isn't supported by this
63+
command you can try using `speed-type-text-top-x` (setting
64+
var `speed-type-default-lang` beforehand). Which will calculate a
65+
frequency list of a gutenberg book.
5466

55-
`speed-type-quote` by default will take a random quote from a random quote-url listed in `speed-type-quote-urls`. You can `C-u speed-type-quote` to specify the url.
67+
`speed-type-quote` by default will take a random quote from a random
68+
quote-url listed in `speed-type-quote-urls`. You can `C-u
69+
speed-type-quote` to specify the url.
5670

71+
`speed-type-pandoc` will prompt you for a URL (e.g. wikipedia) which
72+
will be downloaded. The contents will be used for setting up the text
73+
to type. `speed-type-pandoc-top-x` is also included and works similar
74+
to the other top-x-commands.
5775

5876
## Contribution
5977

@@ -126,3 +144,116 @@ included.
126144
[melpa-stable-link]: https://stable.melpa.org/#/speed-type
127145
[melpa-badge]: https://melpa.org/packages/speed-type-badge.svg
128146
[melpa-stable-badge]: https://stable.melpa.org/packages/speed-type-badge.svg
147+
148+
## Documentation
149+
A little diagram because [uniline](https://github.com/tbanel/uniline) is fun:
150+
```uniline
151+
╭────╮ ╭─────╮ ╭────────────╮
152+
│undo│ │pause│ │median stats│
153+
╰┬──┬╯ ╰┬───┬╯ ╰┬─────────┬─╯
154+
△ │ △ │ display △ │
155+
│ │ │ │ │ │
156+
│ ▽ │ ▽ resume │ ▽
157+
╭─────╮ ╭─────╮ ╭┴──┴─────┴───┴────╮ ╭─┴─────────┴─╮ ╭────╮
158+
│start├──▷┤setup├──────▷┤speed-type session├───▷┤complete/menu├────▷┤quit│
159+
╰─────╯ ╰─┬───╯ ╰──────────────────╯ ╰──────┬──────╯ ╰────╯
160+
△ │
161+
│ ▽
162+
│ ╭─────────────┴──────╮
163+
╰────────────────────────────┤replay/next/continue│
164+
╰────────────────────╯
165+
```
166+
167+
168+
### Start
169+
The flow is started by calling one of the autoloaded commands:
170+
- `speed-type-text`
171+
- `speed-type-text-top-x`
172+
- `speed-type-top-x`
173+
- `speed-type-top-100`
174+
- `speed-type-top-1000`
175+
- `speed-type-buffer`
176+
- `speed-type-buffer-top-x`
177+
- `speed-type-region`
178+
- `speed-type-quotes`
179+
- `speed-type-pandoc`
180+
- `speed-type-pandoc-top-x`
181+
- `speed-type-continue`
182+
183+
### Setup
184+
185+
Every speed-type buffer is created via the function
186+
`speed-type--setup`. This is a large, configurable function with many
187+
optional parameters that define how the flow should behave. Through
188+
these parameters you can control which buffer-local variables are
189+
initialized, which menu entries appear, and how new words are
190+
inserted. It also connects the various speed-type buffers and
191+
initializes all buffer-local variables required for a consistent
192+
typing session. In short, `speed-type--setup` is the blueprint for
193+
every typing session.
194+
195+
#### Buffers:
196+
- `speed-type-buffer`: The buffer in which typing takes places
197+
- `speed-type-content-buffer`: Contains the original content from which the flow was started. It's used for adding words and "continue" the content.
198+
- `speed-type-preview-buffer`: Buffer which "records" typed characters and "unusual" point movement
199+
200+
201+
### Speed-type session
202+
203+
This phase is the core of speed-type. While a typing session is
204+
active, hooks and timers run continuously. With every keystroke, the
205+
user's input is compared to the buffer contents. Based on the
206+
difference (match vs. mismatch), various buffer-local variables are
207+
updated, and characters update their status and color accordingly.
208+
209+
Performance is crucial in this phase: hooks must remain lightweight so
210+
that typing remains responsive and the user is not restricted in how
211+
they move or what commands they use to complete the session.
212+
213+
#### Hooks:
214+
- first-change-hook: Used to start the timer
215+
- before-change-functions: Used to store characters which are going be compared against.
216+
- after-change-functions: Used to compare the inserted characters with the actual characters
217+
218+
#### Overlay and Faces:
219+
To color the characters a overlay is used:
220+
- speed-type-correct-face
221+
- speed-type-error-face
222+
- speed-type-consecutive-error-face
223+
224+
#### Text Properties:
225+
- speed-type-orig-pos: Used for "continue" and add new words
226+
- car: start
227+
- cdr: end
228+
- speed-type-char-status: Used to ignore characters and determine complete
229+
- ignore
230+
- correct
231+
- error
232+
233+
### Completion and Menu
234+
235+
A typing session is considered complete when every character in the
236+
buffer has a `speed-type-char-status` property. Once all characters
237+
have such a value, completion is triggered.
238+
239+
At this point, the `speed-type-buffer` becomes read-only and only the
240+
menu-control keys remain active.
241+
242+
### Replay / Continue / Next
243+
244+
These actions are available from the menu. Based on the key the user
245+
presses, the corresponding action is invoked. The actions are
246+
processed in a similar way how a speed-type session was started. The
247+
action calls `speed-type--setup` with mostly the same parameters
248+
again, which starts a new session.
249+
250+
After setup is complete it kills the completed `speed-type-buffer` and
251+
`speed-type-preview-buffer`. It may reuse the existing content-buffer.
252+
253+
### Median Stats
254+
Calculates and displays the median stats of various buffer-local vars
255+
from current and previous speed-type sessions.
256+
257+
### Quit
258+
Kills the `speed-type-buffer` and all related buffers (content-buffer,
259+
preview-buffer, etc.).

0 commit comments

Comments
 (0)