From: Andreas Gerler Date: Fri, 11 Mar 2016 12:31:02 +0000 (+0100) Subject: - combine abbrev with ispell X-Git-Url: http://git.bundesbrandschatzamt.de/?a=commitdiff_plain;h=974d7818a73f2f754b5213026abd65d6164aa144;p=emacsconfig.git - combine abbrev with ispell borrowed from http://endlessparentheses.com/ispell-and-abbrev-the-perfect-auto-correct.html --- diff --git a/bba.org b/bba.org index cfac8aca..f33971a8 100644 --- a/bba.org +++ b/bba.org @@ -1581,6 +1581,52 @@ Watching [[https://www.youtube.com/watch?v%3DFtieBc3KptU][Emacs For Writers]] by (setq save-abbrevs 'silently) #+END_SRC + +Combine abbrev with Ispell: + +[[http://endlessparentheses.com/ispell-and-abbrev-the-perfect-auto-correct.html][Ispell and Abbrev, the Perfect Auto-Correct]] + +#+BEGIN_SRC emacs-lisp + (global-set-key (kbd "M-$") #'endless/ispell-word-then-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")))) + +#+END_SRC + * syntax-highlighting #+BEGIN_SRC emacs-lisp (font-lock-mode)