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

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

[elpa] externals/cape 0e60999893 032/146: cape-ispell: Fix caching


From: ELPA Syncer
Subject: [elpa] externals/cape 0e60999893 032/146: cape-ispell: Fix caching
Date: Sun, 9 Jan 2022 20:57:40 -0500 (EST)

branch: externals/cape
commit 0e60999893d4f7b7442a63be4761368ea0b1d25a
Author: Daniel Mendler <mail@daniel-mendler.de>
Commit: Daniel Mendler <mail@daniel-mendler.de>

    cape-ispell: Fix caching
---
 cape.el | 42 +++++++++++++++++++++++-------------------
 1 file changed, 23 insertions(+), 19 deletions(-)

diff --git a/cape.el b/cape.el
index 0af2f6ea42..b5b52839ef 100644
--- a/cape.el
+++ b/cape.el
@@ -386,35 +386,39 @@
         :company-kind (lambda (_) 'text)))
 
 (declare-function ispell-lookup-words "ispell")
-(defun cape--ispell-words (str)
-  "Return words from Ispell which match STR."
-  (require 'ispell)
-  (with-demoted-errors
-      (let ((message-log-max nil)
-            (inhibit-message t))
-        (ispell-lookup-words (format "*%s*" str)))))
+(defun cape--ispell-table (bounds)
+  "Return completion table for Ispell completion between BOUNDS."
+  (let ((input nil)
+        (beg (copy-marker (car bounds)))
+        (end (copy-marker (car bounds) t))
+        (words 'init))
+    (lambda (str pred action)
+      (let ((new-input (buffer-substring-no-properties beg end)))
+        (when (or (eq words 'init) (not (string-match-p (regexp-quote input) 
new-input)))
+          (setq input new-input
+                words (with-demoted-errors
+                          (require 'ispell)
+                        (let ((message-log-max nil)
+                              (inhibit-message t))
+                          (ispell-lookup-words (format "*%s*" input)))))))
+      (complete-with-action action words str pred))))
 
 ;;;###autoload
 (defun cape-ispell-capf ()
   "Ispell completion-at-point-function."
   (when-let (bounds (bounds-of-thing-at-point 'word))
-    (let ((input (buffer-substring-no-properties (car bounds) (cdr bounds)))
-          (words nil))
-      `(,(car bounds) ,(cdr bounds)
-        ,(lambda (str pred action)
-           (complete-with-action
-            action (or words (setq words (cape--ispell-words input))) str 
pred))
-        :exclusive no
-        ,@cape--ispell-properties))))
+    `(,(car bounds) ,(cdr bounds)
+      ,(cape--ispell-table bounds)
+      :exclusive no
+      ,@cape--ispell-properties)))
 
 ;;;###autoload
 (defun cape-ispell ()
   "Complete with Ispell at point."
   (interactive)
-  (let* ((bounds (or (bounds-of-thing-at-point 'word) (cons (point) (point))))
-         (input (buffer-substring-no-properties (car bounds) (cdr bounds)))
-         (completion-extra-properties cape--ispell-properties))
-    (completion-in-region (car bounds) (cdr bounds) (cape--ispell-words 
input))))
+  (let ((bounds (or (bounds-of-thing-at-point 'word) (cons (point) (point))))
+        (completion-extra-properties cape--ispell-properties))
+    (completion-in-region (car bounds) (cdr bounds) (cape--ispell-table 
bounds))))
 
 (defvar cape--dict-properties
   (list :annotation-function (lambda (_) " Dict")



reply via email to

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