Function: read-multiple-choice--from-minibuffer

read-multiple-choice--from-minibuffer is a byte-compiled function defined in rmc.el.gz.

Signature

(read-multiple-choice--from-minibuffer PROMPT CHOICES HELP-STRING SHOW-HELP)

Source Code

;; Defined in /usr/src/emacs/lisp/emacs-lisp/rmc.el.gz
(defun read-multiple-choice--from-minibuffer (prompt choices help-string show-help)
  ;; Read short answers from the minibuffer.
  (let* ((prompt-choices
          (if show-help choices (append choices '((?? "?")))))
         (altered-names (mapcar #'rmc--add-key-description prompt-choices))
         (full-prompt
          (format
           "%s (%s): "
           prompt
           (mapconcat #'cdr altered-names ", ")))
         tchar buf
         (map (make-sparse-keymap))
         (cmd-char
          (lambda ()
            (interactive)
            (setq tchar last-command-event)
            (exit-minibuffer)))
         (cmd-help
          (lambda ()
            (interactive)
            (setq buf (rmc--show-help prompt help-string show-help
                                      choices altered-names))))
         (cmd-wrong
          (lambda ()
            (interactive)
            (ding)
            (setq buf (rmc--show-help prompt help-string show-help
                                      choices altered-names))
            (minibuffer-message "Invalid choice")
            (sit-for 2)))
         (this-command this-command)
         (real-this-command real-this-command)
         (enable-recursive-minibuffers t)
         (overriding-text-conversion-style nil))

    (unwind-protect
        (progn
          (when show-help
            (setq buf (rmc--show-help prompt help-string show-help
                                      choices altered-names)))

          (set-keymap-parent map minibuffer-local-map)
          (dolist (char choices)
            (define-key map `[,(car char)] cmd-char))
          (define-key map [help-char] cmd-help)
          (unless show-help (define-key map [??] cmd-help))
          (define-key map [remap self-insert-command] cmd-wrong)

          (when (fboundp 'set-text-conversion-style)
            (set-text-conversion-style text-conversion-style))
          (read-from-minibuffer full-prompt nil map))

      (when (buffer-live-p buf)
        (let ((kill-buffer-quit-windows t))
          (kill-buffer buf))))

    (assq tchar choices)))