[Top][All Lists]

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

Re: Mix of completing-read and read-string

From: Kevin Rodgers
Subject: Re: Mix of completing-read and read-string
Date: Sun, 08 Feb 2009 09:07:13 -0700
User-agent: Thunderbird (Macintosh/20081209)

Drew Adams 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

(copy-keymap minibuffer-local-completion-map) would be safer, eh?

    (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.)

Kevin Rodgers
Denver, Colorado, USA

reply via email to

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