GNU bug report logs - #76884
30.1 problem with flyspell-maybe-correct-transposition

Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.

Package: emacs; Reported by: Jim Diamond <jim@HIDDEN>; dated Sun, 9 Mar 2025 10:21:02 UTC; Maintainer for emacs is bug-gnu-emacs@HIDDEN.

Message received at 76884 <at> debbugs.gnu.org:


Received: (at 76884) by debbugs.gnu.org; 10 Mar 2025 00:44:07 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sun Mar 09 20:44:06 2025
Received: from localhost ([127.0.0.1]:35126 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1trRFW-00027T-7J
	for submit <at> debbugs.gnu.org; Sun, 09 Mar 2025 20:44:06 -0400
Received: from seout10.web-dns1.com ([68.168.119.164]:58430)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <jim@HIDDEN>) id 1trNkA-0002Jg-Pi
 for 76884 <at> debbugs.gnu.org; Sun, 09 Mar 2025 16:59:31 -0400
Received: from mailpro1.whc.ca ([51.79.16.13])
 by se2.web-dns1.com with esmtps (TLSv1.3:TLS_AES_256_GCM_SHA384:256)
 (Exim 4.92) (envelope-from <jim@HIDDEN>)
 id 1trNk2-00D4MI-NS; Sun, 09 Mar 2025 16:59:24 -0400
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=jdvb.ca;
 s=default; h=In-Reply-To:Content-Type:MIME-Version:References:Message-ID:
 Subject:Cc:To:From:Date:Sender:Reply-To:Content-Transfer-Encoding:Content-ID:
 Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc
 :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe:
 List-Post:List-Owner:List-Archive;
 bh=s0BUAusRnIAXJJtPYd9PngUFC2MzyFbbOXbpwJNEQVI=; b=ejY2B//tN/csIrOXIZgOchmVM8
 JqfD+D5GFS2AekwkV0t2bbq5MKYr2eNaoEpXVjZ+iQ38R7UbI3YcGJr7WV0YqoZxHi6FEU4DKe1mr
 F/WpYV2GnlUke6DajYMTH8aZR/IbRQtcG0r5Dk/7benq9srEapc9WF96kcBKmB4I7ZteLlbeg644u
 W65dE3RJhgfLLti+/H8jj+5V5M+MU4DDYuRbYNK08FIYEQxiqH03jZTjZTzS/77oeweg/PMuPg6aB
 QMZ7DG+nef1lypjKhEEOf2ozAhCFlFiqY4ztjanNCh/uHa68iMK2lEhDI2WIfxF1hbQUqwK5WGAUO
 aGnDPAkA==;
Received: from [47.55.144.2] (port=44398 helo=x360)
 by mailpro1.whc.ca with esmtpsa  (TLS1.3) tls TLS_AES_256_GCM_SHA384
 (Exim 4.98.1) (envelope-from <jim@HIDDEN>)
 id 1trNjv-0000000EDmM-2CJ3; Sun, 09 Mar 2025 16:59:22 -0400
Received: by x360 (Postfix, from userid 1000)
 id 1CC941E0DEC; Sun,  9 Mar 2025 17:59:15 -0300 (ADT)
Date: Sun, 9 Mar 2025 17:59:15 -0300
From: Jim Diamond <jim@HIDDEN>
To: Eli Zaretskii <eliz@HIDDEN>
Subject: Re: bug#76884: 30.1 problem with flyspell-maybe-correct-transposition
Message-ID: <Z84BI4Mn3kxNUn8z@HIDDEN>
References: <Z8zl0rLCkKr1EoCN@HIDDEN> <86h642foz4.fsf@HIDDEN>
 <Z83F34NPmdgviJXF@HIDDEN> <8634fmf2dy.fsf@HIDDEN>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <8634fmf2dy.fsf@HIDDEN>
X-Microslop: Just say no
X-Originating-IP: 51.79.16.13
X-SpamExperts-Domain: out.mailpro1.whc.ca
X-SpamExperts-Username: 51.79.16.13
Authentication-Results: web-dns1.com;
 auth=pass smtp.auth=51.79.16.13@HIDDEN
