Function: completion-preview-complete
completion-preview-complete is an interactive and byte-compiled
function defined in completion-preview.el.gz.
Signature
(completion-preview-complete)
Documentation
Complete up to the longest common prefix of all completion candidates.
If you call this command twice in a row, or otherwise if there is no
common prefix to insert, it displays the list of matching completion
candidates unless completion-auto-help is nil. If you repeat this
command again when the completions list is visible, it scrolls the
completions list.
Key Bindings
Source Code
;; Defined in /usr/src/emacs/lisp/completion-preview.el.gz
(defun completion-preview-complete ()
"Complete up to the longest common prefix of all completion candidates.
If you call this command twice in a row, or otherwise if there is no
common prefix to insert, it displays the list of matching completion
candidates unless `completion-auto-help' is nil. If you repeat this
command again when the completions list is visible, it scrolls the
completions list."
(interactive)
(unless completion-preview-active-mode
(user-error "No current completion preview"))
(let* ((beg (completion-preview--get 'completion-preview-beg))
(end (completion-preview--get 'completion-preview-end))
(com (completion-preview--get 'completion-preview-common))
(cur (completion-preview--get 'completion-preview-index))
(all (completion-preview--get 'completion-preview-suffixes))
(base (completion-preview--get 'completion-preview-base))
(props (completion-preview--get 'completion-preview-props))
(efn (plist-get props :exit-function))
(ins (substring-no-properties com (- end beg))))
(goto-char end)
(if (string-empty-p ins)
;; If there's nothing to insert, call `completion-at-point' to
;; show the completions list (or just display a message when
;; `completion-auto-help' is nil).
(let* ((completion-styles completion-preview-completion-styles)
(sub (substring-no-properties com))
(col (mapcar (lambda (suf)
(concat sub (substring-no-properties suf)))
(append (nthcdr cur all) (take cur all))))
;; The candidates are already in order.
(props (plist-put props :display-sort-function #'identity))
;; The :exit-function might be slow, e.g. when the
;; backend is Eglot, so we ensure that the preview is
;; hidden before any original :exit-function is called.
(props (plist-put props :exit-function
(when (functionp efn)
(lambda (string status)
(completion-preview-active-mode -1)
(funcall efn string status)))))
;; The predicate is meant for the original completion
;; candidates, which may be symbols or cons cells, but
;; now we only have strings, so it might not be applicable.
(props (plist-put props :predicate nil))
(completion-at-point-functions
(list (lambda () `(,beg ,end ,col ,@props)))))
(completion-preview--inhibit-update)
(completion-at-point))
;; Otherwise, insert the common prefix and update the preview.
(insert ins)
(let ((suf (nth cur all))
(pos (point)))
(if (or (string-empty-p suf) (null suf))
;; If we've inserted a full candidate, let the post-command
;; hook update the completion preview in case the candidate
;; can be completed further.
(when (functionp efn)
;; Remove stale preview since `efn' can make arbitrary
;; text and point modifications that might interfere with
;; a subsequent preview update. See bug#76606.
(completion-preview-active-mode -1)
(funcall efn (concat base com) (if (cdr all) 'exact 'finished)))
;; Otherwise, remove the common prefix from the preview.
(completion-preview--inhibit-update)
(overlay-put (completion-preview--make-overlay
pos (propertize
suf 'mouse-face 'completion-preview-highlight
'keymap completion-preview--mouse-map))
'completion-preview-end pos))))))