]> git.bundesbrandschatzamt.de Git - emacsconfig.git/commitdiff
- combine abbrev with ispell
authorAndreas Gerler <baronNOSPAMbundesbrandschatzamt.de>
Fri, 11 Mar 2016 12:31:02 +0000 (13:31 +0100)
committerAndreas Gerler <baronNOSPAMbundesbrandschatzamt.de>
Fri, 11 Mar 2016 12:31:02 +0000 (13:31 +0100)
borrowed from http://endlessparentheses.com/ispell-and-abbrev-the-perfect-auto-correct.html

bba.org

diff --git a/bba.org b/bba.org
index cfac8aca5a7e57f4e0649d4ee0993158ae054d87..f33971a8a312c4cfe661ab6131bda32a66ca0a12 100644 (file)
--- 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)