X-SpamExperts-Outgoing-Class: ham
X-SpamExperts-Outgoing-Evidence: Combined (0.25)
X-Recommended-Action: accept
X-Filter-ID: Pt3MvcO5N4iKaDQ5O6lkdGlMVN6RH8bjRMzItlySaT/sxpTJbH/ssszIkHCKSsMaPUtbdvnXkggZ
 3YnVId/Y5jcf0yeVQAvfjHznO7+bT5w2/21xCFlaeKR/ljIldgMAeeTGE6/jLakLVHLNXqEJIjBn
 ZTqcVNU3v+WQaLFrAJsBcORxfCojcTOpEjtvWHp2VsVtw+3H6wjbnL61CcYEDzg9YkzbMy6DOYhG
 3MUcvho42E9/62Xj4gVnOU7mzP18xFe4tDHRAAU4Z9kdrTgEkr1fWIyqtP2Az1FwKT/ERG71RZNZ
 veUd2FVzSNrwDlfLebQJE4GQsxSxOMSRBTDSGcW2K9b7rjx99/aQfurBJHGL5+B4CbE+8r16Dbly
 n0utIpxiiWsp7Mk+EIj3MIgTkJPXAQo9xY23wpdWb+XahseSGpuJN1OVhw4edWBUa0IbPrJgBAji
 PJ0fTqW8MNVzSevjEfTaJe0WbjDSwI4VsDh/Ak5UMKR5Jabn4uqWeMpVMYvjNLAeu65R4aCicH/Y
 kSJK/Ln5YFUvbRWjzq0hN/cgr/U0flMcy2Vi/IcBgY4aIg2Wh441Iy/oD6wYf/J+JKWMwC0nw67U
 B6OskYLcqyXIs4Ft+99WHPUTNuycPeLKw57g+35qANArPJpzfd56s1uu+gB0Wf8P1Q4/TvkENLFi
 hKNR925/EhmML9JllxEYr7VADYGHWaMbGyG9+CESnF9L2zldRguLVknTBH19KmbWXGH5SDG2kyRs
 dcYPy9StYCBYOOAn0b63Bjtd9P0Goyj8QN3aavIy6wdzZd1Ho1cWtdwXDJWqBppx2M9WuQ/C1sme
 kOl7hiQhsTB4c5tLi8A/9xGgj7taJxWtHZ97uYoKfn23zO74WXUImZcqpFdx9R/2gMGq0KWAzmMf
 +ibVDvZtlrYFmdpR2rHS8DVO66tNGZhQu+tLkmiW+qqRdhD9zqxoqKN/nsFBrDSi+Y/0ka3xLX/b
 yrPnUSu3af7DEjjpBpvE2ZlcNkHqKqlt37ebdvehk3pO1b68r8YdRXGgbvY4ocfmWv3Fe9Iziczd
 q+A=
X-Report-Abuse-To: spam@HIDDEN
X-Complaints-To: abuse@HIDDEN
X-Spam-Score: -0.7 (/)
X-Debbugs-Envelope-To: 76884
X-Mailman-Approved-At: Sun, 09 Mar 2025 20:43:58 -0400
Cc: 76884 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.7 (-)

On Sun, Mar  9, 2025 at 21:08 (+0200), Eli Zaretskii wrote:

>> Date: Sun, 9 Mar 2025 13:46:23 -0300
>> From: Jim Diamond <jim@HIDDEN>
>> Cc: 76884 <at> debbugs.gnu.org

>>>> 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?).

No, the error message I got was opaque to me, and so that was when I went
looking for a newer version of auto-correct.el

> 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.

Correct.

> 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.

Correct.

> 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?

No.  As I already said (twice?) I thought there might be some setting to
make it work as I would like, and I posted to the gnu emacs newsgroup,
where an experienced emacs and elisp person opined that it was a bug and I
should report it.

>> 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,

I'd say that is arguable, but let's carry on.

> 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.

Indeed it does.

> 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.

It would appear that is my way forward.

> 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.

OK.  I will interpret that as a definitive "no" answer to my original
question of "is there anything I can configure in flyspell to get what I
want.

> 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.

I will reset things back to how they were and wait for the problem to
repeat itself.  (Unfortunately, the error and subsequent backtrace are not
as easily reproducible as would be convenient.)

                                Jim




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#76884; Package emacs. Full text available.

Message received at 76884 <at> debbugs.gnu.org:


Received: (at 76884) by debbugs.gnu.org; 10 Mar 2025 00:44:02 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sun Mar 09 20:44:02 2025
Received: from localhost ([127.0.0.1]:35117 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1trRFR-00026P-Jy
	for submit <at> debbugs.gnu.org; Sun, 09 Mar 2025 20:44:02 -0400
Received: from seout14.web-dns1.com ([68.168.119.166]:46124)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <jim@HIDDEN>) id 1trJnV-0007TG-5m
 for 76884 <at> debbugs.gnu.org; Sun, 09 Mar 2025 12:46:41 -0400
