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