[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/crux d2643ae 019/112: Add crux-ispell-word-then-abbrev
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/crux d2643ae 019/112: Add crux-ispell-word-then-abbrev |
Date: |
Wed, 11 Aug 2021 09:57:45 -0400 (EDT) |
branch: elpa/crux
commit d2643ae98098fab91dec989057e2cf5a5dd27619
Author: Bozhidar Batsov <bozhidar@batsov.com>
Commit: Bozhidar Batsov <bozhidar@batsov.com>
Add crux-ispell-word-then-abbrev
Borrowed from @Malabarba. More info -
http://endlessparentheses.com/ispell-and-abbrev-the-perfect-auto-correct.html.
---
README.md | 8 ++++++++
crux.el | 33 +++++++++++++++++++++++++++++++++
2 files changed, 41 insertions(+)
diff --git a/README.md b/README.md
index e1274c7..a13b6b5 100644
--- a/README.md
+++ b/README.md
@@ -60,6 +60,7 @@ Command | Suggested
Keybinding(s) |
`crux-top-join-lines` | <kbd>Super-j</kbd> or
<kbd>C-^</kbd> | Join lines
`crux-kill-whole-line` | <kbd>Super-k</kbd> | Kill whole
line
`crux-kill-line-backwards` | <kbd>C-Backspace</kbd> | Kill
line backwards
+`crux-ispell-word-then-abbrev` | <kbd>C-c i</kbd> | Fix word
using `ispell` and then save to `abbrev`.
Here's how you'd bind some of the commands to keycombos:
@@ -72,6 +73,13 @@ Here's how you'd bind some of the commands to keycombos:
(global-set-key [remap kill-whole-line] #'crux-kill-whole-line)
```
+For `crux-ispell-word-then-abbrev` to be most effective you'll also need to
add this to your config:
+
+```el
+(setq save-abbrevs 'silently)
+(setq-default abbrev-mode t)
+```
+
## Using the bundled advices
crux ships with some handy advises that can enhance the operation of existing
commands.
diff --git a/crux.el b/crux.el
index 3de5450..08027f5 100644
--- a/crux.el
+++ b/crux.el
@@ -353,6 +353,39 @@ Doesn't mess with special buffers."
(t (error "Unknown shell")))))
(find-file-other-window (expand-file-name shell-init-file (getenv
"HOME")))))
+;;
http://endlessparentheses.com/ispell-and-abbrev-the-perfect-auto-correct.html
+(defun crux-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 (thing-at-point '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))
+ (setq aft (thing-at-point '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"))))
+
(defmacro crux-with-region-or-buffer (func)
"When called with no active region, call FUNC on current buffer.
- [nongnu] elpa/crux aafcf48 009/112: Introduce some customization options, (continued)
- [nongnu] elpa/crux aafcf48 009/112: Introduce some customization options, ELPA Syncer, 2021/08/11
- [nongnu] elpa/crux c174247 014/112: Change crux-kill-like-backward to crux-kill-line-backward, ELPA Syncer, 2021/08/11
- [nongnu] elpa/crux 0f04d98 015/112: Fix unbound var reference, ELPA Syncer, 2021/08/11
- [nongnu] elpa/crux 3009713 018/112: Update the copyright, ELPA Syncer, 2021/08/11
- [nongnu] elpa/crux 86cabce 027/112: Merge pull request #10 from waymondo/file-and-buffer-naming-conventions, ELPA Syncer, 2021/08/11
- [nongnu] elpa/crux 5ee7dc9 032/112: Require tramp for `tramp-tramp-file-p`, ELPA Syncer, 2021/08/11
- [nongnu] elpa/crux b07b31a 005/112: Move a function around, ELPA Syncer, 2021/08/11
- [nongnu] elpa/crux b5eac2a 008/112: Code style, ELPA Syncer, 2021/08/11
- [nongnu] elpa/crux 3088be2 012/112: Add a way to make commands operate on either a region or a buffer, ELPA Syncer, 2021/08/11
- [nongnu] elpa/crux 16eb56d 011/112: Kill crux-setup-default-keybindings, ELPA Syncer, 2021/08/11
- [nongnu] elpa/crux d2643ae 019/112: Add crux-ispell-word-then-abbrev,
ELPA Syncer <=
- [nongnu] elpa/crux 382834e 020/112: Fix contributors link, ELPA Syncer, 2021/08/11
- [nongnu] elpa/crux e6e3221 025/112: Fix crux-*-file-and-buffer commands inconsistencies and alias the inverse, ELPA Syncer, 2021/08/11
- [nongnu] elpa/crux 4c90762 026/112: Add complementary `with-region-or-line` & `with-region-or-point-to-eol`, ELPA Syncer, 2021/08/11
- [nongnu] elpa/crux e4c539b 028/112: Merge pull request #9 from waymondo/with-region-or-line, ELPA Syncer, 2021/08/11
- [nongnu] elpa/crux dc1606b 034/112: Add crux-transpose-windows for swapping the buffers between two windows, ELPA Syncer, 2021/08/11
- [nongnu] elpa/crux 2be95ea 040/112: Use read-from-minibuffer for the new file name, ELPA Syncer, 2021/08/11
- [nongnu] elpa/crux e2124c8 023/112: Merge pull request #6 from verdammelt/patch-1, ELPA Syncer, 2021/08/11
- [nongnu] elpa/crux 3c14b4a 024/112: Merge pull request #13 from jiegec/master, ELPA Syncer, 2021/08/11
- [nongnu] elpa/crux 79e500e 030/112: Add multiple choice with completion for shell init files., ELPA Syncer, 2021/08/11
- [nongnu] elpa/crux e6c7421 035/112: Remove crux-swap-windows and alias it to crux-transpose-windows, ELPA Syncer, 2021/08/11