Function: pcomplete-completions-at-point
pcomplete-completions-at-point is a byte-compiled function defined in
pcomplete.el.gz.
Signature
(pcomplete-completions-at-point)
Documentation
Provide standard completion using pcomplete's completion tables.
Same as pcomplete but using the standard completion UI.
Probably introduced at or before Emacs version 27.1.
Source Code
;; Defined in /usr/src/emacs/lisp/pcomplete.el.gz
(defun pcomplete-completions-at-point ()
"Provide standard completion using pcomplete's completion tables.
Same as `pcomplete' but using the standard completion UI."
;; FIXME: it only completes the text before point, whereas the
;; standard UI may also consider text after point.
;; FIXME: the `pcomplete' UI may be used internally during
;; pcomplete-completions and then throw to `pcompleted', thus
;; imposing the pcomplete UI over the standard UI.
(catch 'pcompleted
(let* ((pcomplete-stub)
(buffer-read-only
;; Make sure the function obeys `pcomplete-allow-modifications'.
(if pcomplete-allow-modifications buffer-read-only t))
pcomplete-seen pcomplete-norm-func
pcomplete-args pcomplete-last pcomplete-index
(pcomplete-autolist pcomplete-autolist)
(pcomplete-suffix-list pcomplete-suffix-list)
;; Apparently the vars above are global vars modified by
;; side-effects, whereas pcomplete-completions is the core
;; function that finds the chunk of text to complete
;; (returned indirectly in pcomplete-stub) and the set of
;; possible completions.
(completions (pcomplete-completions))
;; Usually there's some close connection between pcomplete-stub
;; and the text before point. But depending on what
;; pcomplete-parse-arguments-function does, that connection
;; might not be that close. E.g. in eshell,
;; pcomplete-parse-arguments-function expands envvars.
;;
;; Since we use minibuffer-complete, which doesn't know
;; pcomplete-stub and works from the buffer's text instead,
;; we need to trick minibuffer-complete, into using
;; pcomplete-stub without its knowledge. To that end, we
;; use completion-table-subvert to construct a completion
;; table which expects strings using a prefix from the
;; buffer's text but internally uses the corresponding
;; prefix from pcomplete-stub.
;;
(argbeg (pcomplete-begin))
;; When completing an envvar within an argument in Eshell
;; (e.g. "cd /home/$US TAB"), `pcomplete-stub' will just be
;; "US" whereas `argbeg' will point to the first "/".
;; We could rely on c-t-subvert to handle the difference,
;; but we try here to guess the "real" beginning so as to
;; rely less on c-t-subvert.
(beg (max (- (point) (length pcomplete-stub))
argbeg))
buftext)
;; Try and improve our guess of `beg' in case the difference
;; between pcomplete-stub and the buffer's text is simply due to
;; some chars removed by unquoting. Again, this is not
;; indispensable but reduces the reliance on c-t-subvert and
;; improves corner case behaviors.
(while (progn (setq buftext (pcomplete-unquote-argument
(buffer-substring beg (point))))
(and (> beg argbeg)
(> (length pcomplete-stub) (length buftext))))
(setq beg (max argbeg (- beg (- (length pcomplete-stub)
(length buftext))))))
(when completions
(let ((table
(completion-table-with-quoting
(if (equal pcomplete-stub buftext)
completions
;; This may not always be strictly right, but given the lack
;; of any other info, it's about as good as it gets, and in
;; practice it should work just fine (fingers crossed).
(let ((suf-len (pcomplete--common-suffix
pcomplete-stub buftext)))
(completion-table-subvert
completions
(substring buftext 0 (- (length buftext) suf-len))
(substring pcomplete-stub 0
(- (length pcomplete-stub) suf-len)))))
pcomplete-unquote-argument-function
pcomplete-requote-argument-function))
(pred
;; Pare it down, if applicable.
(when (and pcomplete-use-paring pcomplete-seen)
;; Capture the dynbound values for later use.
(let ((norm-func pcomplete-norm-func)
(seen
(mapcar (lambda (f)
(funcall pcomplete-norm-func
(directory-file-name f)))
pcomplete-seen)))
(lambda (f)
(not (member
(funcall norm-func (directory-file-name f))
seen)))))))
(when completion-ignore-case
(setq table (completion-table-case-fold table)))
(list beg (point) table
:annotation-function
(lambda (cand)
(when (stringp cand)
(get-text-property 0 'pcomplete-annotation cand)))
:company-docsig
(lambda (cand)
(when (stringp cand)
(get-text-property 0 'pcomplete-help cand)))
:predicate pred
:exit-function
;; If completion is finished, add a terminating space.
;; We used to also do this if STATUS is `sole', but
;; that does not work right when completion cycling.
(unless (zerop (length pcomplete-termination-string))
(lambda (_s status)
(when (eq status 'finished)
(if (looking-at
(regexp-quote pcomplete-termination-string))
(goto-char (match-end 0))
(insert pcomplete-termination-string)))))))))))