I am not a fantastic typist. My speed is acceptable, but I make a great
deal of mistakes. The following snippet has turned me into the Messi
of keyboards.
Whenever I make a typo:
Hit C-x C-i, instead of erasing the mistake;
Select the appropriate correction (thanks to Ispell);
Sleep easier at night knowing I'll never see that mistake again (thanks to abbrev).
(define-keyctl-x-map"\C-i"#'endless/ispell-word-then-abbrev)(defunendless/simple-get-word()(car-safe(save-excursion(ispell-get-wordnil))))(defunendless/ispell-word-then-abbrev(p)"Call `ispell-word', then create an abbrev for it.
With prefix P, create local abbrev. Otherwise it will
be global.
If there's nothing wrong with the word at point, keep
looking for a typo until the beginning of buffer. You can
skip typos you don't want to fix with `SPC', and you can
abort completely with `C-g'."(interactive"P")(let(befaft)(save-excursion(while(if(setqbef(endless/simple-get-word));; Word was corrected or used quit.(if(ispell-wordnil'quiet)nil; End the loop.;; Also end if we reach `bob'.(not(bobp)));; If there's no word at point, keep looking;; until `bob'.(not(bobp)))(backward-word)(backward-char))(setqaft(endless/simple-get-word)))(if(andaftbef(not(equalaftbef)))(let((aft(downcaseaft))(bef(downcasebef)))(define-abbrev(ifplocal-abbrev-tableglobal-abbrev-table)befaft)(message"\"%s\" now expands to \"%s\" %sally"befaft(ifp"loc""glob")))(user-error"No typo at or before point"))))(setqsave-abbrevs'silently)(setq-defaultabbrev-modet)
In my innocence, I had initially assigned this command to a
3-key sequence. It took me less then a month to realise it needed a
shorter bind, I'd been using it 30 times a day.
Ispell and Abbrev, the Perfect Auto-Correct
05 Jul 2014, by Artur Malabarba.I am not a fantastic typist. My speed is acceptable, but I make a great deal of mistakes. The following snippet has turned me into the Messi of keyboards.
Whenever I make a typo:
In my innocence, I had initially assigned this command to a 3-key sequence. It took me less then a month to realise it needed a shorter bind, I'd been using it 30 times a day.
Auto correction with abbrev is far from a new concept. Do you use anything similar?
Update 11 Jan 2016
The command now searches backward for the closest wrong word. So you can just hit C-x C-i even if the mistake happened several words ago.
Update 20 Jan 2016
Fixed some corner-case issues with the previous update.
Tags: ispell, abbrev, writing, keybind, init.el, emacs,
Emacs Documentation v1.3 Android App: Built-in Viewer and Theme Choice »
« Require Feature or Install Package
Related Posts
A few paredit keys that take over the world in writing
Fill and unfill paragraphs with a single key in keybind
Disable Mouse only inside Emacs in keybind
Content © 2019, All rights reserved. Icons under CC3.0.