(prefix (substring string base)))
(when last
(setcdr last nil)
- (let* ((filtered (seq-filter (apply-partially #'string-prefix-p prefix)
- all))
+ (let* ((filtered
+ (seq-filter (apply-partially #'string-prefix-p prefix) all))
(sorted (funcall sort-fn filtered))
(multi (cadr sorted)) ; multiple candidates
(cand (car sorted)))
- (when (and cand
- (not (and multi completion-preview-exact-match-only)))
+ (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 prefix)) 'face face)))
(unless (string-empty-p after)
(add-text-properties 0 1 '(cursor 1) after)
(setq completion-preview--overlay (make-overlay end end))
(overlay-put completion-preview--overlay 'after-string after)
- (overlay-put completion-preview--overlay 'completion-preview-plist plist)
- (overlay-put completion-preview--overlay 'completion-preview-string cand)
+ (overlay-put completion-preview--overlay 'completion-preview-data
+ (append (list beg end (list cand)) plist))
(completion-preview-active-mode)))))))))))
(defun completion-preview--post-command ()
(while-no-input
(completion-preview-show))))
-(defun completion-preview--insert ()
- "Insert the completion preview suggestion."
- (let ((after (substring-no-properties
- (overlay-get completion-preview--overlay 'after-string)))
- (string (overlay-get completion-preview--overlay
- 'completion-preview-string))
- (plist (overlay-get completion-preview--overlay
- 'completion-preview-plist)))
- (completion-preview-active-mode -1)
- (insert after)
- (when-let ((exit-fn (plist-get plist :exit-function)))
- (funcall exit-fn string 'finished))))
-
-(defun completion-preview-insert-function ()
- "Return a function inserting the completion preview."
- #'completion-preview--insert)
-
(define-minor-mode completion-preview-active-mode
"Mode for when the completion preview is active."
:interactive nil
(if completion-preview-active-mode
- (add-hook 'completion-at-point-functions
- #'completion-preview-insert-function -1 t)
- (remove-hook 'completion-at-point-functions
- #'completion-preview-insert-function t)
+ (add-hook 'completion-at-point-functions #'completion-preview-insert -1 t)
+ (remove-hook 'completion-at-point-functions #'completion-preview-insert t)
(completion-preview-hide)))
+(defun completion-preview-insert ()
+ "Completion at point function for inserting the current preview."
+ (when completion-preview-active-mode
+ (overlay-get completion-preview--overlay 'completion-preview-data)))
+
;;;###autoload
(define-minor-mode completion-preview-mode
"Show in-buffer completion preview as you type."