help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: a function more than interactive..


From: jdx2172
Subject: Re: a function more than interactive..
Date: Wed, 08 Dec 2010 15:07:55 -0000
User-agent: G2/1.0

On May 11, 11:22 am, p...@informatimago.com (Pascal J. Bourguignon)
wrote:
> jdx2172 <dj9...@gmail.com> writes:
> > [Dont know what to call this functionality in emacs.. hence the
> > subject "more than interactive..."]
>
> > How do I write a function that when executed prompts the user to enter
> > a value at a prompt, asks another value and so on.. until all the
> > arguments are provided returns a result.
>
> As mentionned by Alan, interactive does it:
>
> (defun my-interactive-command (str num sym buf fil exp)
>   (interactive "sGime a string:
> nGime a number:
> SGime a symbol:
> bGime a buffer:
> fGime a file:
> xGime an expression: ")
>   (message "Got %S" (list str num sym buf fil exp)))
>
> But perhaps you really want command that is even more interactive than
> that?  Then you can use read-from-minibuffer:
>
> (defun my-more-than-interactive-command ()
>   (interactive)
>   (message "Got %S" (list (read-from-minibuffer "Gime a string: ")
>                           (parse-number (read-from-minibuffer "Gime a number: 
> "))
>                           (read-from-string (read-from-minibuffer "Gime a 
> symbol: "))
>                           ; ...
>                           )))
>
> But read-from-minibuffer is harder to use than interactive, you will
> have to validate and convert the data yourself.  On the other hand, it
> allow you to get user interaction in the middle of your command.
>
> --
> __Pascal Bourguignon__http://www.informatimago.com

Thank you so much.
Very good explanations.


reply via email to

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