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

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

[elpa] externals/cape f2ead46f52 1/2: cape-wrap-super: Check main backen


From: ELPA Syncer
Subject: [elpa] externals/cape f2ead46f52 1/2: cape-wrap-super: Check main backends for candidates
Date: Sat, 30 Mar 2024 21:57:31 -0400 (EDT)

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

    cape-wrap-super: Check main backends for candidates
    
    Only return candidates if one of the main backends returned a list of
    candidates. It is not sufficient if only one of the :with backends has
    candidates.
---
 cape.el | 24 +++++++++++++++---------
 1 file changed, 15 insertions(+), 9 deletions(-)

diff --git a/cape.el b/cape.el
index d2cfb93378..f829366988 100644
--- a/cape.el
+++ b/cape.el
@@ -904,23 +904,23 @@ The functions `cape-wrap-super' and `cape-capf-super' are
 experimental."
   (when-let ((results (cl-loop for capf in capfs until (eq capf :with)
                                for res = (funcall capf)
-                               if res collect res)))
+                               if res collect (cons t res))))
     (pcase-let* ((results (nconc results
                                  (cl-loop for capf in (cdr (memq :with capfs))
                                           for res = (funcall capf)
-                                          if res collect res)))
-                 (`((,beg ,end . ,_)) results)
+                                          if res collect (cons nil res))))
+                 (`((,_ ,beg ,end . ,_)) results)
                  (cand-ht nil)
                  (tables nil)
                  (prefix-len nil))
-      (cl-loop for (beg2 end2 . rest) in results do
+      (cl-loop for (main beg2 end2 . rest) in results do
                ;; TODO `cape-capf-super' currently cannot merge Capfs which
                ;; trigger at different beginning positions.  In order to 
support
                ;; this, take the smallest BEG value and then normalize all
                ;; candidates by prefixing them such that they all start at the
                ;; smallest BEG position.
                (when (= beg beg2)
-                 (push rest tables)
+                 (push (cons main rest) tables)
                  (setq end (max end end2))
                  (let ((plen (plist-get (cdr rest) :company-prefix-length)))
                    (cond
@@ -941,8 +941,9 @@ experimental."
                          (cycle-sort-function . identity)))
              ('t ;; all-completions
               (let ((ht (make-hash-table :test #'equal))
+                    (main-cands nil)
                     (candidates nil))
-                (cl-loop for (table . plist) in tables do
+                (cl-loop for (main table . plist) in tables do
                          (let* ((pr (if-let (pr (plist-get plist :predicate))
                                         (if pred
                                             (lambda (x) (and (funcall pr x) 
(funcall pred x)))
@@ -952,6 +953,7 @@ experimental."
                                 (sort (or (completion-metadata-get md 
'display-sort-function)
                                           #'identity))
                                 (cands (funcall sort (all-completions str 
table pr))))
+                           (setq main-cands (or main-cands (and main cands)))
                            ;; Handle duplicates with a hash table.
                            (cl-loop
                             for cand in-ref cands
@@ -967,10 +969,14 @@ experimental."
                               (setf cand (propertize cand 'cape-capf-super
                                                      (cons cand plist))))))
                            (push cands candidates)))
-                (setq cand-ht ht)
-                (apply #'nconc (nreverse candidates))))
+                ;; The backend is available if it has either been available
+                ;; before (cand-ht non-nil) or if a main backend returned
+                ;; candidates.
+                (when (or cand-ht main-cands)
+                  (setq cand-ht ht)
+                  (apply #'nconc (nreverse candidates)))))
              (_ ;; try-completion and test-completion
-              (cl-loop for (table . plist) in tables thereis
+              (cl-loop for (_main table . plist) in tables thereis
                        (complete-with-action
                         action table str
                         (if-let (pr (plist-get plist :predicate))



reply via email to

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