completing-read-multiple: Implement on top of completing-read

Avoid code duplication during minibuffer setup.

* lisp/emacs-lisp/crm.el (completing-read-multiple): Call
`completing-read' instead of duplicating the setup code of
`completing-read-default'.
This commit is contained in:
Daniel Mendler 2026-01-31 10:13:02 +01:00 committed by Stefan Monnier
parent 7fd6fa4a8b
commit c86094057b

View file

@ -255,14 +255,11 @@ with empty strings removed."
crm-local-must-match-map
crm-local-completion-map))
(map (minibuffer-visible-completions--maybe-compose-map map))
(buffer (current-buffer))
input)
(minibuffer-with-setup-hook
(lambda ()
(add-hook 'choose-completion-string-functions
'crm--choose-completion-string nil 'local)
(setq-local minibuffer-completion-table #'crm--collection-fn)
(setq-local minibuffer-completion-predicate predicate)
(setq-local completion-list-insert-choice-function
(lambda (_start _end choice)
(let* ((beg (save-excursion
@ -276,14 +273,9 @@ with empty strings removed."
(1- (point))
(point-max)))))
(completion--replace beg end choice))))
;; see completing_read in src/minibuf.c
(setq-local minibuffer-completion-confirm
(unless (eq require-match t) require-match))
(setq-local minibuffer--require-match require-match)
(setq-local minibuffer--original-buffer buffer)
(setq-local crm-completion-table table)
(completions--start-eager-display))
(setq input (read-from-minibuffer
(use-local-map map))
(setq input (completing-read
(format-spec
crm-prompt
(let* ((sep (or (get-text-property 0 'separator crm-separator)
@ -291,11 +283,8 @@ with empty strings removed."
(desc (or (get-text-property 0 'description crm-separator)
(concat "list separated by " sep))))
`((?s . ,sep) (?d . ,desc) (?p . ,prompt))))
initial-input map nil hist def inherit-input-method)))
;; If the user enters empty input, `read-from-minibuffer'
;; returns the empty string, not DEF.
(when (and def (string-equal input ""))
(setq input (if (consp def) (car def) def)))
#'crm--collection-fn predicate
require-match initial-input hist def inherit-input-method)))
;; Remove empty strings in the list of read strings.
(split-string input crm-separator t)))