Received: from mailpro1.whc.ca ([51.79.16.13])
 by se1.web-dns1.com with esmtps (TLSv1.3:TLS_AES_256_GCM_SHA384:256)
 (Exim 4.92) (envelope-from <jim@HIDDEN>)
 id 1trJnM-000EuT-Dl; Sun, 09 Mar 2025 12:46:34 -0400
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=jdvb.ca;
 s=default; h=In-Reply-To:Content-Type:MIME-Version:References:Message-ID:
 Subject:Cc:To:From:Date:Sender:Reply-To:Content-Transfer-Encoding:Content-ID:
 Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc
 :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe:
 List-Post:List-Owner:List-Archive;
 bh=IOOP/7upjsMfJnQUy29Uje0blhCfSlr2wnnxz8KRjEg=; b=nZCGwwQLLBlVSSaC7x7MDk0yuX
 7c61CHtxku6ix8xYKO+J110kou4TinO8DZwir25Px4X/Xm1BmZ9SoBeH/1buEtGl2KWOCKGY08wQ1
 DGOdayUwtN/HN9bvzxORIKixa6wpLA/He7GArS6EePabPclIBjLZOv34ZaWPigtP8iq6c8HXaIseS
 74AY+8njO1TWD3zqVLu9fCVjuPkeT/rQxv51xL/bP+CIJswq6RHqAN03SoCVykJn56CtnXP7NW2Tn
 WAzMJWA77o61j9AwK93luyDrE74RL60FIOJk7nHmORoBJAFKDuYNu2BZVrBofaBoBU83M4gd29iy4
 wJsddttg==;
Received: from [47.55.144.2] (port=42932 helo=x360)
 by mailpro1.whc.ca with esmtpsa  (TLS1.3) tls TLS_AES_256_GCM_SHA384
 (Exim 4.98.1) (envelope-from <jim@HIDDEN>)
 id 1trJnD-0000000Ctp3-3Nng; Sun, 09 Mar 2025 12:46:30 -0400
Received: by x360 (Postfix, from userid 1000)
 id 415E81E0DEC; Sun,  9 Mar 2025 13:46:23 -0300 (ADT)
Date: Sun, 9 Mar 2025 13:46:23 -0300
From: Jim Diamond <jim@HIDDEN>
To: Eli Zaretskii <eliz@HIDDEN>
Subject: Re: bug#76884: 30.1 problem with flyspell-maybe-correct-transposition
Message-ID: <Z83F34NPmdgviJXF@HIDDEN>
References: <Z8zl0rLCkKr1EoCN@HIDDEN>
 <86h642foz4.fsf@HIDDEN>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <86h642foz4.fsf@HIDDEN>
X-Microslop: Just say no
X-Originating-IP: 51.79.16.13
X-SpamExperts-Domain: out.mailpro1.whc.ca
X-SpamExperts-Username: 51.79.16.13
Authentication-Results: web-dns1.com;
 auth=pass smtp.auth=51.79.16.13@HIDDEN
X-SpamExperts-Outgoing-Class: ham
X-SpamExperts-Outgoing-Evidence: Combined (0.25)
X-Recommended-Action: accept
X-Filter-ID: Pt3MvcO5N4iKaDQ5O6lkdGlMVN6RH8bjRMzItlySaT+sjgGJyYjSsIbLy+M6M16KPUtbdvnXkggZ
 3YnVId/Y5jcf0yeVQAvfjHznO7+bT5w2/21xCFlaeKR/ljIldgMAeeTGE6/jLakLVHLNXqEJIjBn
 ZTqcVNU3v+WQaLFrAJsBcORxfCojcTOpEjtvWHp2neJO/Aomwg+5UeNQsy/u0Dg9YkzbMy6DOYhG
 3MUcvho42E9/62Xj4gVnOU7mzP18xFe4tDHRAAU4Z9kdrTgEkr1fWIyqtP2Az1FwKT/ERG5A23IV
 Cz9obSuNRYneElGLebQJE4GQsxSxOMSRBTDSGcW2K9b7rjx99/aQfurBJHGL5+B4CbE+8r16Dbly
 n0utIpxiiWsp7Mk+EIj3MIgTkJPXAQo9xY23wpdWb+XahseSGpuJN1OVhw4edWBUa0IbPrJgBAji
 PJ0fTqW8MNVzSevjEfTaJe0WbjDSwI4VsDh/Ak5UMKR5Jabn4uqWeMpVMYvjNLAeu65R4aCicH/Y
 kSJK/Ln5YFUvbRWjzq0hN/cgr/U0flMcy2Vi/IcBgY4aIg2Wh441Iy/oD6wYf/J+JKWMwC0nw67U
 B6OskYLcqyX1QKFLcL0wS6Dm1GCnj10T75zjwqr4AoZZnPmASpR5LpbFHlP9eR/RQEzrGyw6dukB
 /DVDmmMwr3DV303s3/+5No+FcdYLqmAuizoF+hlBHIEoL7oRiwAdl8TfOEaJomAIgflZ8nO54M5T
 uuEq4ZWS0i3GnaYu2Kt0mBKq1880AjiHz2DgWzoXCmpOpjxbMK/GdOAOljOmdzv3c6Yr0my0Ybjz
 rwR1D0UnZP7hlBaWxSG7X+t1TW39Ja77LGPpOwAKh/wfh5pNcaIENKNiRuEkYnNGFdRN3CtPPBjS
 HkIxZUze13Qmdgy1WOQgp+9BXipKr8DB55pPxQclO6XlolriLCUPaWdjVRTfh2Iq7+9OrgtHI0sr
 RlulocqwlfkrlFi/R/iAFUvEkJDEYnB5w5glm6ZNGZyGn3ta2iA9PFDDYFMq8BDKS9xOa7P+aYMH
 vy8=
