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

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

[elpa] externals/cape a878347ebd 2/2: cape-company-to-capf: Overhaul can


From: ELPA Syncer
Subject: [elpa] externals/cape a878347ebd 2/2: cape-company-to-capf: Overhaul candidate lookup in :exit-function
Date: Fri, 8 Dec 2023 03:57:34 -0500 (EST)

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

    cape-company-to-capf: Overhaul candidate lookup in :exit-function
    
    The :exit-function looks up the candidate in order to restore text 
properties.
    This lookup is not necessary with Corfu, which guarantees that the 
candidates
    are propertized. The lookup even hurts since duplicate candidates lose their
    specificity, they would get replaced by their first occurrence in the 
candidate
    list.
---
 cape.el | 27 +++++++++++++++++----------
 1 file changed, 17 insertions(+), 10 deletions(-)

diff --git a/cape.el b/cape.el
index 4c9ec3c6c9..531e4a8ebd 100644
--- a/cape.el
+++ b/cape.el
@@ -786,7 +786,7 @@ changed.  The function `cape-company-to-capf' is 
experimental."
       (let* ((end (point)) (beg (- end (length initial-input)))
              (valid (if (cape--company-call backend 'no-cache initial-input)
                         #'equal (or valid #'string-prefix-p)))
-             candidates)
+             restore-props)
         (list beg end
               (funcall
                (if (cape--company-call backend 'ignore-case)
@@ -796,8 +796,15 @@ changed.  The function `cape-company-to-capf' is 
experimental."
                 (cape--dynamic-table
                  beg end
                  (lambda (input)
-                   (setq candidates (cape--company-call backend 'candidates 
input))
-                   (cons (apply-partially valid input) candidates)))
+                   (let ((cands (cape--company-call backend 'candidates 
input)))
+                     ;; The candidate string including text properties should 
be
+                     ;; restored in the :exit-function, if the UI does not
+                     ;; guarantee this itself.  Restoration is not necessary 
for
+                     ;; Corfu since the introduction of `corfu--exit-function'.
+                     (unless (and (eq completion-in-region-function 
'corfu--in-region)
+                                  (fboundp 'corfu--exit-function))
+                       (setq restore-props cands))
+                     (cons (apply-partially valid input) cands))))
                 :category backend
                 :sort (not (cape--company-call backend 'sorted))))
               :exclusive 'no
@@ -809,13 +816,13 @@ changed.  The function `cape-company-to-capf' is 
experimental."
               :company-kind (lambda (x) (cape--company-call backend 'kind x))
               :annotation-function (lambda (x)
                                      (when-let (ann (cape--company-call 
backend 'annotation x))
-                                       (if (string-match-p "^[ \t]" ann)
-                                           ann
-                                         (concat " " ann))))
-              :exit-function
-              (lambda (x _status)
-                (cape--company-call backend 'post-completion
-                                    (or (car (member x candidates)) x))))))))
+                                       (concat " " (string-trim ann))))
+              :exit-function (lambda (x _status)
+                               ;; Restore the candidate string including
+                               ;; properties if restore-props is non-nil.  See
+                               ;; the comment above.
+                               (setq x (or (car (member x restore-props)) x))
+                               (cape--company-call backend 'post-completion 
x)))))))
 
 ;;;###autoload
 (defun cape-interactive (&rest capfs)



reply via email to

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