Function: magit-read-string
magit-read-string is a byte-compiled function defined in
magit-base.el.
Signature
(magit-read-string PROMPT &optional INITIAL-INPUT HISTORY DEFAULT-VALUE INHERIT-INPUT-METHOD NO-WHITESPACE)
Documentation
Read a string from the minibuffer, prompting with string PROMPT.
This is similar to read-string, but
* empty input is only allowed if DEFAULT-VALUE is non-nil in
which case that is returned,
* whitespace is not allowed and leading and trailing whitespace is
removed automatically if NO-WHITESPACE is non-nil,
* format-prompt is used internally.
* an invalid DEFAULT-VALUE is silently ignored.
Source Code
;; Defined in ~/.emacs.d/elpa/magit-20260411.1452/magit-base.el
(defun magit-read-string ( prompt &optional initial-input history default-value
inherit-input-method no-whitespace)
"Read a string from the minibuffer, prompting with string PROMPT.
This is similar to `read-string', but
* empty input is only allowed if DEFAULT-VALUE is non-nil in
which case that is returned,
* whitespace is not allowed and leading and trailing whitespace is
removed automatically if NO-WHITESPACE is non-nil,
* `format-prompt' is used internally.
* an invalid DEFAULT-VALUE is silently ignored."
(when default-value
(when (consp default-value)
(setq default-value (car default-value)))
(unless (stringp default-value)
(setq default-value nil)))
(let* ((minibuffer-completion-table nil)
(val (read-from-minibuffer
(format-prompt prompt default-value)
initial-input (and no-whitespace magit-minibuffer-local-ns-map)
nil history default-value inherit-input-method))
(trim (lambda (regexp string)
(save-match-data
(if (string-match regexp string)
(replace-match "" t t string)
string)))))
(when (and (string= val "") default-value)
(setq val default-value))
(when no-whitespace
(setq val (funcall trim "\\`\\(?:[ \t\n\r]+\\)"
(funcall trim "\\(?:[ \t\n\r]+\\)\\'" val))))
(cond ((string= val "")
(user-error "Need non-empty input"))
((and no-whitespace (string-match-p "[\s\t\n]" val))
(user-error "Input contains whitespace"))
(val))))