X-Report-Abuse-To: spam@HIDDEN
X-Complaints-To: abuse@HIDDEN
X-Spam-Score: 0.0 (/)
X-Debbugs-Envelope-To: 76884
X-Mailman-Approved-At: Sun, 09 Mar 2025 20:43:58 -0400
Cc: 76884 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)

On Sun, Mar  9, 2025 at 13:00 (+0200), Eli Zaretskii wrote:

>> Date: Sat, 8 Mar 2025 20:50:26 -0400
>> From: Jim Diamond <jim@HIDDEN>

>> I recently upgraded to emacs 30.1.  For many years I had been using a
>> function which automatically corrected transposition errors, but it no
>> longer works in 30.1.  The author of that function kindly pointed me to the
>> fact that such functionality has been part of flyspell for a long time, and
>> that I should add
>>     (add-hook 'flyspell-incorrect-hook 'flyspell-maybe-correct-transposition)
>> to my init.el.

>> So I put that line in my init.el and started editing away, only to discover
>> that it doesn't do exactly what I want.  To reproduce the problem,


>> (1) Create a file ABC like this
>> ----------------- cut here --------------------

>> ABC

>> ----------------- cut here --------------------

>> (2) Replace your entire init.el with this one line:
>> (add-hook 'flyspell-incorrect-hook 'flyspell-maybe-correct-transposition)
>> (Or start with "emacs -Q" and make the "obvious" changes to the procedure
>> below.)

>> (3) Fire up a fresh emacs as follows:
>> emacs ABC

>> (4) Turn on flyspell
>> M-x flyspell-mode

>> (5) Navigate to the end of the 'abc' line

>> (6) Type Ctrl-T

>> 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.


> IOW, I don't understand what scenario worked for you in older versions
> of Emacs and no longer works in Emacs 30.1.  Could you please show a
> recipe, starting from "emacs -Q", which did NOT convert ABC into CAB
> in Emacs 29 or earlier, but does with Emacs 30.1?   Because if I try
> using that add-hook in Emacs 28.2, I get the same result: ABC => CAB,
> if I type C-t at the end of the ABC line.  So I'm confused regarding
> the problem which you found in Emacs 30 that didn't exist before.

I am thinking you ignored the part where I said "For many years I had been
using a function which automatically corrected transposition errors, but it
no longer works in 30.1.  The author of that function kindly pointed me to
the fact that such functionality has been part of flyspell for a long time,
and that I should add
     (add-hook 'flyspell-incorrect-hook 'flyspell-maybe-correct-transposition)
to my init.el."

(Many years is sincce 1999 or so, in case anyone reading this is wondering.)

So the "recipe" doesn't depend on flyspell.  It depends on abbrev-mode, and
most recently was triggered as follows:
        (advice-add abbrev-expand-function 
            :before (lambda () (fix-transposed-characters)))
This worked in 28.2 and (IIRC) in 29.4.


>> With my old setup in emacs 28 and before, the transposition correction
>> function was triggered when emacs was about to see if there was an
>> abbreviation to expand, so if I was anticipating a problem I could
>> transpose two letters and then move away from the "word" using something
>> other than a space (e.g., arrow keys), and the text would stay how I wanted
>> it.

> Sorry, I don't understand this description.  Could you please show a
> recipe with all the commands and key sequences explicit?


With apologies to the original author of the code (John Wiegley), here is
my somewhat modified version of his code which did what I want in 28.2.  I
hesitated to mention his name because some of my changes may be abhorrent
to him or other people reading this, and I don't want any bad thoughts or
words sent his way.

I don't have a system with 29.3 or 29.4 to test this, but I did test this
on 28.2.

(1) Put this code in a file called auto-correct.el:

%%%%%------------------ auto-correct.el --------------------

