branch: externals/capf-autosuggest
commit 531b04c2e1eb96c26f855fc04f40659bfbd5c9bd
Author: jakanakaevangeli <[email protected]>
Commit: jakanakaevangeli <[email protected]>
Take completion boundaries/base into account
---
capf-autosuggest.el | 40 +++++++++++++++++++++-------------------
1 file changed, 21 insertions(+), 19 deletions(-)
diff --git a/capf-autosuggest.el b/capf-autosuggest.el
index 6c9ec6b..9662ca1 100644
--- a/capf-autosuggest.el
+++ b/capf-autosuggest.el
@@ -109,25 +109,27 @@ point forward."
'capf-autosuggest-capf)
#'completion--capf-wrapper 'all)
(`(,_fun ,beg ,end ,table . ,plist)
- (when-let*
- ((completions
- (let ((capf-autosuggest-all-completions-only-one t))
- ;; Use `all-completions' rather than
- ;; `completion-all-completions' to bypass completion
- ;; styles and perform only prefix completions. This makes
- ;; sense here as we only use the string without the
- ;; prefix for the overlay.
- (all-completions (buffer-substring-no-properties beg end)
- table (plist-get plist :predicate))))
- (str (substring (car completions) (- end beg)))
- ((/= 0 (length str))))
- (setq capf-autosuggest--region (cons beg end)
- capf-autosuggest--str (copy-sequence str))
- (move-overlay capf-autosuggest--overlay end end)
- (add-text-properties 0 1 (list 'cursor (length str)) str)
- (add-face-text-property 0 (length str) 'capf-autosuggest-face t str)
- (overlay-put capf-autosuggest--overlay 'after-string str)
- (capf-autosuggest-active-mode)))))))
+ (let* ((pred (plist-get plist :predicate))
+ (string (buffer-substring-no-properties beg end))
+ (base (car (completion-boundaries string table pred ""))))
+ (when-let*
+ ((completions
+ (let ((capf-autosuggest-all-completions-only-one t))
+ ;; Use `all-completions' rather than
+ ;; `completion-all-completions' to bypass completion styles
+ ;; and strictly match only on prefix. This makes sense here
+ ;; as we only use the string without the prefix for the
+ ;; overlay.
+ (all-completions string table pred)))
+ (str (substring (car completions) (- end beg base)))
+ ((/= 0 (length str))))
+ (setq capf-autosuggest--region (cons beg end)
+ capf-autosuggest--str (copy-sequence str))
+ (move-overlay capf-autosuggest--overlay end end)
+ (add-text-properties 0 1 (list 'cursor (length str)) str)
+ (add-face-text-property 0 (length str) 'capf-autosuggest-face t
str)
+ (overlay-put capf-autosuggest--overlay 'after-string str)
+ (capf-autosuggest-active-mode))))))))
;;;###autoload
(define-minor-mode capf-autosuggest-mode