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

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

[elpa] externals/company 477799b362 18/30: Make suffix matching use "pro


From: ELPA Syncer
Subject: [elpa] externals/company 477799b362 18/30: Make suffix matching use "proper suffix" logic by default
Date: Sat, 13 Jul 2024 00:57:51 -0400 (EDT)

branch: externals/company
commit 477799b36210ee27ca8501b6d47637db40ea0a55
Author: Dmitry Gutov <dmitry@gutov.dev>
Commit: Dmitry Gutov <dmitry@gutov.dev>

    Make suffix matching use "proper suffix" logic by default
    
    And add popup highlighting for success (when completion will replace it).
---
 company.el | 26 ++++++++++++++++++++++----
 1 file changed, 22 insertions(+), 4 deletions(-)

diff --git a/company.el b/company.el
index 99758ab7e5..f35fb96131 100644
--- a/company.el
+++ b/company.el
@@ -2443,13 +2443,25 @@ For more details see `company-insertion-on-trigger' and
 (defsubst company-keep (command)
   (and (symbolp command) (get command 'company-keep)))
 
+(defun company--proper-suffix-p (candidate)
+  (and
+   (>= (length candidate)
+       (+ (length company-prefix)
+          (length company-suffix)))
+   (string-suffix-p company-suffix candidate
+                    (company-call-backend 'ignore-case))))
+
 (defun company--boundaries (&optional candidate)
   (or
    (company-call-backend 'adjust-boundaries
                          (or candidate
                              (nth (or company-selection 0) company-candidates))
                          company-prefix company-suffix)
-   (cons company-prefix company-suffix)))
+   (and
+    ;; Default to replacing the suffix only if the completion ends with it.
+    (company--proper-suffix-p candidate)
+    (cons company-prefix company-suffix))
+   (cons company-prefix "")))
 
 (defun company--active-p ()
   company-candidates)
@@ -3487,7 +3499,7 @@ If SHOW-VERSION is non-nil, show the version in the echo 
area."
       (pop copy))
     (apply 'concat pieces)))
 
-(defun company--common-or-matches (value)
+(defun company--common-or-matches (value &optional suffix)
   (let ((matches (company-call-backend 'match value)))
     (when (and matches
                company-common
@@ -3499,7 +3511,13 @@ If SHOW-VERSION is non-nil, show the version in the echo 
area."
     (when (integerp matches)
       (setq matches `((0 . ,matches))))
     (or matches
-        (and company-common `((0 . ,(length company-common))))
+        (and company-common `((0 . ,(length company-common))
+                              ,@(list
+                                 (cons
+                                  (- (length value)
+                                     (length (or suffix
+                                                 (cdr (company--boundaries 
value)))))
+                                  (length value)))))
         nil)))
 
 (defun company-fill-propertize (value annotation width selected left right)
@@ -4221,7 +4239,7 @@ Delay is determined by `company-tooltip-idle-delay'."
          (company-common (and company-common
                               (string-prefix-p prefix company-common)
                               company-common))
-         (common (company--common-or-matches completion)))
+         (common (company--common-or-matches completion suffix)))
     (setq completion (copy-sequence (company--pre-render completion)))
     (add-face-text-property 0 (length completion) 'company-preview
                             nil completion)



reply via email to

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