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

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

[elpa] externals/company b5db1934ce 08/30: company--capf-post-completion


From: ELPA Syncer
Subject: [elpa] externals/company b5db1934ce 08/30: company--capf-post-completion: Make sure to replace the suffix
Date: Sat, 13 Jul 2024 00:57:50 -0400 (EDT)

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

    company--capf-post-completion: Make sure to replace the suffix
    
    Unless the completion style ignores the suffix (the only currently known 
example
    in emacs22, so we hardcode it, for now).
    
    #340
    #1106
---
 company-capf.el | 23 ++++++++++++++++++++---
 company.el      |  7 ++-----
 2 files changed, 22 insertions(+), 8 deletions(-)

diff --git a/company-capf.el b/company-capf.el
index e43cbdf009..ff775e517d 100644
--- a/company-capf.el
+++ b/company-capf.el
@@ -160,7 +160,7 @@ so we can't just use the preceding variable instead.")
      (plist-get (nthcdr 4 (company--capf-data)) :company-require-match))
     (`init nil)      ;Don't bother: plenty of other ways to initialize the 
code.
     (`post-completion
-     (company--capf-post-completion arg))
+     (company--capf-post-completion arg (car rest)))
     ))
 
 (defun company-capf--annotation (arg)
@@ -220,10 +220,27 @@ so we can't just use the preceding variable instead.")
            (throw 'interrupted 'new-input))
       res)))
 
-(defun company--capf-post-completion (arg)
+(defun company--capf-post-completion (arg prefix)
   (let* ((res company-capf--current-completion-data)
          (exit-function (plist-get (nthcdr 4 res) :exit-function))
-         (table (nth 3 res)))
+         (pred (plist-get (nthcdr 4 res) :predicate))
+         (suffix (buffer-substring (+ (nth 1 res) (length arg))
+                                   (+ (nth 2 res)
+                                      (- (length arg) (length prefix)))))
+         (table (nth 3 res))
+         (replace-suffix t))
+    ;; If emacs22 is reached and matches, that style is used.
+    (cl-letf (((symbol-function 'completion-emacs22-all-completions)
+               (lambda (&rest _)
+                 (and (member arg
+                              (all-completions prefix table pred))
+                      (setq replace-suffix nil)))))
+      (completion-all-completions (concat prefix suffix)
+                                  table pred
+                                  (length prefix)))
+    (when replace-suffix
+      ;; Replace unless the style is emacs22.
+      (delete-region (point) (+ (point) (length suffix))))
     (if exit-function
         ;; We can more or less know when the user is done with completion,
         ;; so we do something different than `completion--done'.
diff --git a/company.el b/company.el
index 9bde013cba..a4d7824486 100644
--- a/company.el
+++ b/company.el
@@ -1483,10 +1483,7 @@ be recomputed when this value changes."
         (insert (company-strip-prefix candidate))
       (unless (equal company-prefix candidate)
         (delete-region (- (point) (length company-prefix)) (point))
-        (insert candidate)))
-    ;; FIXME: Ideally delegate to backend (to know how much to replace).
-    (when (string-suffix-p company-suffix (company-strip-prefix candidate))
-      (delete-char (length company-suffix)))))
+        (insert candidate)))))
 
 (defmacro company-with-candidate-inserted (candidate &rest body)
   "Evaluate BODY with CANDIDATE temporarily inserted.
@@ -2386,7 +2383,7 @@ For more details see `company-insertion-on-trigger' and
       (if (stringp result)
           (let ((company-backend backend))
             (run-hook-with-args 'company-completion-finished-hook result)
-            (company-call-backend 'post-completion result))
+            (company-call-backend 'post-completion result prefix))
         (run-hook-with-args 'company-completion-cancelled-hook result))
       (run-hook-with-args 'company-after-completion-hook result)))
   ;; Make return value explicit.



reply via email to

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