Skip to content

Instantly share code, notes, and snippets.

@alienbogart
Created July 3, 2020 15:01
Show Gist options
  • Save alienbogart/3f7a0d210b4bba57df754f8e082b4db0 to your computer and use it in GitHub Desktop.
Save alienbogart/3f7a0d210b4bba57df754f8e082b4db0 to your computer and use it in GitHub Desktop.
;; SAVE CORRECTIONS TO ABBREV
(defun endless/simple-get-word ()
(car-safe (save-excursion (ispell-get-word nil))))
(defun endless/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 (bef aft)
(save-excursion
(while (if (setq bef (endless/simple-get-word))
;; word was corrected or used quit.
(if (ispell-word nil '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))
(setq aft (endless/simple-get-word)))
(if (and aft bef (not (equal aft bef)))
(let ((aft (downcase aft))
(bef (downcase bef)))
(define-abbrev
(if p local-abbrev-table global-abbrev-table)
bef aft)
(message "\"%s\" now expands to \"%s\" %sally"
bef aft (if p "loc" "glob")))
(user-error "no typo at or before point"))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment