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

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

[elpa] externals/cape adb80db319: Improve cape-dict for cape-dict-grep=n


From: ELPA Syncer
Subject: [elpa] externals/cape adb80db319: Improve cape-dict for cape-dict-grep=nil
Date: Sun, 9 Apr 2023 11:57:21 -0400 (EDT)

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

    Improve cape-dict for cape-dict-grep=nil
---
 cape.el | 38 ++++++++++++++++++--------------------
 1 file changed, 18 insertions(+), 20 deletions(-)

diff --git a/cape.el b/cape.el
index 0d570abcb2..68f96c96d6 100644
--- a/cape.el
+++ b/cape.el
@@ -446,24 +446,25 @@ See the user options `cape-dabbrev-min-length' and
        (funcall cape-dict-file)
      cape-dict-file)))
 
+(defvar cape--dict-all-words nil)
 (defun cape--dict-grep-words (input)
   "Return all words from `cape-dict-file' matching INPUT."
   (unless (equal input "")
     (cape--case-replace-list
      cape-dict-case-replace input
-     (apply #'process-lines-ignore-status
-            "grep" "-Fi" input (cape--dict-file)))))
-
-(defvar cape--dict-all-words nil)
-(defun cape--dict-all-words ()
-  "Load all words from `cape-dict-file'."
-  (or cape--dict-all-words
-      (setq cape--dict-all-words
-            (split-string (with-temp-buffer
-                            (mapc #'insert-file-contents
-                                  (cape--dict-file))
-                            (buffer-string))
-                          "\n" 'omit-nulls))))
+     (if cape-dict-grep
+         (apply #'process-lines-ignore-status
+                "grep" "-Fi" input (cape--dict-file))
+       (unless cape--dict-all-words
+         (setq cape--dict-all-words
+               (split-string (with-temp-buffer
+                               (mapc #'insert-file-contents
+                                     (cape--dict-file))
+                               (buffer-string))
+                             "\n" 'omit-nulls)))
+       (let ((completion-ignore-case t)
+             (completion-regexp-list (list (regexp-quote input))))
+         (all-completions "" cape--dict-all-words))))))
 
 ;;;###autoload
 (defun cape-dict (&optional interactive)
@@ -476,13 +477,10 @@ If INTERACTIVE is nil the function acts like a Capf."
     (pcase-let ((`(,beg . ,end) (cape--bounds 'word)))
       `(,beg ,end
         ,(cape--table-with-properties
-          (if cape-dict-grep
-              (cape--cached-table beg end
-                                  #'cape--dict-grep-words
-                                  #'string-search)
-            (cape--case-replace-list cape-dict-case-replace
-                                     (buffer-substring-no-properties beg end)
-                                     (cape--dict-all-words)))
+          (cape--cached-table beg end
+                              #'cape--dict-grep-words
+                              (lambda (old new)
+                                (string-match-p (regexp-quote old) new)))
           :category 'cape-dict)
         ,@cape--dict-properties))))
 



reply via email to

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