reddit / emacs

Auto-correct the "*ign" -> "*ing" typo

HM0880 · 2022-11-19 16:56
I use `global-abbrev-table` to auto-correct my common typos; a short example is below. (define-abbrev-table 'global-abbrev-table '(("adn" "and" nil 0) ("nad" "and" nil 0))) I would like to auto-correct the `*ign` -> `*ing` typo. Using the generic regex `("*ign" "*ing" nil 0)` works *except* that "sign" becomes "sing". Is there a way to use the `("*ign" "*ing" nil 0)` regex and only ignore the word "sign"? Or do I need to define each "ign" typo manually? Or is there a better option? edit: remove `*` so that the text is not italicized.
joranvar · 2022-11-19 18:00
And by design, malign the reign of a foreign sovereign? Of feign to resign from a campaign for benign champaign? (Sorry, I don't know if it's possible to exclude a word (or better yet, several words) from abbrev, but I could not refrain from pointing out other words that correctly end in -ign (https://www.thefreedictionary.com/words-that-end-in-ign). Hope someone else knows a solution.)
HM0880 · 2022-11-19 18:29
Ha! In my day job, "sign" occurs more frequently than "feign" and friends. :) Hopefully there's a solution shorter than "write all -ing words in a lookup table."
mickeyp · 2022-11-19 19:51
I wrote about this a little while ago. But I instead prefer sourcing a common list of typos -- wikipedia has an extensive one I've used for many, many years -- and feeding it to Emacs: https://www.masteringemacs.org/article/correcting-typos-misspellings-abbrev It's a better approach in the long run, I think, to explicitly list them instead -- if you would deign to do so :-)
HM0880 · 2022-11-19 20:55
Thanks for the suggestion! It's a good sign to get a response from the Mastering Emacs author, so I will realign my design choices and use a separate file.
mickeyp · 2022-11-19 21:54
I mean it's all up to you, of course, but I just foresee it generating a lot more typos in the long run.
_viz_ · 2022-11-20 07:24
Use the :expand-function abbrev-table property to check if the previous word at point is sign and return nil if so?
HM0880 · 2022-11-22 00:13
This sounds like what I want. Can you point me to where I can find the `:expand-function` documentation for `abbrev-table`? (I looked in Help without success.)
_viz_ · 2022-11-22 02:34
Check the docstring of define-abbrev-table and its info entry.