(require 'ispell)

(defvar correct-words-applicable-modes
  '(text-mode zsd-mail-mode c-mode c++-mode texinfo-mode plain-tex-mode)
  "*A list of modes in which words should be automatically corrected.")

(defun auto-correct-check-word ()
  "Call ispell-word with ispell-check-only set to t.
Setting this to t will not prompt for corrections, but return nil if the
word is incorrect.  Redefine (message) and (beep) to shut ispell up."
  (let ((ispell-check-only t)
        (beep-def (symbol-function 'beep))
        (message-def (symbol-function 'message))
        (found t)
       )
    (defun beep () (setq found nil))
    (defun message (&rest garbage) t)
    (ispell-word nil t)
    (fset 'beep beep-def)
    (fset 'message message-def)
    found
  )
)

(defun fix-transposed-characters ()
    "Fix any transposed characters in the input."
    (catch 'done
        (if (and (memq major-mode correct-words-applicable-modes)
                 (not (auto-correct-check-word)))
            (let ((end (point)))
                (backward-word 1)
                (if (not (looking-at "[a-zA-Z]+\\([ \t]\\|$\\)"))
                    (prong
                        (goto-char end)
                        (throw 'done t)
                    )
                )
                (if (and
                        (equal major-mode 'plain-tex-mode)
                        (if (not (bobp))
                            (save-excursion
                                (backward-char 1)
                                (looking-at "\\\\")
                            )
                            nil
                        )
                    )
                    (prong
                        (goto-char end)
                        (throw 'done t)
                    )
                )
                (let ((case-fold-search nil))
                    (if (looking-at "[A-Z]+\\([ \t]\\|$\\)")
                        (prong
                            (goto-char end)
                            (throw 'done t)
                        )
                    )
                )
                (forward-char 1)
                (while (< (point) end)
                    (transpose-chars nil)
                    (if (auto-correct-check-word)
                        (progn
                            (goto-char end)
                            (throw 'done t)
                        )
                        (forward-char -1)
                        (transpose-chars nil)
                    )
                )
            )
        )
    )
)

(advice-add abbrev-expand-function 
            :before (lambda () (fix-transposed-characters)))

%%%---------------------------------------------------

(2) In the same directory as this auto-correct.el file, start up emacs 28.2:
       emacs -Q

(3) Load and execute the auto-correction code:
        ESC : (load-file "auto-correct.el") RTE

(4) Visit a file "a.txt"
        C-x C-f a.txt RTE

(5) Turn on abbrev mode and flyspell mode:
        ESC : (abbrev-mode t) RET
        ESC : (flyspell-mode) RTE

(4) Enter the 3 chars "abc" on a single line.
        a b c

(5) At the end of the single line, type Ctrl-T:
        C-t

(6) Note that you now have "acb", not "cab".

Following that, if I now enter a space, "acb" is automagically changed to
"cab", as expected.

But (and this is the salient point) "acb" *is not* changed to "cab"
immediately upon typing Ctrl-T, it is only done when the abbrev
functionality is exercised (I believe this is the correct thing to say).

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.


Does that fully explain the issue, as well as what I would like to achieve?
If not, let me know and I'll add whatever detail is needed.

Cheers.
                                Jim




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#76884; Package emacs. Full text available.

Message received at 76884 <at> debbugs.gnu.org:


Received: (at 76884) by debbugs.gnu.org; 9 Mar 2025 19:08:36 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sun Mar 09 15:08:36 2025
Received: from localhost ([127.0.0.1]:34336 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1trM0p-0005lw-Vc
	for submit <at> debbugs.gnu.org; Sun, 09 Mar 2025 15:08:36 -0400
Received: from eggs.gnu.org ([2001:470:142:3::10]:41346)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <eliz@HIDDEN>) id 1trM0n-0005li-3p
 for 76884 <at> debbugs.gnu.org; Sun, 09 Mar 2025 15:08:34 -0400
Received: from fencepost.gnu.org ([2001:470:142:3::e])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <eliz@HIDDEN>)
 id 1trM0h-00077M-07; Sun, 09 Mar 2025 15:08:27 -0400
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org;
 s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date:
 mime-version; bh=VXiP0TSC5s89zeDA4zBf0n/tRIbRiSFP1AhoY1FEFao=; b=igHdJkfJIvvK
 2dKOzmEdlziqlVJQRDomDzrfHBzXARq1rXLLG+pshdsZfM5wCCW/AZpp2h08tVUUunUC8gmiIyLLv
 Ss4fc4WvCMO6Scz0gxoGfUKlGQWBU0kCFflEXZKEJvIBB39cPAqJYLeILqeosFCY5gUeXAf6Njy74
 R5UkjVIit0Tbjas62f1YGrJZNKBgM6uW7kB4cIXgPOu7UAuTVu/ytyCXXhrSuxAZPC8qG0bs9T5t3
 hjyMNb0K7Y+eZ2xFuTKksf3Zanz4ycoYIiPDWc9g8Hwxs/DFNriVIqMEMmvVR7O/gFZyGzYLu1Z2z
 Uc3uKGhWA5rmPNLIr2fmeQ==;
Date: Sun, 09 Mar 2025 21:08:25 +0200
Message-Id: <8634fmf2dy.fsf@HIDDEN>
From: Eli Zaretskii <eliz@HIDDEN>
To: Jim Diamond <jim@HIDDEN>
In-Reply-To: <Z83F34NPmdgviJXF@HIDDEN> (message from Jim Diamond on
 Sun, 9 Mar 2025 13:46:23 -0300)
Subject: Re: bug#76884: 30.1 problem with flyspell-maybe-correct-transposition
References: <Z8zl0rLCkKr1EoCN@HIDDEN>
 <86h642foz4.fsf@HIDDEN> <Z83F34NPmdgviJXF@HIDDEN>
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: 76884
Cc: 76884 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -3.3 (---)

> Date: Sun, 9 Mar 2025 13:46:23 -0300
> From: Jim Diamond <jim@HIDDEN>
> Cc: 76884 <at> debbugs.gnu.org
> 
> >> 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.




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#76884; Package emacs. Full text available.

Message received at 76884 <at> debbugs.gnu.org:


Received: (at 76884) by debbugs.gnu.org; 9 Mar 2025 11:01:00 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sun Mar 09 07:00:59 2025
Received: from localhost ([127.0.0.1]:58577 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1trEOx-0003V8-FE
	for submit <at> debbugs.gnu.org; Sun, 09 Mar 2025 07:00:59 -0400
Received: from eggs.gnu.org ([2001:470:142:3::10]:37330)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <eliz@HIDDEN>) id 1trEOv-0003Ug-Is
 for 76884 <at> debbugs.gnu.org; Sun, 09 Mar 2025 07:00:58 -0400
Received: from fencepost.gnu.org ([2001:470:142:3::e])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <eliz@HIDDEN>)
 id 1trEOn-000329-SO; Sun, 09 Mar 2025 07:00:51 -0400
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org;
 s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date:
 mime-version; bh=wzkQzoCooaK4VkI8OwY6TbnqMupU3pqecH2VzYjXuYc=; b=rXAnGiVWbra3
 exkVCaeTlTDJMVy+HMM8eZItn0XEXS7Po7GCgjP3Nu9dR3vJ1MiRM2QmV8OM4ichrpVulLv5m6Oxd
 usMB5b550UrkHwqQxTqJiAJjImZquBUDWdZiJVVIieOC3ab0lTqdbOMlG6bTmyFBGBSOeWFtsFtUh
 3khpa9/jDYRzIZJPKnRg1lz13gKqWBBXeJFEFvjjp1qrC+kf87FIafc7O6efWBTvaptWD/hJJcqDh
 O5LUTlCmj7/eNWcE0pHClDlDzXMewR3GNXF4iUwzwSdzwV1RNIs0wmFqTFTDYsu80eyW7M4Up2smH
 4I+sYhAwmjDp9I8mW/inPQ==;
Date: Sun, 09 Mar 2025 13:00:31 +0200
Message-Id: <86h642foz4.fsf@HIDDEN>
From: Eli Zaretskii <eliz@HIDDEN>
To: Jim Diamond <jim@HIDDEN>
In-Reply-To: <Z8zl0rLCkKr1EoCN@HIDDEN> (message from Jim Diamond on
 Sat, 8 Mar 2025 20:50:26 -0400)
Subject: Re: bug#76884: 30.1 problem with flyspell-maybe-correct-transposition
References: <Z8zl0rLCkKr1EoCN@HIDDEN>
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: 76884
Cc: 76884 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -3.3 (---)

> Date: Sat, 8 Mar 2025 20:50:26 -0400
> From: Jim Diamond <jim@HIDDEN>
> 
> I recently upgraded to emacs 30.1.  For many years I had been using a
> function which automatically corrected transposition errors, but it no
> longer works in 30.1.  The author of that function kindly pointed me to the
> fact that such functionality has been part of flyspell for a long time, and
> that I should add
>     (add-hook 'flyspell-incorrect-hook 'flyspell-maybe-correct-transposition)
> to my init.el.
> 
> So I put that line in my init.el and started editing away, only to discover
> that it doesn't do exactly what I want.  To reproduce the problem,
> 
> 
> (1) Create a file ABC like this
> ----------------- cut here --------------------
> 
> ABC
> 
> ----------------- cut here --------------------
> 
> (2) Replace your entire init.el with this one line:
> (add-hook 'flyspell-incorrect-hook 'flyspell-maybe-correct-transposition)
> (Or start with "emacs -Q" and make the "obvious" changes to the procedure
> below.)
> 
> (3) Fire up a fresh emacs as follows:
> emacs ABC
> 
> (4) Turn on flyspell
> M-x flyspell-mode
> 
> (5) Navigate to the end of the 'abc' line
> 
> (6) Type Ctrl-T
> 
> 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?

IOW, I don't understand what scenario worked for you in older versions
of Emacs and no longer works in Emacs 30.1.  Could you please show a
recipe, starting from "emacs -Q", which did NOT convert ABC into CAB
in Emacs 29 or earlier, but does with Emacs 30.1?  Because if I try
using that add-hook in Emacs 28.2, I get the same result: ABC => CAB,
if I type C-t at the end of the ABC line.  So I'm confused regarding
the problem which you found in Emacs 30 that didn't exist before.

> With my old setup in emacs 28 and before, the transposition correction
> function was triggered when emacs was about to see if there was an
> abbreviation to expand, so if I was anticipating a problem I could
> transpose two letters and then move away from the "word" using something
> other than a space (e.g., arrow keys), and the text would stay how I wanted
> it.

Sorry, I don't understand this description.  Could you please show a
recipe with all the commands and key sequences explicit?




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#76884; Package emacs. Full text available.

Message received at submit <at> debbugs.gnu.org:


Received: (at submit) by debbugs.gnu.org; 9 Mar 2025 10:20:42 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sun Mar 09 06:20:42 2025
Received: from localhost ([127.0.0.1]:58498 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1trDlx-0001ey-6O
	for submit <at> debbugs.gnu.org; Sun, 09 Mar 2025 06:20:42 -0400
Received: from lists.gnu.org ([2001:470:142::17]:49766)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <jim@HIDDEN>) id 1tr4sO-00081S-V0
 for submit <at> debbugs.gnu.org; Sat, 08 Mar 2025 19:50:46 -0500
Received: from eggs.gnu.org ([2001:470:142:3::10])
 by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <jim@HIDDEN>) id 1tr4sJ-0001Iw-45
 for bug-gnu-emacs@HIDDEN; Sat, 08 Mar 2025 19:50:39 -0500
Received: from seout2.web-dns1.com ([68.168.119.163])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <jim@HIDDEN>) id 1tr4sH-00076B-39
 for bug-gnu-emacs@HIDDEN; Sat, 08 Mar 2025 19:50:38 -0500
Received: from mailpro1.whc.ca ([51.79.16.13])
 by se1.web-dns1.com with esmtps (TLSv1.3:TLS_AES_256_GCM_SHA384:256)
 (Exim 4.92) (envelope-from <jim@HIDDEN>) id 1tr4sD-00BEBr-8K
 for bug-gnu-emacs@HIDDEN; Sat, 08 Mar 2025 19:50:35 -0500
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=jdvb.ca;
 s=default; h=Content-Type:MIME-Version:Message-ID:Subject:To:From:Date:Sender
 :Reply-To:Cc:Content-Transfer-Encoding:Content-ID:Content-Description:
 Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:
 In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:List-Subscribe:
 List-Post:List-Owner:List-Archive;
 bh=V3Z+3TP1W5wWLfUp1l37QLX4DOPScA4sHvJWbm2OBT8=; b=KTcH7wcaEBhgiQE5d5qdFud5/R
 Fd557QzAaAOKT24bj72NzRxGqna0qgdDb1wRUtcj6z3VrZIvUlsXOQgmWTljpCZtCHlu37dgCwaT9
 qv8BGVm2CN7uR8NN7GuiS53pMnn2GClMO52GVtO4W4URSy82YUMEiz8cclo1LY3RKhWJv+sh/TFgt
 DoUihvanaI3Y+hOh7gyQU/UEAaJwv12zCT6w4wZw0BoXm5a1itJcrtSnQjFSx1x2RefE80guQvjxf
 yNA//wINvYz37Ew2L6g/21LkbjbLASyK1Eq4DPpSeSaQcdik9Fs3KRJGhObwNH2vv0QCWE7q7gOJ1
 LNAeXvBg==;
Received: from [47.55.144.2] (port=38152 helo=x360)
 by mailpro1.whc.ca with esmtpsa  (TLS1.3) tls TLS_AES_256_GCM_SHA384
 (Exim 4.98.1) (envelope-from <jim@HIDDEN>)
 id 1tr4s7-000000089qg-03XK for bug-gnu-emacs@HIDDEN;
 Sat, 08 Mar 2025 19:50:33 -0500
Received: by x360 (Postfix, from userid 1000)
 id 9534C1E0DEC; Sat,  8 Mar 2025 20:50:26 -0400 (AST)
Date: Sat, 8 Mar 2025 20:50:26 -0400
From: Jim Diamond <jim@HIDDEN>
To: bug-gnu-emacs@HIDDEN
Subject: 30.1 problem with flyspell-maybe-correct-transposition
Message-ID: <Z8zl0rLCkKr1EoCN@HIDDEN>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
X-Originating-IP: 51.79.16.13
X-SpamExperts-Domain: out.mailpro1.whc.ca
X-SpamExperts-Username: 51.79.16.13
Authentication-Results: web-dns1.com;
 auth=pass smtp.auth=51.79.16.13@HIDDEN
X-SpamExperts-Outgoing-Class: ham
X-SpamExperts-Outgoing-Evidence: Combined (0.17)
X-Recommended-Action: accept
X-Filter-ID: Pt3MvcO5N4iKaDQ5O6lkdGlMVN6RH8bjRMzItlySaT+Kx+RJzcrvEper6aWUbT2ePUtbdvnXkggZ
 3YnVId/Y5jcf0yeVQAvfjHznO7+bT5wlAxozo778b01LESzM9ruWD181ZRkJ75zosNBWoY/fPNcV
 PSoHm0W/3adFfiYl2nsGGbqDMqP9i+8k+Eh/w0r8/T4GcPvCLvSpAEEGy7kYxtLSm6ZPIIlKlwTC
 gIG9JyxQrxJhchCunvHNGKnzhTg7BGjzuh4BML6Ea1s3IuoPv0ceC5CQEPeJemrFIiSNMvThFICu
 rO5GrHxvhcBIPS3XvRkWzsAgaWolxIxCj2GHto6atsxaFkWS/KO9ggVt7y11v0HCq9Ij3WgoQoez
 M+scYG4yYBh/iFtUTfPc63fdkHYWpV+R5wxBKtDjzXK7v691pXzGdN11xofvbT+C+nOmFR0WqQUD
 5gqRSXJ0uHlxJoe3veMkpTjjM+L4/Olz0bnNTOt1lTs6HBd4ftgtnEKNHo+FpNHjfNrHwQt6r1Om
 pMuAp99MiCXue4Y78glTXfjY5Qx4fJOk03R5fJtf/Dv/hr5nJzWxRiVyQwNuu4CHF9M9yLyVkzmX
 px11wuj3nJFuDwaV9BmtfzJ2TVypcoeRZovWtD8Ww+AEobgMkYCaogw4CrVrTQSil/GdOXpZk5aI
 S9EkKnzUOzpOM+eXtmtKmLtOS0bSiFJAxNLRuUjIwKaVFwmXRHhNPcmHxuFnEKeyAP4WehsiuTRA
 qNI7in/36E/LbAGsUfBhNJ9K4nqf4gxxEf7vABXSr7wnI1Am2EkVoaw9T9SnWbGDriVpmijTUV8S
 hebT8U8Xw9HTDfreWXiuDO4GaKRWOqtFc/DmZ37DqcigOvSxdRnthmhn8Zn64eLa0FuVVtzzdTZ5
 G9+TwPe9xdwoBXon8/ivvM3S/JrE+P2DA1UQf7wqaJgGjfHg3DtzWxemfWoLUeLspqcdEr9hxTZh
 lYzghM0Y5fogrpVV/bRBXh9n4rW7DM09FBXnxypUhWZ7DV/QthUn4wTjFg==
X-Report-Abuse-To: spam@HIDDEN
X-Complaints-To: abuse@HIDDEN
Received-SPF: pass client-ip=68.168.119.163; envelope-from=jim@HIDDEN;
 helo=seout2.web-dns1.com
X-Spam_score_int: -27
X-Spam_score: -2.8
X-Spam_bar: --
X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1,
 DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,
 RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001,
 RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001,
 SPF_PASS=-0.001 autolearn=ham autolearn_force=no
X-Spam_action: no action
X-Spam-Score: 1.0 (+)
X-Debbugs-Envelope-To: submit
X-Mailman-Approved-At: Sun, 09 Mar 2025 06:20:39 -0400
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -0.0 (/)

I recently upgraded to emacs 30.1.  For many years I had been using a
function which automatically corrected transposition errors, but it no
longer works in 30.1.  The author of that function kindly pointed me to the
fact that such functionality has been part of flyspell for a long time, and
that I should add
    (add-hook 'flyspell-incorrect-hook 'flyspell-maybe-correct-transposition)
to my init.el.

So I put that line in my init.el and started editing away, only to discover
that it doesn't do exactly what I want.  To reproduce the problem,


(1) Create a file ABC like this
----------------- cut here --------------------

ABC

----------------- cut here --------------------

(2) Replace your entire init.el with this one line:
(add-hook 'flyspell-incorrect-hook 'flyspell-maybe-correct-transposition)
(Or start with "emacs -Q" and make the "obvious" changes to the procedure
below.)

(3) Fire up a fresh emacs as follows:
emacs ABC

(4) Turn on flyspell
M-x flyspell-mode

(5) Navigate to the end of the 'abc' line

(6) Type Ctrl-T

Result: I get "CAB", whereas I expect "ACB".  This is not merely
unexpected, but an actual problem.

Now, I know that "cab" is an English word, and that "acb" is not, and
I presume flyspell is looking at "ACB" immediately after I do the Ctrl-T
and "fixes" the resulting spelling error.

(Finance wonks may recognize ACB as the abbreviation for "adjusted cost
base", so it is something I might actually want to type.  Yes, I could add
ACB to my dictionary, but that doesn't solve the problem in general,
because there are lots of acronyms which are just one transposition away
from a "normal" word.)

With my old setup in emacs 28 and before, the transposition correction
function was triggered when emacs was about to see if there was an
abbreviation to expand, so if I was anticipating a problem I could
transpose two letters and then move away from the "word" using something
other than a space (e.g., arrow keys), and the text would stay how I wanted
it.

I posted this on gnu.emacs.help looking for a work-around, but a person
with far more emacs expertise than me said it was a bug and I should submit
a bug report.  Here it is.

Thanks.
                                Jim




Acknowledgement sent to Jim Diamond <jim@HIDDEN>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs@HIDDEN. Full text available.
Report forwarded to bug-gnu-emacs@HIDDEN:
bug#76884; Package emacs. Full text available.
Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.
Last modified: Mon, 10 Mar 2025 00:45:02 UTC

GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997 nCipher Corporation Ltd, 1994-97 Ian Jackson.