@code{completion-local-styles}. @xref{Completion Variables}.
@end deffn
-@defun display-completion-list completions
+@defun display-completion-list completions group-fun
This function displays @var{completions} to the stream in
@code{standard-output}, usually a buffer. (@xref{Read and Print}, for more
information about streams.) The argument @var{completions} is normally
the two strings is the actual completion, the second string serves as
annotation.
+The optional argument @var{group-fun} is a completions grouping
+function, @ref{Completions grouping function}.
+
This function is called by @code{minibuffer-completion-help}. A
common way to use it is together with
@code{with-output-to-temp-buffer}, like this:
takes priority over @code{annotation-function}.
@cindex @code{group-function}, in completion
+@anchor{Completions grouping function}
@item group-function
The value should be a function for grouping the completion candidates.
The function must take two arguments, @var{completion}, which is a
"Insert a list of STRINGS into the current buffer.
The candidate strings are inserted into the buffer depending on the
completions format as specified by the variable `completions-format'.
-Runs of equal candidate strings are eliminated. GROUP-FUN is a
-`group-function' used for grouping the completion candidates."
+Runs of equal candidate strings are eliminated.
+
+Optional argument GROUP-FUN, if non-nil, is a completions grouping
+function as described in the documentation of `completion-metadata'."
(when (consp strings)
(let* ((length (apply #'max
(mapcar (lambda (s)
:version "30.1"
:type 'boolean)
-(defun display-completion-list (completions &optional common-substring group-fun)
+(defun display-completion-list (completions &optional group-fun)
"Display the list of completions, COMPLETIONS, using `standard-output'.
Each element may be just a symbol or string
or may be a list of two strings to be printed as if concatenated.
properties of `highlight'.
At the end, this runs the normal hook `completion-setup-hook'.
It can find the completion buffer in `standard-output'.
-GROUP-FUN is a `group-function' used for grouping the completion
-candidates."
- (declare (advertised-calling-convention (completions) "24.4"))
- (if common-substring
- (setq completions (completion-hilit-commonality
- completions (length common-substring)
- ;; We don't know the base-size.
- nil)))
- (if (not (bufferp standard-output))
- ;; This *never* (ever) happens, so there's no point trying to be clever.
- (with-temp-buffer
- (let ((standard-output (current-buffer))
- (completion-setup-hook nil))
- (with-suppressed-warnings ((callargs display-completion-list))
- (display-completion-list completions common-substring group-fun)))
- (princ (buffer-string)))
- (let ((pred-desc
- (if-let ((pd (minibuffer--completion-predicate-description)))
- (concat ", " pd)
- ""))
- (sort-desc
- (if minibuffer-completions-sort-function
- (concat
- (when-let
- ((sd (nth 4 (seq-find
- (lambda (order)
- (eq
- (nth 3 order)
- (advice--cd*r
- minibuffer-completions-sort-function)))
- minibuffer-completions-sort-orders))))
- (concat ", " sd))
- (when (advice-function-member-p
- #'reverse minibuffer-completions-sort-function)
- ", reversed"))
- ""))
- (cat (if completion-category (format " %s" completion-category) "")))
- (with-current-buffer standard-output
- (goto-char (point-max))
- (if completions-header-format
- (let ((heading
- (format-spec completions-header-format
- (list (cons ?s (length completions))
- (cons ?t sort-desc)
- (cons ?r pred-desc)
- (cons ?c cat)))))
- (add-face-text-property
- 0 (length heading) 'completions-heading t heading)
- (insert heading))
- (unless completion-show-help
- ;; Ensure beginning-of-buffer isn't a completion.
- (insert (propertize "\n" 'face '(:height 0)))))
- (completion--insert-strings completions group-fun))))
+
+Optional argument GROUP-FUN, if non-nil, is a completions grouping
+function as described in the documentation of `completion-metadata'."
+ (let ((pred-desc
+ (if-let ((pd (minibuffer--completion-predicate-description)))
+ (concat ", " pd)
+ ""))
+ (sort-desc
+ (if minibuffer-completions-sort-function
+ (concat
+ (when-let
+ ((sd (nth 4 (seq-find
+ (lambda (order)
+ (eq
+ (nth 3 order)
+ (advice--cd*r
+ minibuffer-completions-sort-function)))
+ minibuffer-completions-sort-orders))))
+ (concat ", " sd))
+ (when (advice-function-member-p
+ #'reverse minibuffer-completions-sort-function)
+ ", reversed"))
+ ""))
+ (cat (if completion-category (format " %s" completion-category) "")))
+ (with-current-buffer standard-output
+ (goto-char (point-max))
+ (if completions-header-format
+ (let ((heading
+ (format-spec completions-header-format
+ (list (cons ?s (length completions))
+ (cons ?t sort-desc)
+ (cons ?r pred-desc)
+ (cons ?c cat)))))
+ (add-face-text-property
+ 0 (length heading) 'completions-heading t heading)
+ (insert heading))
+ (unless completion-show-help
+ ;; Ensure beginning-of-buffer isn't a completion.
+ (insert (propertize "\n" 'face '(:height 0)))))
+ (completion--insert-strings completions group-fun)))
(run-hooks 'completion-setup-hook)
nil)
(if (eq (car bounds) (length result))
'exact 'finished)))))))
- (display-completion-list completions nil group-fun)))))
+ (display-completion-list completions group-fun)))))
nil)))
nil))