* Mix of completing-read and read-string
@ 2009-02-07 20:22 Johan Andersson
2009-02-08 4:09 ` Drew Adams
0 siblings, 1 reply; 7+ messages in thread
From: Johan Andersson @ 2009-02-07 20:22 UTC (permalink / raw)
To: help-gnu-emacs
[-- Attachment #1: Type: text/plain, Size: 227 bytes --]
Hi!
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?
Thanks!
[-- Attachment #2: Type: text/html, Size: 248 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
* RE: Mix of completing-read and read-string
2009-02-07 20:22 Mix of completing-read and read-string Johan Andersson
@ 2009-02-08 4:09 ` Drew Adams
2009-02-08 9:49 ` Johan Andersson
2009-02-08 16:07 ` Kevin Rodgers
0 siblings, 2 replies; 7+ messages in thread
From: Drew Adams @ 2009-02-08 4:09 UTC (permalink / raw)
To: 'Johan Andersson', help-gnu-emacs
> 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.)
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Mix of completing-read and read-string
2009-02-08 4:09 ` Drew Adams
@ 2009-02-08 9:49 ` Johan Andersson
2009-02-08 16:07 ` Kevin Rodgers
1 sibling, 0 replies; 7+ messages in thread
From: Johan Andersson @ 2009-02-08 9:49 UTC (permalink / raw)
To: Drew Adams; +Cc: help-gnu-emacs
[-- Attachment #1: Type: text/plain, Size: 1482 bytes --]
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.)
>
>
[-- Attachment #2: Type: text/html, Size: 2302 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Mix of completing-read and read-string
2009-02-08 4:09 ` Drew Adams
2009-02-08 9:49 ` Johan Andersson
@ 2009-02-08 16:07 ` Kevin Rodgers
2009-02-08 18:44 ` Drew Adams
1 sibling, 1 reply; 7+ messages in thread
From: Kevin Rodgers @ 2009-02-08 16:07 UTC (permalink / raw)
To: help-gnu-emacs
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))
(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
^ permalink raw reply [flat|nested] 7+ messages in thread
* RE: Mix of completing-read and read-string
2009-02-08 16:07 ` Kevin Rodgers
@ 2009-02-08 18:44 ` Drew Adams
2009-02-08 19:32 ` Kevin Rodgers
0 siblings, 1 reply; 7+ messages in thread
From: Drew Adams @ 2009-02-08 18:44 UTC (permalink / raw)
To: 'Kevin Rodgers', help-gnu-emacs
> > (let ((minibuffer-local-completion-map
> > minibuffer-local-completion-map))
>
> (copy-keymap minibuffer-local-completion-map) would be safer, eh?
Yes. In case of error or quitting (`C-g') during completion, that will prevent
possibly leaving behind a SPC binding as `self-insert-command'.
(let ((minibuffer-local-completion-map
(copy-keymap minibuffer-local-completion-map)))
...
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Mix of completing-read and read-string
2009-02-08 18:44 ` Drew Adams
@ 2009-02-08 19:32 ` Kevin Rodgers
2009-02-17 16:51 ` Drew Adams
0 siblings, 1 reply; 7+ messages in thread
From: Kevin Rodgers @ 2009-02-08 19:32 UTC (permalink / raw)
To: help-gnu-emacs
Drew Adams wrote:
>>> (let ((minibuffer-local-completion-map
>>> minibuffer-local-completion-map))
>> (copy-keymap minibuffer-local-completion-map) would be safer, eh?
>
> Yes. In case of error or quitting (`C-g') during completion, that will prevent
> possibly leaving behind a SPC binding as `self-insert-command'.
>
> (let ((minibuffer-local-completion-map
> (copy-keymap minibuffer-local-completion-map)))
> ...
Actually, I was considering the possibility that define-key would
destructively modify the keymap:
(define-key minibuffer-local-completion-map
" " 'self-insert-command)
It doesn't happen in emacs -Q, but if SPC were already bound or
minibuffer-local-completion-map were a full keymap...
--
Kevin Rodgers
Denver, Colorado, USA
^ permalink raw reply [flat|nested] 7+ messages in thread
* RE: Mix of completing-read and read-string
2009-02-08 19:32 ` Kevin Rodgers
@ 2009-02-17 16:51 ` Drew Adams
0 siblings, 0 replies; 7+ messages in thread
From: Drew Adams @ 2009-02-17 16:51 UTC (permalink / raw)
To: 'Kevin Rodgers', help-gnu-emacs,
'Johan Andersson'
>> (let ((minibuffer-local-completion-map
>> minibuffer-local-completion-map))
>
> (copy-keymap minibuffer-local-completion-map) would be safer, eh?
This is probably the best approach; it is used in Emacs sources:
(let ((minibuffer-local-completion-map
(let ((map (make-sparse-keymap)))
(set-keymap-parent map minibuffer-local-completion-map)
(define-key map " " 'self-insert-command)
(define-key map "?" 'self-insert-command)
map)))
(completing-read ...))
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2009-02-17 16:51 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-02-07 20:22 Mix of completing-read and read-string Johan Andersson
2009-02-08 4:09 ` Drew Adams
2009-02-08 9:49 ` Johan Andersson
2009-02-08 16:07 ` Kevin Rodgers
2009-02-08 18:44 ` Drew Adams
2009-02-08 19:32 ` Kevin Rodgers
2009-02-17 16:51 ` Drew Adams
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).