Function: hargs:read-match

hargs:read-match is a byte-compiled function defined in hargs.el.

Signature

(hargs:read-match PROMPT COLLECTION &optional PREDICATE MUST-MATCH INITIAL-INPUT VAL-TYPE)

Documentation

PROMPT with completion for a value in COLLECTION and return it.

COLLECTION may be a list of strings, an alist, an obarray (for symbol-name completion) or a hash collection. COLLECTION may also be a function to do the completion itself. Optional PREDICATE limits completion to a subset of COLLECTION. Optional MUST-MATCH means value returned must be from COLLECTION and not blank (unless INITIAL-INPUT is given as an empty string). Optional INITIAL-INPUT is a string inserted after PROMPT as the default value. Optional VAL-TYPE is a symbol indicating the type of value to be read.

Source Code

;; Defined in ~/.emacs.d/elpa/hyperbole-20260414.325/hargs.el
(defun hargs:read-match (prompt collection
			 &optional predicate must-match initial-input val-type)
  "PROMPT with completion for a value in COLLECTION and return it.
COLLECTION may be a list of strings, an alist, an obarray (for
`symbol-name' completion) or a hash collection.  COLLECTION may
also be a function to do the completion itself.  Optional
PREDICATE limits completion to a subset of COLLECTION.  Optional
MUST-MATCH means value returned must be from COLLECTION and not
blank (unless INITIAL-INPUT is given as an empty string).
Optional INITIAL-INPUT is a string inserted after PROMPT as the
default value.  Optional VAL-TYPE is a symbol indicating the type
of value to be read."
  (unless (and must-match (null collection))
    (let ((prev-reading-p hargs:reading-type)
	  (completion-ignore-case t)
	  (owind (selected-window))
	  (obuf (current-buffer))
	  result)
      (unwind-protect
	  (progn
	    (setq hargs:reading-type (or val-type t))
	    (while (null result)
	      (setq result (completing-read prompt collection predicate must-match initial-input))
	      (when (and must-match (stringp result) (string-blank-p result)
			 (not (equal initial-input "")))
		(setq result initial-input)
		(when (not initial-input)
		  (beep))))
	    result)
	(setq hargs:reading-type prev-reading-p)
	(when (window-live-p owind)
	  (select-window owind)
	  (switch-to-buffer obuf))))))