From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Johan Andersson Newsgroups: gmane.emacs.help Subject: Re: Mix of completing-read and read-string Date: Sun, 8 Feb 2009 10:49:17 +0100 Message-ID: <929ccd880902080149r43dbad17h54bd3b31387d665a@mail.gmail.com> References: <929ccd880902071222o64e828e3h107f176ccb78592a@mail.gmail.com> <001201c989a3$02d61970$0200a8c0@us.oracle.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=0015174c34a2db7c2a0462652aa9 X-Trace: ger.gmane.org 1234086656 18608 80.91.229.12 (8 Feb 2009 09:50:56 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 8 Feb 2009 09:50:56 +0000 (UTC) Cc: help-gnu-emacs@gnu.org To: Drew Adams Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sun Feb 08 10:52:10 2009 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1LW6Jb-0005OA-OB for geh-help-gnu-emacs@m.gmane.org; Sun, 08 Feb 2009 10:51:04 +0100 Original-Received: from localhost ([127.0.0.1]:36307 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LW6II-0006lI-8K for geh-help-gnu-emacs@m.gmane.org; Sun, 08 Feb 2009 04:49:42 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LW6Hw-0006lC-8q for help-gnu-emacs@gnu.org; Sun, 08 Feb 2009 04:49:20 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LW6Hv-0006l0-3i for help-gnu-emacs@gnu.org; Sun, 08 Feb 2009 04:49:19 -0500 Original-Received: from [199.232.76.173] (port=37584 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LW6Hu-0006kx-Tj for help-gnu-emacs@gnu.org; Sun, 08 Feb 2009 04:49:18 -0500 Original-Received: from ey-out-1920.google.com ([74.125.78.145]:7978) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1LW6Hu-0003NA-A2 for help-gnu-emacs@gnu.org; Sun, 08 Feb 2009 04:49:18 -0500 Original-Received: by ey-out-1920.google.com with SMTP id 4so192685eyg.24 for ; Sun, 08 Feb 2009 01:49:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:cc:content-type; bh=3wbSKa+V2Pgd5ZzND7jGumJU5LJ85DF4zEclcnMIljQ=; b=BNDGBpZ7nPLuO8HKCabzVvl15nWq+eVyl3a3cBG0XceYoTZXjZsRNwId2ig4boSYN4 lT5ko35fGx7gTqM3rQTHSiJZE48HQlivDsL3Gw6QwHnrt1pvwsnJeZ2GQrFWYEB+VDbM J74cRLFxqOLgXgtVYSTquYtwQHlGPhZEhhU1E= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; b=iXUCZ3LStObOlo6hXhZVsIhzZ6LeUudrkg5P+hfN3GHUjxQeXuW5uWIJHaenT7yOH2 zV7bvcg5ncO4DHh5RxJCS4EGxmCp6Zpyq/DBK/PKwtSwksAHzElUIiwkhjanh4VetmKn 8DOKNfMyrRPYzTwk//AFQPfo2yczfzJybO7FI= Original-Received: by 10.210.19.7 with SMTP id 7mr2886751ebs.145.1234086557088; Sun, 08 Feb 2009 01:49:17 -0800 (PST) In-Reply-To: <001201c989a3$02d61970$0200a8c0@us.oracle.com> X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 2) X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:61995 Archived-At: --0015174c34a2db7c2a0462652aa9 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Thanks a lot Drew. Exactly what I was looking for! On Sun, Feb 8, 2009 at 5:09 AM, 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 " " > 'self-insert-command). > > IOW, something like this: > > (defun my-read-string-completing (prompt collection > &optional predicate > init hist def i-i-m) > "..." > (let ((minibuffer-local-completion-map > 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.) > > --0015174c34a2db7c2a0462652aa9 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Thanks a lot Drew. Exactly what I was looking for!

On Sun, Feb 8, 2009 at 5:09 AM, Drew Adams <drew.adams@oracle.com> 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 " "
'self-insert-command).

IOW, something like this:

(defun my-read-string-completing (prompt collection
                                 &optional predicate
                                 init hist def i-i-m)
 "..."
 (let ((minibuffer-local-completion-map
        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.)


--0015174c34a2db7c2a0462652aa9--