Skip to content

Commit

Permalink
treat skip as one-time rapid mode enabler
Browse files Browse the repository at this point in the history
Required for #58
  • Loading branch information
d12frosted committed Feb 15, 2020
1 parent 747e1a9 commit 8b0831e
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 11 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.org
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
- Rewrite all tests using [[https://github.com/jorgenschaefer/emacs-buttercup][buttercup]] library.
- Allow to correct and save the word in one pass (see #66).
- New action - =stop= allowing to leave the point at the misspelled word.
- =skip= action now allows to correct 'next' word even if rapid mode is not
enabled (#58).

* v0.6.1

Expand Down
11 changes: 8 additions & 3 deletions flyspell-correct.el
Original file line number Diff line number Diff line change
Expand Up @@ -311,9 +311,14 @@ until all errors in buffer have been addressed."
hard-move-point t))

;; break from rapid mode
(when (or (not rapid)
(eq (car-safe res) 'break)
(eq (car-safe res) 'stop))
(when (or
;; treat skip as one-time rapid mode enabler
(and (not (eq (car-safe res) 'skip))
(not rapid))

;; explicit rapid mode disablers
(eq (car-safe res) 'break)
(eq (car-safe res) 'stop))
(setq overlay nil))

;; push mark
Expand Down
81 changes: 73 additions & 8 deletions test/test-flyspell-correct.el
Original file line number Diff line number Diff line change
Expand Up @@ -377,24 +377,57 @@ Simply passed WORD to `correct-word' mock."
(with-mistakes|cursor-before
(flyspell-correct-next (point))

(expect-no-correction "versiuns")))
(expect 'correct-interface :to-have-been-called-times 2)
(expect 'correct-word :to-have-been-called-times 2)
(expect 'correct-word :to-have-been-called-with "versiuns")
(expect 'correct-word :to-have-been-called-with "werk")
(expect 'flyspell-do-correct :not :to-have-been-called)))

(it "call correct when the cursor is at the beginning of misspelled word"
(with-mistakes|cursor-beginning
(flyspell-correct-next (point))
(expect-no-correction "versiuns")))

(expect 'correct-interface :to-have-been-called-times 2)
(expect 'correct-word :to-have-been-called-times 2)
(expect 'correct-word :to-have-been-called-with "versiuns")
(expect 'correct-word :to-have-been-called-with "werk")
(expect 'flyspell-do-correct :not :to-have-been-called)))

(it "call correct when the cursor is inside of misspelled word"
(with-mistakes|cursor-inside
(flyspell-correct-next (point))

(expect-no-correction "versiuns")))
(expect 'correct-interface :to-have-been-called-times 2)
(expect 'correct-word :to-have-been-called-times 2)
(expect 'correct-word :to-have-been-called-with "versiuns")
(expect 'correct-word :to-have-been-called-with "werk")
(expect 'flyspell-do-correct :not :to-have-been-called)))

(it "call correct when the cursor is at the end of misspelled word"
(with-mistakes|cursor-end
(flyspell-correct-next (point))

(expect-no-correction "versiuns"))))
(expect 'correct-interface :to-have-been-called-times 2)
(expect 'correct-word :to-have-been-called-times 2)
(expect 'correct-word :to-have-been-called-with "versiuns")
(expect 'correct-word :to-have-been-called-with "werk")
(expect 'flyspell-do-correct :not :to-have-been-called)))

(it "act as a one-time rapid mode enabler"
(with-mistakes|cursor-before-all
(spy-on 'correct-word :and-call-fake
(lambda (word)
(if (string-equal word "versiuns")
"versions"
(cons 'skip word))))

(flyspell-correct-next (point))

(expect 'correct-interface :to-have-been-called-times 2)
(expect 'correct-word :to-have-been-called-times 2)
(expect 'correct-word :to-have-been-called-with "Generel")
(expect 'correct-word :to-have-been-called-with "versiuns")
(expect 'flyspell-do-correct :to-have-been-called-with-nth 0 "versions"))))

(describe "action - stop"

Expand Down Expand Up @@ -468,25 +501,57 @@ Simply passed WORD to `correct-word' mock."
(with-mistakes|cursor-beginning
(flyspell-correct-previous (point))

(expect-no-correction "versiuns")))
(expect 'correct-interface :to-have-been-called-times 2)
(expect 'correct-word :to-have-been-called-times 2)
(expect 'correct-word :to-have-been-called-with "versiuns")
(expect 'correct-word :to-have-been-called-with "Generel")
(expect 'flyspell-do-correct :not :to-have-been-called)))

(it "call correct when the cursor is inside of misspelled word, but skip"
(with-mistakes|cursor-inside
(flyspell-correct-previous (point))

(expect-no-correction "versiuns")))
(expect 'correct-interface :to-have-been-called-times 2)
(expect 'correct-word :to-have-been-called-times 2)
(expect 'correct-word :to-have-been-called-with "versiuns")
(expect 'correct-word :to-have-been-called-with "Generel")
(expect 'flyspell-do-correct :not :to-have-been-called)))

(it "call correct when the cursor is at the end of misspelled word"
(with-mistakes|cursor-end
(flyspell-correct-previous (point))

(expect-no-correction "versiuns")))
(expect 'correct-interface :to-have-been-called-times 2)
(expect 'correct-word :to-have-been-called-times 2)
(expect 'correct-word :to-have-been-called-with "versiuns")
(expect 'correct-word :to-have-been-called-with "Generel")
(expect 'flyspell-do-correct :not :to-have-been-called)))

(it "call correct when the cursor is after misspelled word"
(with-mistakes|cursor-after
(flyspell-correct-previous (point))

(expect-no-correction "versiuns"))))
(expect 'correct-interface :to-have-been-called-times 2)
(expect 'correct-word :to-have-been-called-times 2)
(expect 'correct-word :to-have-been-called-with "versiuns")
(expect 'correct-word :to-have-been-called-with "Generel")
(expect 'flyspell-do-correct :not :to-have-been-called)))

(it "act as a one-time rapid mode enabler"
(with-mistakes|cursor-after-all
(spy-on 'correct-word :and-call-fake
(lambda (word)
(if (string-equal word "versiuns")
"versions"
(cons 'skip word))))

(flyspell-correct-previous (point))

(expect 'correct-interface :to-have-been-called-times 2)
(expect 'correct-word :to-have-been-called-times 2)
(expect 'correct-word :to-have-been-called-with "werk")
(expect 'correct-word :to-have-been-called-with "versiuns")
(expect 'flyspell-do-correct :to-have-been-called-with-nth 0 "versions"))))

(describe "action - stop"

Expand Down

1 comment on commit 8b0831e

@gusbrs
Copy link
Contributor

@gusbrs gusbrs commented on 8b0831e Feb 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A suggested small improvement of this commit is to rephrase the description of action "skip" in the docstring of flyspell-correct-interface, for something like:

"- skip - do nothing to misspelled word, used for jumping to the next (or previous) misspelled word, whether in rapid mode or not"

Please sign in to comment.