Function: completion--twq-all
completion--twq-all is a byte-compiled function defined in
minibuffer.el.gz.
Signature
(completion--twq-all STRING USTRING COMPLETIONS BOUNDARY UNQUOTE REQUOTE)
Source Code
;; Defined in /usr/src/emacs/lisp/minibuffer.el.gz
(defun completion--twq-all (string ustring completions boundary
_unquote requote)
(when completions
(pcase-let*
((prefix
(let ((completion-regexp-list nil))
(try-completion "" (cons (substring ustring boundary)
completions))))
(`(,qfullpos . ,qfun)
(funcall requote (+ boundary (length prefix)) string))
(qfullprefix (substring string 0 qfullpos))
;; FIXME: This assertion can be wrong, e.g. in Cygwin, where
;; (unquote "c:\bin") => "/usr/bin" but (unquote "c:\") => "/".
;;(cl-assert (string-equal-ignore-case
;; (funcall unquote qfullprefix)
;; (concat (substring ustring 0 boundary) prefix))
;; t))
(qboundary (car (funcall requote boundary string)))
(_ (cl-assert (<= qboundary qfullpos)))
;; FIXME: this split/quote/concat business messes up the carefully
;; placed completions-common-part and completions-first-difference
;; faces. We could try within the mapcar loop to search for the
;; boundaries of those faces, pass them to `requote' to find their
;; equivalent positions in the quoted output and re-add the faces:
;; this might actually lead to correct results but would be
;; pretty expensive.
;; The better solution is to not quote the *Completions* display,
;; which nicely circumvents the problem. The solution I used here
;; instead is to hope that `qfun' preserves the text-properties and
;; presume that the `first-difference' is not within the `prefix';
;; this presumption is not always true, but at least in practice it is
;; true in most cases.
(qprefix (propertize (substring qfullprefix qboundary)
'face 'completions-common-part)))
;; Here we choose to quote all elements returned, but a better option
;; would be to return unquoted elements together with a function to
;; requote them, so that *Completions* can show nicer unquoted values
;; which only get quoted when needed by choose-completion.
(nconc
(mapcar (lambda (completion)
(cl-assert (string-prefix-p prefix completion 'ignore-case) t)
(let* ((new (substring completion (length prefix)))
(qnew (funcall qfun new))
(qprefix
(if (not completion-ignore-case)
qprefix
;; Make qprefix inherit the case from `completion'.
(let* ((rest (substring completion
0 (length prefix)))
(qrest (funcall qfun rest)))
(if (string-equal-ignore-case qprefix qrest)
(propertize qrest 'face
'completions-common-part)
qprefix))))
(qcompletion (concat qprefix qnew)))
;; Some completion tables (including this one) pass
;; along necessary information as text properties
;; on the first character of the completion. Make
;; sure the quoted completion has these properties
;; too.
(add-text-properties 0 1 (text-properties-at 0 completion)
qcompletion)
;; Attach unquoted completion string, which is needed
;; to score the completion in `completion--flex-score'.
(put-text-property 0 1 'completion--unquoted
completion qcompletion)
;; FIXME: Similarly here, Cygwin's mapping trips this
;; assertion.
;;(cl-assert
;; (string-equal-ignore-case
;; (funcall unquote
;; (concat (substring string 0 qboundary)
;; qcompletion))
;; (concat (substring ustring 0 boundary)
;; completion))
;; t)
qcompletion))
completions)
qboundary))))