summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Mendler <mail@daniel-mendler.de>2022-02-27 04:11:52 +0100
committerDaniel Mendler <mail@daniel-mendler.de>2022-02-27 04:11:52 +0100
commite93aff671929177263068edfe5894e192840c3fe (patch)
tree5f1f16555c375d138e1404184d320dd2f4c65a3e
parent4f52903663370dfb674fed0ff75659b78e8b81cf (diff)
Fix cape-super-cache invalidation (Fix #29)
-rw-r--r--README.org1
-rw-r--r--cape.el41
2 files changed, 22 insertions, 20 deletions
diff --git a/README.org b/README.org
index c5b8a28..6c50dd1 100644
--- a/README.org
+++ b/README.org
@@ -170,6 +170,7 @@ then be used as a Capf via ~cape-company-to-capf~.
Cape supports merging multiple Capfs using the function ~cape-super-capf~. This
feature is experimental and should only be used in special scenarios.
+*Don't use cape-super-capf if you are not 100% sure that you need it!*
Note that ~cape-super-capf~ is not needed if you want to use multiple Capfs which
are tried one by one, e.g., it is perfectly possible to use ~cape-file~ together
diff --git a/cape.el b/cape.el
index 6a205a3..00cc373 100644
--- a/cape.el
+++ b/cape.el
@@ -821,7 +821,7 @@ If INTERACTIVE is nil the function acts like a capf."
(when-let (results (delq nil (mapcar #'funcall capfs)))
(pcase-let* ((`((,beg ,end . ,_)) results)
(cache-candidates nil)
- (cache-str nil)
+ (cache-filter nil)
(cache-ht (make-hash-table :test #'equal))
(extra-fun
(lambda (prop)
@@ -851,25 +851,26 @@ If INTERACTIVE is nil the function acts like a capf."
(display-sort-function . identity)
(cycle-sort-function . identity)))
('t
- (unless (equal str cache-str)
- (let ((ht (make-hash-table :test #'equal))
- (candidates nil))
- (cl-loop for (table . plist) in tables do
- (let* ((pr (plist-get plist :predicate))
- (md (completion-metadata "" table pr))
- (sort (or (completion-metadata-get md 'display-sort-function)
- #'identity))
- (cands (funcall sort (all-completions str table pr))))
- (cl-loop for cell on cands
- for cand = (car cell) do
- (if (and (eq (gethash cand ht t) t)
- (or (not pred) (funcall pred cand)))
- (puthash cand plist ht)
- (setcar cell nil)))
- (setq candidates (nconc candidates cands))))
- (setq cache-str str
- cache-candidates (delq nil candidates)
- cache-ht ht)))
+ (let ((filter (list str (copy-sequence completion-regexp-list) completion-ignore-case)))
+ (unless (equal filter cache-filter)
+ (let ((ht (make-hash-table :test #'equal))
+ (candidates nil))
+ (cl-loop for (table . plist) in tables do
+ (let* ((pr (plist-get plist :predicate))
+ (md (completion-metadata "" table pr))
+ (sort (or (completion-metadata-get md 'display-sort-function)
+ #'identity))
+ (cands (funcall sort (all-completions str table pr))))
+ (cl-loop for cell on cands
+ for cand = (car cell) do
+ (if (and (eq (gethash cand ht t) t)
+ (or (not pred) (funcall pred cand)))
+ (puthash cand plist ht)
+ (setcar cell nil)))
+ (setq candidates (nconc candidates cands))))
+ (setq cache-filter (list str (copy-sequence completion-regexp-list) completion-ignore-case)
+ cache-candidates (delq nil candidates)
+ cache-ht ht))))
(copy-sequence cache-candidates))
(_
(completion--some