reddit / emacs

Correcting Typos and Misspellings with Abbrev

mickeyp · 2022-05-21 15:00
mickeyp · 2022-05-21 15:03
Abbrev's great for automatic text replacement. I've had the wikipedia list for so long I often forget it's even there. Any other clever abbrev hacks out there?
karthink · 2022-05-21 16:20
In general I try to avoid magic auto-corrections when I type, preferring to call `flyspell-auto-correct-previous-word` instead. However, I use abbrev to define (auto-expanding) shell aliases in `eshell` and `M-x shell`. For example, * `scu` expands to `systemctl --user `, * `pac` expands to `sudo pacman -`, * `xo` expands to `xdg-open `, * `dow` expands to `dired-other-window `, * `ffof` expandss to `find-file-other-frame `, and so on. I've got a fair few of these. The advantages of this approach over defining conventional eshell or shell aliases are that: - Command argument completion (with pcomplete + [pcmpl-args](https://github.com/JonWaltman/pcmpl-args.el)) works as expected, I get [full support](https://abode.karthinks.com/share/pcmpl-args-1.png). - The expanded command is committed to history instead of the alias, which makes incremental reverse search much more useful.
thetemp_ · 2022-05-21 16:28
> In order to add abbrev entries you need to decide if you want to do it the inverted way – where you place point at the end of the word you want to replace – or the other way around. Thank you for this! I found the combination of the regular and "inverted" commands confusing until reading this explanation. Now it makes sense. > you can import Wikipedia’s word list You can also get the autocorrect word list that LibreOffice uses. Since it's open source, just go to the source! :-D If you have MS Word, you can extract its word list using a VBA script. But then you'd have to carry that secret (of unlicensed usage) with you to the grave, and it probably isn't any better than LibreOffice's list.
_viz_ · 2022-05-21 16:42
I don't have any "hacks" per-se but I would like to bring attention to two abbrev properties that proved useful to me: 1. :enable-function 2. :regexp I use (1) to expand abbrev in org-mode only in "text areas" i.e., (not (texmathp)). (2) is quite powerful but it has a caveat though since self-insert-command simply does not check the abbrev table if the last character of the word is not part of the word syntax. If you wrote a :regexp that made "/" a valid part of an abbrev, "abc/" is still not a valid abbrev. For an example, see (find-library "python"). BTW :regexp is not greedy (see abbrev--before-point).
_viz_ · 2022-05-21 16:44
> preferring to call flyspell-auto-correct-previous-word instead. Sorry for derailing this thread but I have to ask: for those who also use ispell, do you find the flyspell interface annoying? I feel like I spam C-; every time I need to correct my misspelling.
_viz_ · 2022-05-21 16:45
FWIW, the docstrings for abbrev functions was improved yesterday (maybe it was today?).
mickeyp · 2022-05-21 18:10
I tend to use `M-$` for (suspected) misspellings when I only want to check a single word. I do use `flyspell-[prog]-mode` to go with that for the highlighting.
mickeyp · 2022-05-21 18:11
> You can also get the autocorrect word list that LibreOffice uses. Since it's open source, just go to the source! :-D > > Good idea!
paretoOptimalDev · 2022-05-21 19:52
I've held that opinion before, but I'll argue that if your list is specific enough there's nothing magical about the corrections. If flycheck told you your most corrected word and you turned it into an abbrev, do you think you'd feel discomfort? This is all subjective to the habitability of our personal highly customized environments so any answer is fine. I've allowed too much magic recently and have reconsidered my current positions, so not sure if I agree with the characterization of these replacements as magic or not.
oantolin · 2022-05-21 20:44
In the keyboard macro described at the end, instead of finishing with `<f4> C-0 C-x e`, I'd just use `C-0 <f4>`. Who has time to actually finish recording before you start running the macro?! :P More generally, I consider `C-x e` completely superseded by `<f4>`.
chieftwit · 2022-05-22 00:17
Love this. Implemented it immediately. Thanks, Mickey!
Phil-Hudson · 2022-05-22 11:29
The keyboard macro will abort whenever your existing abbrev table contains an existing expansion, even if it's identical to the one you're importing. This fixes the underlying abbrev code by making it silently skip these identical instances: ;; Redefine to be smarter about exact duplicates (defun inverse-add-abbrev (table type arg) (let (name exp start end) (save-excursion (forward-word (1+ (- arg))) (skip-syntax-backward "^w") (setq end (point)) (backward-word 1) (setq start (point) name (buffer-substring-no-properties start end))) (setq exp (read-string (format "%s expansion for \"%s\": " type name) nil nil nil t)) (let ((current-expansion (abbrev-expansion name table))) (when (and (not (string= current-expansion exp)) (or (not current-expansion) (y-or-n-p (format "%s expands to \"%s\"; redefine? " name current-expansion)))) (define-abbrev table (downcase name) exp) (save-excursion (goto-char end) (expand-abbrev))) ) ;; (when (or (not (abbrev-expansion name table)) ;; (y-or-n-p (format "%s expands to \"%s\"; redefine? " ;; name (abbrev-expansion name table)))) ;; (define-abbrev table (downcase name) exp) ;; (save-excursion ;; (goto-char end) ;; (expand-abbrev))) ))
HM0880 · 2022-05-25 00:07
Is there a way to correct the ending typo "*ign" -> "*ing"? I used to have an AutoHotKey replacement for the typo, but an important issue was that the word "sign" gets converted to "sing."
ypote · 2022-05-27 19:03
Hi I've tried [Spanish word list](https://es.wikipedia.org/wiki/Wikipedia:Lista_de_errores_ortogr%C3%A1ficos_comunes/M%C3%A1quinas), and it has words like: `a basto->abasto` `ONG's->ONG` &#x200B; Is it possible to expand those words? or something like : `.->.` (SPC.->.)