[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.
- [elpa] externals/company updated (8d2ca28a16 -> 31f7ad52e4), ELPA Syncer, 2024/07/13
- [elpa] externals/company 22551866cc 03/30: Switch to non-obsolete function, ELPA Syncer, 2024/07/13
- [elpa] externals/company b5db1934ce 08/30: company--capf-post-completion: Make sure to replace the suffix,
ELPA Syncer <=
- [elpa] externals/company 01e82364bf 23/30: company-post-command: Refresh more often, ELPA Syncer, 2024/07/13
- [elpa] externals/company 78ed92db96 14/30: Fix "Attempt to modify read-only object", ELPA Syncer, 2024/07/13
- [elpa] externals/company ff6107bde3 04/30: company-inhibit-inside-symbols: New option, ELPA Syncer, 2024/07/13
- [elpa] externals/company 426e1830ff 06/30: company--unique-match-p: Also include suffix, ELPA Syncer, 2024/07/13
- [elpa] externals/company d7e77b9673 01/30: #1106 #340 Complete inside symbols, ELPA Syncer, 2024/07/13
- [elpa] externals/company 7ed2baeedd 05/30: Merge branch 'master' into completion_inside_symbol, ELPA Syncer, 2024/07/13
- [elpa] externals/company ebe5244443 07/30: Merge branch 'master' into completion_inside_symbol, ELPA Syncer, 2024/07/13
- [elpa] externals/company 10fcb21d46 09/30: Remove suffix after completion by company-dabbrev-code too, ELPA Syncer, 2024/07/13
- [elpa] externals/company 2fefdc7ce3 02/30: Fix test failures, ELPA Syncer, 2024/07/13
- [elpa] externals/company 436b0d6247 10/30: New backend command `adjust-boundaries`, ELPA Syncer, 2024/07/13