Function: completion-preview-partial-insert
completion-preview-partial-insert is a byte-compiled function defined
in completion-preview.el.gz.
Signature
(completion-preview-partial-insert FUN &rest ARGS)
Documentation
Insert part of the current completion preview candidate.
This function calls FUN with arguments ARGS, after temporarily inserting the entire current completion preview candidate. FUN should move point: if it moves point forward into the completion text, this function inserts the prefix of the completion candidate up to that point. Beyond moving point, FUN should not modify the current buffer.
Source Code
;; Defined in /usr/src/emacs/lisp/completion-preview.el.gz
(defun completion-preview-partial-insert (fun &rest args)
"Insert part of the current completion preview candidate.
This function calls FUN with arguments ARGS, after temporarily inserting
the entire current completion preview candidate. FUN should move point:
if it moves point forward into the completion text, this function
inserts the prefix of the completion candidate up to that point.
Beyond moving point, FUN should not modify the current buffer."
(completion-preview--barf-if-no-preview)
(let* ((end (completion-preview--get 'completion-preview-end))
(aft (completion-preview--get 'after-string))
(eoc (+ end (length aft))))
;; Keep region active, if it is already. This lets commands that
;; call this function interact correctly with `shift-select-mode'.
(let ((deactivate-mark nil))
;; Partially insert current completion candidate.
(catch 'abort-atomic-change
(atomic-change-group
(let ((change-group (prepare-change-group)))
(save-excursion
(goto-char end)
;; Temporarily insert the full completion candidate.
(insert-and-inherit (substring-no-properties aft)))
;; Set point to the end of the prefix that we want to keep.
(apply fun args)
(unless (< end (point))
;; Point didn't advance into the completion, so abort change
;; to avoid littering `buffer-undo-list' with a nop entry.
(throw 'abort-atomic-change nil))
;; Delete the rest.
(delete-region (min (point) eoc) eoc)
;; Combine into one change group.
(undo-amalgamate-change-group change-group)))))
;; Cleanup.
(cond
;; If we kept the entire completion candidate, call :exit-function.
((<= eoc (point))
(let* ((pre (completion-preview--get 'completion-preview-base))
(ind (completion-preview--get 'completion-preview-index))
(all (completion-preview--get 'completion-preview-suffixes))
(com (completion-preview--get 'completion-preview-common))
(efn (plist-get
(completion-preview--get 'completion-preview-props)
:exit-function)))
(completion-preview-active-mode -1)
(when (functionp efn) (funcall efn (concat pre com (nth ind all))
'finished))))
;; If we kept anything, update preview overlay accordingly.
((< end (point))
(completion-preview--inhibit-update)
(overlay-put (completion-preview--make-overlay
(point)
(completion-preview--propertize-for-mouse
(substring aft (- (point) end))))
'completion-preview-end (point)))
;; If we kept nothing, do nothing.
)))