[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: elisp - only accepting input of known values
From: |
Pascal J. Bourguignon |
Subject: |
Re: elisp - only accepting input of known values |
Date: |
Wed, 01 Dec 2010 15:17:44 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux) |
Gary <help-gnu-emacs@garydjones.name> writes:
> Is it somehow possible to accept input from a set of known values (and
> only those values), possibly based on regex but I'm not married to that
> idea?
Yes, with completing-read, you can define the valid inputs.
For example:
(defun get-fruit-list () '(apple banana orange))
(let ((fruit nil))
(list
(completing-read
"Fruit: "
(mapcar (lambda (x) (cons x nil)) (get-fruit-list)) ; collection
(lambda (selection) (setq fruit (car selection))) ; predicate
t ; require-match!
)
fruit))
--> ("orange" orange)
--
__Pascal Bourguignon__ http://www.informatimago.com/
A bad day in () is better than a good day in {}.
- Re: elisp - only accepting input of known values,
Pascal J. Bourguignon <=