Function: completion-preview--show
completion-preview--show is a byte-compiled function defined in
completion-preview.el.gz.
Signature
(completion-preview--show)
Documentation
Show a new completion preview.
Call completion-at-point-functions in order to obtain and
display a completion candidate for the text around point.
If the preview is already shown, first check whether the suggested candidate remains a valid completion for the text at point. If so, update the preview according the new text at point, otherwise hide it.
Source Code
;; Defined in /usr/src/emacs/lisp/completion-preview.el.gz
(defun completion-preview--show ()
"Show a new completion preview.
Call `completion-at-point-functions' in order to obtain and
display a completion candidate for the text around point.
If the preview is already shown, first check whether the
suggested candidate remains a valid completion for the text at
point. If so, update the preview according the new text at
point, otherwise hide it."
(when completion-preview-active-mode
;; We were already showing a preview before this command, so we
;; check if the text before point is still a prefix of the
;; candidate that the preview suggested, and if so we first update
;; existing preview according to the changes made by this command,
;; and only then try to get a new candidate. This ensures that we
;; never display a stale preview and that the preview doesn't
;; flicker, even with slow completion backends.
(let* ((beg (completion-preview--get 'completion-preview-beg))
(end (max (point) (overlay-start completion-preview--overlay)))
(sufs (completion-preview--get 'completion-preview-suffixes))
(index (completion-preview--get 'completion-preview-index))
(common (completion-preview--get 'completion-preview-common))
(suffix (nth index sufs))
(cand nil))
(set-text-properties 0 (length suffix)
(list 'face (if (cdr sufs)
'completion-preview
'completion-preview-exact))
suffix)
(setq cand (concat common (nth index sufs)))
(if (and (<= beg (point) end (1- (+ beg (length cand))))
(string-prefix-p (buffer-substring beg end) cand))
;; The previous preview is still applicable, update it.
(overlay-put (completion-preview--make-overlay
end (propertize (substring cand (- end beg))
'mouse-face 'completion-preview-highlight
'keymap completion-preview--mouse-map))
'completion-preview-end end)
;; The previous preview is no longer applicable, hide it.
(completion-preview-active-mode -1))))
;; Run `completion-at-point-functions' to get a new candidate.
(if completion-preview-idle-delay
(setq completion-preview--timer
(run-with-idle-timer completion-preview-idle-delay
nil #'completion-preview--update-from-timer
(selected-window) (current-buffer)))
(completion-preview--try-update)))