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

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

Re: elisp - only accepting input of known values


From: Richard Riley
Subject: Re: elisp - only accepting input of known values
Date: Wed, 01 Dec 2010 16:52:37 +0100
User-agent: Gnus/5.110011 (No Gnus v0.11) Emacs/23.2 (gnu/linux)

Tyler Smith <tyler.smith@eku.edu> writes:

> Gary <help-gnu-emacs@garydjones.name> writes:
>
>> Tassilo Horn wrote:
>>> Gary 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?
>>>
>>> What exactly do you mean with "input"?  Input to what?  A function?
>>
>> User input.
>
> completing-read does this. The info file is here:
>
> (info "(elisp)Minibuffer Completion")
>
> The help reads, in part:
>
> completing-read is a built-in function in `C source code'.
>
> (completing-read PROMPT COLLECTION &optional PREDICATE REQUIRE-MATCH
> INITIAL-INPUT HIST DEF INHERIT-INPUT-METHOD)
>
> Read a string in the minibuffer, with completion.
> PROMPT is a string to prompt with; normally it ends in a colon and a space.
> COLLECTION can be a list of strings, an alist, an obarray or a hash table.
> COLLECTION can also be a function to do the completion itself.
> PREDICATE limits completion to a subset of COLLECTION.
> See `try-completion' and `all-completions' for more details
>  on completion, COLLECTION, and PREDICATE.
>
> Tyler
>

And here is an example using ido completing read

--8<---------------cut here---------------start------------->8---
  ; IDO switch between irc channels.
  (defun rgr/ido-erc-buffer()
    (interactive)
    (switch-to-buffer
     (ido-completing-read "Channel:"
                          (save-excursion
                            (delq
                             nil
                             (mapcar (lambda (buf)
                                       (when (buffer-live-p buf)
                                         (with-current-buffer buf
                                           (and (eq major-mode 'erc-mode)
                                                (buffer-name buf)))))
                                     (buffer-list)))))))

  (eval-after-load 'erc '(global-set-key (kbd "C-c e") 'rgr/ido-erc-buffer))
--8<---------------cut here---------------end--------------->8---



reply via email to

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