Subject: Re: bug#76884: 30.1 problem with flyspell-maybe-correct-transposition

From: Eli Zaretskii <[email-masked]>
Date: Sun, 09 Mar 2025 21:08:25 +0200

> Date: Sun, 9 Mar 2025 13:46:23 -0300
> From: Jim Diamond <[email-masked]>
> Cc: [email-masked]
> 
> >> Result: I get "CAB", whereas I expect "ACB".  This is not merely
> >> unexpected, but an actual problem.
> 
> > What causes that problem is that add-hook you did.  If you want C-t to
> > transpose characters, and Flyspell to not react on C-t, then why did
> > you add to that hook?
> 
> I added to that hook because, when the above-mentioned "automatically fix
> transposition errors" stopped working (with my upgrade to 30.1), I went
> looking for a newer version of the software.  The original author told me
> that flyspell has had the ability to automatically fix transposition errors
> for some time, and thus he has stopped updating his code.  And he suggested
> I add that function to that hook.  So I did.
> 
> Given that he (presumably!) understands perfectly what his original
> software did, I assumed that adding to that hook would do the same thing.
> It doesn't, at least the way I am using it.

So let me see if I understand what you are describing.

You had a bunch of function in auto-correct.el which would
automatically fix transposed characters as side effect of expanding
abbrevs, which happens when you type a non-word character such as SPC
after a sequence of word-constituent characters.  This code stopped
working in Emacs 30.1 (any idea why, btw?).  So you were looking for a
replacement, and someone told you that setting flyspell-incorrect-hook
to call flyspell-maybe-correct-transposition would do the job.  But it
doesn't do the job as you'd like it, because it attempts to fix
mis-spellings too early, immediately when you type C-t instead of when
you type SPC after C-t.  So your bug report is that using
flyspell-maybe-correct-transposition this way doesn't work as you'd
like, and you consider that a bug.  Did I understand you correctly?

> I realize that the flyspell mechanism doesn't rely on abbrev mode, and so
> my original question to the gnu emacs newsgroup was a hope that someone
> with more elisp knowledge than me could help me out.  But, as I mentioned,
> someone with far more elisp knowledge than me claimed it was a bug, and I
> believed him.  So here we are.

If I understood you correctly, there's no bug in what
flyspell-maybe-correct-transposition does, and invoking it from
flyspell-incorrect-hook is indeed supposed to work as you see, which
is not what you want.  flyspell-incorrect-hook is called when Flyspell
decides the word before point is mis-spelled and underlines it with
that red wavy underline, and that happens as soon as you type C-t.

I think you should figure out why the functions you used before no
longer work and adapt them to Emacs 30, so you could keep using them
as you did before.  Because Flyspell and its hook will not allow you
to have the same functionality if the ability to type C-t without
having Flyspell intervene right away is not part of what
flyspell-maybe-correct-transposition can offer.

If you explain why auto-correct no longer works and show the details,
maybe we can even find the solution as part of this discussion,
although it will no longer be about a bug in Flyspell.