Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

flyspell-correct a region #103

Open
ChauhanT opened this issue Feb 10, 2022 · 3 comments
Open

flyspell-correct a region #103

ChauhanT opened this issue Feb 10, 2022 · 3 comments

Comments

@ChauhanT
Copy link

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.

@d12frosted
Copy link
Owner

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.

@ChauhanT
Copy link
Author

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

@ghost
Copy link

ghost commented Nov 11, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants