emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/jinx 9982192145: Add jinx--correct-replace (Fix #81)


From: ELPA Syncer
Subject: [elpa] externals/jinx 9982192145: Add jinx--correct-replace (Fix #81)
Date: Thu, 25 May 2023 12:58:01 -0400 (EDT)

branch: externals/jinx
commit 9982192145500bb9fa6f2d7d2ed4db6cd7f905d9
Author: Daniel Mendler <mail@daniel-mendler.de>
Commit: Daniel Mendler <mail@daniel-mendler.de>

    Add jinx--correct-replace (Fix #81)
---
 jinx.el | 28 ++++++++++++++++------------
 1 file changed, 16 insertions(+), 12 deletions(-)

diff --git a/jinx.el b/jinx.el
index 48adda1dca..4bf4bdcb8a 100644
--- a/jinx.el
+++ b/jinx.el
@@ -710,18 +710,22 @@ If CHECK is non-nil, always check first."
                      nil nil nil t word)
                     word)))))
          (len (length choice)))
-    (if-let ((save (and (> len 0) (assq (aref choice 0) jinx--save-keys))))
-        (progn
-          (funcall (cdr save) 'save (car save) (if (> len 1) (substring choice 
1) word))
-          (jinx--recheck-overlays))
-      (when-let (((not (equal choice word)))
-                 (start (overlay-start overlay))
-                 (end (overlay-end overlay)))
-        (undo-boundary)
-        (delete-overlay overlay)
-        (goto-char end)
-        (insert-before-markers choice)
-        (delete-region start end)))))
+    (pcase (and (> len 0) (assq (aref choice 0) jinx--save-keys))
+      (`(,key . ,fun)
+       (funcall fun 'save key (if (> len 1) (substring choice 1) word))
+       (jinx--recheck-overlays))
+      ((guard (not (equal choice word)))
+       (jinx--correct-replace overlay choice)))))
+
+(defun jinx--correct-replace (overlay word)
+  "Replace OVERLAY with WORD."
+  (when-let ((start (overlay-start overlay))
+             (end (overlay-end overlay)))
+    (undo-boundary)
+    (delete-overlay overlay)
+    (goto-char end)
+    (insert-before-markers word)
+    (delete-region start end)))
 
 (defun jinx--load-dicts ()
   "Load dictionaries and setup syntax table."



reply via email to

[Prev in Thread] Current Thread [Next in Thread]