flyspell-correct
flyspell-correct copied to clipboard
flyspell-correct a region
Hi,
I was wondering if there is a built-in way to run flyspell-correct
on a selected region. So far, I have got this:
(defun +xx/spellcheck-region-and-launch (beg end)
"Spellcheck the selected region."
(interactive "r")
(when (use-region-p)
(flyspell-region beg end)
(flyspell-correct-wrapper)))
While it does indeed run flyspell
on the selected region, but after doing that, it proceeds to spellcheck the entire buffer with flyspell-correct
! Any help/tips/links would be very welcome. And apologies if this is not the right forum for this question. I'm happy to immediately delete this issue if this is the case.
Hi,
That's because flyspell-correct-wrapper
doesn't care about regions at all and was implemented with a slightly different use case in mind. I'd say that region correction is about active spell fixing and not about writing, while flyspell-correct-wrapper
is about active writing and spell fixing on the go. I type the text and then I notice that I have a typo, I call flyspell-correct-wrapper
, it allows me to fix that typo (and maybe more) and continue writing from the place I left.
And it doesn't mean that your use case is wrong or out of the scope of this library. I'd say, flyspell-correct
library should/could provide a function flyspell-correct-region
utilising flyspell-correct-at-point
for correction.
Hi,
Thanks. That was a great answer to read because it also goes into the philosophy of your implementation (active spellchecking vs. writing). As you might have seen from the code I included, I am rather bad at elisp since I use it only very occasionally and I probably know about 0.5% of what elisp has to offer.
I will try to implement something like flyspell-correct-region
(thanks for the tip, I'll use flyspell-correct-at-point
) one of these weekends when I find some time. If I do, I will try to send it to you for feedbacks and a possible contribution to your awesome library!
Cheers
FWIW, you may use narrow-to-region
in this case:
(defun +xx/spellcheck-region-and-launch (beg end)
(interactive "r")
(flyspell-region beg end)
(save-restriction
(narrow-to-region beg end)
(flyspell-correct-move (point-min) t t))
Not quite ideal because you cannot see other parts of the buffer while correcting words. So IMO a dedicated command without narrowing is still useful.