From: Eshel Yaron Date: Sun, 29 Oct 2023 12:07:46 +0000 (+0100) Subject: Handle non-zero completion base offset X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=2fd7429656a616451fbd453ca12c70f37918e5fd;p=completion-preview.git Handle non-zero completion base offset --- diff --git a/completion-preview.el b/completion-preview.el index 49b8bff..1074e12 100644 --- a/completion-preview.el +++ b/completion-preview.el @@ -119,10 +119,12 @@ Compatibility definition for `minibuffer--sort-by-length-alpha'." (or (plist-get plist :predicate) completion-preview-predicate) (- (point) beg) md)) - (last (last all))) + (last (last all)) + (base (or (cdr last) 0)) + (prefix (substring string base))) (when last (setcdr last nil) - (let* ((filtered (seq-filter (apply-partially #'string-prefix-p string) + (let* ((filtered (seq-filter (apply-partially #'string-prefix-p prefix) all)) (sorted (funcall sort-fn filtered)) (multi (cadr sorted)) ; multiple candidates @@ -130,7 +132,7 @@ Compatibility definition for `minibuffer--sort-by-length-alpha'." (when (and cand (not (and multi completion-preview-exact-match-only))) (let* ((face (if multi 'completion-preview 'completion-preview-exact)) - (after (propertize (substring cand (length string)) 'face face))) + (after (propertize (substring cand (length prefix)) 'face face))) (unless (string-empty-p after) (add-text-properties 0 1 '(cursor 1) after)) (setq completion-preview--overlay (make-overlay end end))