branch: externals/cape
commit 84c5ccc04e8055665dac109e517e0cd90dd302a7
Author: Daniel Mendler <m...@daniel-mendler.de>
Commit: Daniel Mendler <m...@daniel-mendler.de>

    cape-super-capf: Mark as exclusive depending on the merged Capfs
---
 CHANGELOG.org |  2 ++
 cape.el       | 15 ++++++++++-----
 2 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/CHANGELOG.org b/CHANGELOG.org
index 9b8564b8ad..7ae37fcca7 100644
--- a/CHANGELOG.org
+++ b/CHANGELOG.org
@@ -10,6 +10,8 @@
   change improves compatibility with Company.
 - ~cape-capf-super~: Add support for the ~:with~ keyword. See the docstring of
   ~cape-wrap-super~ for details. This change improves compatibility with 
Company.
+- ~cape-capf-super~: The returned Capf is exclusive if one of the main Capfs 
(the
+  Capfs listed before the ~:with~ keyword) is exclusive.
 
 * Version 1.4 (2024-03-08)
 
diff --git a/cape.el b/cape.el
index d2cfb93378..c051e112be 100644
--- a/cape.el
+++ b/cape.el
@@ -904,16 +904,17 @@ 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))))
+                 (`((,_main ,beg ,end . ,_)) results)
                  (cand-ht nil)
                  (tables nil)
+                 (exclusive 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
@@ -921,6 +922,10 @@ experimental."
                ;; smallest BEG position.
                (when (= beg beg2)
                  (push rest tables)
+                 ;; The resulting merged Capf is exclusive if one of the main
+                 ;; Capfs is exclusive.
+                 (when (and main (not (eq (plist-get (cdr rest) :exclusive) 
'no)))
+                   (setq exclusive t))
                  (setq end (max end end2))
                  (let ((plen (plist-get (cdr rest) :company-prefix-length)))
                    (cond
@@ -978,8 +983,8 @@ experimental."
                                 (lambda (x) (and (funcall pr x) (funcall pred 
x)))
                               pr)
                           pred))))))
-        :exclusive no
         :company-prefix-length ,prefix-len
+        ,@(and (not exclusive) '(:exclusive no))
         ,@(mapcan
            (lambda (prop)
              (list prop (lambda (cand &rest args)

Reply via email to