[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 00cdd17: auto-correct: Add support for flyspell-correct-wo
From: |
Ian Dunn |
Subject: |
[elpa] master 00cdd17: auto-correct: Add support for flyspell-correct-word-* |
Date: |
Sat, 23 Jun 2018 15:05:24 -0400 (EDT) |
branch: master
commit 00cdd170a15c537bb37baecefa19c6998727d950
Author: Ian Dunn <address@hidden>
Commit: Ian Dunn <address@hidden>
auto-correct: Add support for flyspell-correct-word-*
* auto-correct.el (auto-correct--flyspell-old-word): New variable.
(auto-correct--flyspell-do-correct-wrapper): Wrapper for
flyspell-do-correct.
(auto-correct-flyspell-insert): Use the new variable.
(auto-correct--activate-flyspell-support): Advise flyspell-do-correct.
---
packages/auto-correct/auto-correct.el | 29 +++++++++++++++++++++++------
1 file changed, 23 insertions(+), 6 deletions(-)
diff --git a/packages/auto-correct/auto-correct.el
b/packages/auto-correct/auto-correct.el
index 39c224d..528dad2 100644
--- a/packages/auto-correct/auto-correct.el
+++ b/packages/auto-correct/auto-correct.el
@@ -5,7 +5,7 @@
;; Author: Ian Dunn <address@hidden>
;; Maintainer: Ian Dunn <address@hidden>
;; Keywords: editing
-;; Version: 1.1.3
+;; Version: 1.1.4
;; This file is part of GNU Emacs.
@@ -204,19 +204,32 @@ indicating whether to activate or deactivate support."
;; Flyspell Support
+(defvar-local auto-correct--flyspell-old-word nil)
+
(defvar flyspell-auto-correct-word)
(defvar flyspell-use-global-abbrev-table-p)
(defvar flyspell-insert-function)
+(defun auto-correct--flyspell-do-correct-wrapper (oldfun replace poss word
cursor-location start end save)
+ "Wraps `flyspell-do-correct' to store the word it's correcting."
+ (let ((auto-correct--flyspell-old-word word))
+ (funcall oldfun replace poss word cursor-location start end save)))
+
(defun auto-correct-flyspell-insert (word)
"Insert WORD and add it as a correction.
The original (misspelled) word is drawn from the variable
-`flyspell-auto-correct-word'.
+`flyspell-auto-correct-word' (if coming from
+`flyspell-auto-correct-word') or `auto-correct--flyspell-old-word'
+if coming from `flyspell-do-correct'.
When `auto-correct-mode' is enabled, this function is set as
`flyspell-insert-function'."
- (let ((old-word flyspell-auto-correct-word)
+ ;; If coming from `flyspell-auto-correct-word' (the function), use
+ ;; `flyspell-auto-correct-word' (the variable) for the old word. Otherwise,
+ ;; we're coming from `flyspell-do-correct', so use our stored old word.
+ (let ((old-word (or flyspell-auto-correct-word
+ auto-correct--flyspell-old-word))
(new-word word)
(local (not flyspell-use-global-abbrev-table-p)))
(auto-correct--add-or-update-correction old-word new-word local)))
@@ -230,9 +243,13 @@ Otherwise, deactivate it.
Activation means adding `auto-correct-flyspell-insert' to
`flyspell-insert-function'."
(if activate
- (add-function :before flyspell-insert-function
- #'auto-correct-flyspell-insert)
- (remove-function flyspell-insert-function #'auto-correct-flyspell-insert)))
+ (progn
+ (advice-add 'flyspell-do-correct :around
+ #'auto-correct--flyspell-do-correct-wrapper)
+ (add-function :before flyspell-insert-function
+ #'auto-correct-flyspell-insert))
+ (remove-function flyspell-insert-function #'auto-correct-flyspell-insert)
+ (advice-remove 'flyspell-do-correct
#'auto-correct--flyspell-do-correct-wrapper)))
;; Silence the byte-compiler; this will be enabled shortly
(defvar auto-correct-enable-flyspell-support)
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [elpa] master 00cdd17: auto-correct: Add support for flyspell-correct-word-*,
Ian Dunn <=