[Top][All Lists]

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

Re: Mix of completing-read and read-string

From: Johan Andersson
Subject: Re: Mix of completing-read and read-string
Date: Sun, 8 Feb 2009 10:49:17 +0100

Thanks a lot Drew. Exactly what I was looking for!

On Sun, Feb 8, 2009 at 5:09 AM, Drew Adams <address@hidden> wrote:
> I'm looking for a function that is a mix of read-string
> and completing-read. I want completion and I want to be
> able to input anything, such as spaces. Is there any such
> function or do I have to write one myself?

1. Use lax completion (`completing-read' with nil as the REQUIRE-MATCH argument.

2. Use a keymap that has SPC bound to `self-insert-command'.

You can do #2 by binding `minibuffer-local-completion-map' (so it is restored
afterward), and doing (define-key minibuffer-local-completion-map " "

IOW, something like this:

(defun my-read-string-completing (prompt collection
                                 &optional predicate
                                 init hist def i-i-m)
 (let ((minibuffer-local-completion-map
   (define-key minibuffer-local-completion-map
               " " 'self-insert-command)
   (completing-read prompt collection
                    predicate nil init def hist i-i-m)))

You would call the function with a COLLECTION argument that is a list of strings
(Emacs 22+) or a list of singleton string lists (all versions). E.g.:

(my-read-string-completing "String: "
 '(("alpha") ("beta") ("gamma")))

(If you use Icicles, `icicle-read-string-completing' does this.)

reply via email to

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