help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to read an integer from the minibuffer


From: Emanuel Berg
Subject: Re: How to read an integer from the minibuffer
Date: Thu, 11 Nov 2021 11:28:55 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux)

Gregory Heytings wrote:

> (defun restricted-read-from-minibuffer (prompt allowed-chars)
>   "Read a string from the minibuffer, prompting with PROMPT.
> The only allowed characters are those in the string ALLOWED-CHARS."
>   (let ((m (make-keymap)))
>     (define-key m [t] #'ignore)
>     (define-key m (kbd "RET") #'exit-minibuffer)
>     (define-key m (kbd "<return>") #'exit-minibuffer)
>     (define-key m (kbd "C-j") #'exit-minibuffer)
>     (define-key m (kbd "C-g") #'abort-minibuffers)
>     (dolist (c (split-string allowed-chars "" t))
>       (define-key m c #'self-insert-command))
>     (read-from-minibuffer prompt nil m)))

(read-number "try input a string instead: ")

-- 
underground experts united
https://dataswamp.org/~incal




reply via email to

[Prev in Thread] Current Thread [Next in Thread]