[Top][All Lists]

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

RE: Mix of completing-read and read-string

From: Drew Adams
Subject: RE: Mix of completing-read and read-string
Date: Sat, 7 Feb 2009 20:09:16 -0800

> 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]