summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Mendler <mail@daniel-mendler.de>2023-04-09 17:08:16 +0200
committerDaniel Mendler <mail@daniel-mendler.de>2023-04-09 17:08:16 +0200
commitadb80db319d3b2b7075ab18e4431167f6055f763 (patch)
tree6d24159c226c104fc6ff3f6aa7e676bb303b53ec
parentc88e1ee3026af6d1734c0e171555c1ae9152f07a (diff)
Improve cape-dict for cape-dict-grep=nil
-rw-r--r--cape.el38
1 files changed, 18 insertions, 20 deletions
diff --git a/cape.el b/cape.el
index 0d570ab..68f96c9 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))))