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

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

[elpa] externals/company 10fcb21d46 09/30: Remove suffix after completio


From: ELPA Syncer
Subject: [elpa] externals/company 10fcb21d46 09/30: Remove suffix after completion by company-dabbrev-code too
Date: Sat, 13 Jul 2024 00:57:50 -0400 (EDT)

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

    Remove suffix after completion by company-dabbrev-code too
    
    Though only when company-dabbrev-code-completion-styles is non-nil.
    
    #340
    #1106
---
 company-capf.el         | 22 +++++++++++-----------
 company-dabbrev-code.el | 46 ++++++++++++++++++++++++++++------------------
 company.el              |  3 ++-
 3 files changed, 41 insertions(+), 30 deletions(-)

diff --git a/company-capf.el b/company-capf.el
index ff775e517d..93f54e16fc 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 (car rest)))
+     (company--capf-post-completion arg (nth 0 rest) (nth 1 rest)))
     ))
 
 (defun company-capf--annotation (arg)
@@ -220,15 +220,8 @@ so we can't just use the preceding variable instead.")
            (throw 'interrupted 'new-input))
       res)))
 
-(defun company--capf-post-completion (arg prefix)
-  (let* ((res company-capf--current-completion-data)
-         (exit-function (plist-get (nthcdr 4 res) :exit-function))
-         (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))
+(defun company--capf-chop-suffix (arg prefix suffix table &optional pred)
+  (let ((replace-suffix t))
     ;; If emacs22 is reached and matches, that style is used.
     (cl-letf (((symbol-function 'completion-emacs22-all-completions)
                (lambda (&rest _)
@@ -240,7 +233,14 @@ so we can't just use the preceding variable instead.")
                                   (length prefix)))
     (when replace-suffix
       ;; Replace unless the style is emacs22.
-      (delete-region (point) (+ (point) (length suffix))))
+      (delete-region (point) (+ (point) (length suffix))))))
+
+(defun company--capf-post-completion (arg prefix suffix)
+  (let* ((res company-capf--current-completion-data)
+         (exit-function (plist-get (nthcdr 4 res) :exit-function))
+         (pred (plist-get (nthcdr 4 res) :predicate))
+         (table (nth 3 res)))
+    (company--capf-chop-suffix arg prefix suffix table pred)
     (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-dabbrev-code.el b/company-dabbrev-code.el
index 1060c844fa..968ca967a2 100644
--- a/company-dabbrev-code.el
+++ b/company-dabbrev-code.el
@@ -106,24 +106,15 @@ comments or strings."
                  (or company-dabbrev-code-everywhere
                      (not (company-in-string-or-comment)))
                  (company-grab-symbol-parts)))
-    (candidates
-     (let* ((case-fold-search company-dabbrev-code-ignore-case)
-            (regexp (company-dabbrev-code--make-regexp arg)))
-       (company-dabbrev-code--filter
-        arg (car rest)
-        (company-cache-fetch
-         'dabbrev-code-candidates
-         (lambda ()
-           (company-dabbrev--search
-            regexp
-            company-dabbrev-code-time-limit
-            (pcase company-dabbrev-code-other-buffers
-              (`t (list major-mode))
-              (`code company-dabbrev-code-modes)
-              (`all `all))
-            (not company-dabbrev-code-everywhere)))
-         :expire t
-         :check-tag regexp))))
+    (candidates (company-dabbrev--candidates arg (car rest)))
+    (post-completion
+     (when company-dabbrev-code-completion-styles
+       (let ((completion-styles (if (listp 
company-dabbrev-code-completion-styles)
+                                    company-dabbrev-code-completion-styles
+                                  completion-styles)))
+         (require 'company-capf)
+         (company--capf-chop-suffix arg (nth 0 rest) (nth 1 rest)
+                                    (company-dabbrev--candidates arg (car 
rest))))))
     (kind 'text)
     (no-cache t)
     (ignore-case company-dabbrev-code-ignore-case)
@@ -131,6 +122,25 @@ comments or strings."
              (company--match-from-capf-face arg)))
     (duplicates t)))
 
+(defun company-dabbrev--candidates (prefix suffix)
+  (let* ((case-fold-search company-dabbrev-code-ignore-case)
+         (regexp (company-dabbrev-code--make-regexp prefix)))
+    (company-dabbrev-code--filter
+     prefix suffix
+     (company-cache-fetch
+      'dabbrev-code-candidates
+      (lambda ()
+        (company-dabbrev--search
+         regexp
+         company-dabbrev-code-time-limit
+         (pcase company-dabbrev-code-other-buffers
+           (`t (list major-mode))
+           (`code company-dabbrev-code-modes)
+           (`all `all))
+         (not company-dabbrev-code-everywhere)))
+      :expire t
+      :check-tag regexp))))
+
 (defun company-dabbrev-code--filter (prefix suffix table)
   (let ((completion-ignore-case company-dabbrev-code-ignore-case)
         (completion-styles (if (listp company-dabbrev-code-completion-styles)
diff --git a/company.el b/company.el
index a4d7824486..06e19655a1 100644
--- a/company.el
+++ b/company.el
@@ -2356,6 +2356,7 @@ For more details see `company-insertion-on-trigger' and
 
 (defun company-cancel (&optional result)
   (let ((prefix company-prefix)
+        (suffix company-suffix)
         (backend company-backend))
     (setq company-backend nil
           company-prefix nil
@@ -2383,7 +2384,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 prefix))
+            (company-call-backend 'post-completion result prefix suffix))
         (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]