[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Read another with M-RET
From: |
Nordlöw |
Subject: |
Re: Read another with M-RET |
Date: |
Wed, 08 Dec 2010 15:19:52 -0000 |
User-agent: |
G2/1.0 |
On Jul 21, 4:45 pm, TheFlyingDutchman <zzbba...@aol.com> wrote:
> On Jul 21, 4:25 am, Nordlöw <per.nord...@gmail.com> wrote:
>
>
>
>
>
> > How do I modify read-string-list so that RET ends loop a single read
> > and M-RET finishes current input and ask for another instead of the
> > logic given in the code below where RET finishes current and ask for
> > another and a final empty string (just RET) instead ends the loop?
>
> > Thanks in advance,
> > Nordlöw
>
> > Here's the code:
>
> > (defun read-string-list (&optional prompt uniquify)
> > "Construct a list of strings interactively from minibuffer.
> > An empty string (RET) terminates the read loop."
> > (interactive)
> > (let ((sl nil))
> > (let (str)
> > (while (not (equal
> > (setq str (read-string
> > (concat (or prompt
> > "String")
> > " (or RET to end list): ")))
> > ""))
> > (if uniquify
> > (add-to-list 'sl str t)
> > (setq sl (append sl `(,str))))
> > ))
> > sl))
>
> I think this does what you are asking for:
>
> (defun Return ()
> "exit minibuffer and stop loop in read-string-list2"
> (interactive)
> (setq keepLooping nil)
> (exit-minibuffer)
> )
>
> (defun read-string-list2 (&optional prompt uniquify)
> "Construct a list of strings interactively from minibuffer.
> <ALT-RETURN> to terminate all items except the last, which is
> ended with <RETURN>."
> (interactive)
> (define-key minibuffer-local-map (kbd "<M-return>") 'exit-
> minibuffer)
> (define-key minibuffer-local-map (kbd "<return>") 'Return)
> (let ((sl nil))
> (let (str)
> (setq keepLooping t)
> (while keepLooping
> (setq str (read-string
> (concat (or prompt
> "String")
> " (or RET to end list): ")))
>
> (if uniquify
> (add-to-list 'sl str t)
> (setq sl (append sl `(,str))))
> )
> (define-key minibuffer-local-map (kbd "<return>") 'exit-
> minibuffer)
> )
> (message "%s" sl)
> sl))
Thanks a lot.
/Per