* interact with user
@ 2008-11-26 13:39 Xend
2008-11-26 13:46 ` Xah Lee
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Xend @ 2008-11-26 13:39 UTC (permalink / raw
To: help-gnu-emacs
how can i get input from user (interact with user)in function with GNU/
emacs,the function interactive only work to parse arguments. are there
bulitin emacs function or i should programming to do it?
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: interact with user
2008-11-26 13:39 interact with user Xend
@ 2008-11-26 13:46 ` Xah Lee
2008-11-28 2:23 ` Xend
2008-11-26 15:25 ` Drew Adams
[not found] ` <mailman.1294.1227713142.26697.help-gnu-emacs@gnu.org>
2 siblings, 1 reply; 5+ messages in thread
From: Xah Lee @ 2008-11-26 13:46 UTC (permalink / raw
To: help-gnu-emacs
On Nov 26, 5:39 am, Xend <firperf...@gmail.com> wrote:
> how can i get input from user (interact with user)in function with GNU/
> emacs,the function interactive only work to parse arguments. are there
> bulitin emacs function or i should programming to do it?
btw, The “interactive” function has a general form like this:
“(interactive lispExp)”, where in the lispExp is any lisp code, among
which you can use any lisp function that query user. The return value
of lispExp becomes the argument of your command.
more answer here:
• Emacs Lisp Idioms
http://xahlee.org/emacs/elisp_idioms.html
here's relevant excerpt:
----------------------------------------
Prompting User for Input
Get User Input as Arguments
Idiom for promping user for input as the argument to your command.
Use this code “(interactive "‹code›‹promp string›")”. Example:
(defun query-friends-phone (name)
"..."
(interactive "sEnter friend's name: ")
(message "Name: %s" name)
)
What the “(interactive "sEnter friend's name:")” does is that it will
ask user to input something, taken as string, and becomes the value of
your command's parameter.
The “interactive” can be used to get other types of input. Here are
some basic examples of using “interactive”.
* “(interactive)” makes the function available thru interactive
use, where user can call it with execute-extended-command (M-x).
* “(interactive "s")” will prompt user for input, taken as string,
as argument to the function.
* “(interactive "n")” will prompt user for input, taken as number,
as argument to the function.
The prompt text can follow the single-letter code string.
If your function takes multiple inputs, you can promp user multiple
times, using a single call “interactive”, by joining the promp code
string with “\n” in between, like this:
(defun query-friends-phone (name age)
"..."
(interactive "sEnter friend's name: \nnEnter friend's age: ")
(message "Name: %s, Age: %d" name age)
)
(info "(elisp)Defining Commands")
Query For User Input
The “(interactive ...)” clause is useful for filling parameters of
your command. But sometimes you need to promp user in the middle of a
program. For example: “Make change to this file?”. You can use “y-or-n-
p” function. Like this:
(if (y-or-n-p "Do it?")
(progn
;; code to do something here
)
(progn
;; code if user answered no.
)
)
The y-or-n-p will ask the user to type a “y” or “n” character. You can
also use “yes-and-no-p”, which forces user to type full “yes” and “no”
to answer. This can be used for example when you want to confirm
deleting files.
Yes-or-No-Queries
If you need more general mechanism for getting user input, you'll need
to use “read-from-minibuffer”. This can be useful for example, when
you want use features like keyword completion or input history.
(info "(elisp)Text from Minibuffer")
Xah
∑ http://xahlee.org/
☄
^ permalink raw reply [flat|nested] 5+ messages in thread
* RE: interact with user
2008-11-26 13:39 interact with user Xend
2008-11-26 13:46 ` Xah Lee
@ 2008-11-26 15:25 ` Drew Adams
[not found] ` <mailman.1294.1227713142.26697.help-gnu-emacs@gnu.org>
2 siblings, 0 replies; 5+ messages in thread
From: Drew Adams @ 2008-11-26 15:25 UTC (permalink / raw
To: 'Xend', help-gnu-emacs
> how can i get input from user (interact with user)in function
> with GNU/emacs,the function interactive only work to parse
> arguments. are there bulitin emacs function or i should
> programming to do it?
Do you mean that you want to ask the user for input and show output to the user?
If so then see the Elisp manual, nodes `Text from Minibuffer' and `Minibuffer
Completion', for reading input. You can use a function such as `completing-read'
or `read-from-minibuffer'.
To show output, you can use function `message' or fill a buffer with the output
and use `display-buffer' or `pop-to-buffer'. See also
`with-output-to-temp-buffer.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: interact with user
[not found] ` <mailman.1294.1227713142.26697.help-gnu-emacs@gnu.org>
@ 2008-11-28 2:22 ` Xend
0 siblings, 0 replies; 5+ messages in thread
From: Xend @ 2008-11-28 2:22 UTC (permalink / raw
To: help-gnu-emacs
On Nov 26, 11:25 pm, "Drew Adams" <drew.ad...@oracle.com> wrote:
> > how can i get input from user (interact with user)in function
> > with GNU/emacs,the function interactive only work to parse
> > arguments. are there bulitin emacs function or i should
> > programming to do it?
>
> Do you mean that you want to ask the user for input and show output to the user?
>
> If so then see the Elisp manual, nodes `Text from Minibuffer' and `Minibuffer
> Completion', for reading input. You can use a function such as `completing-read'
> or `read-from-minibuffer'.
>
> To show output, you can use function `message' or fill a buffer with the output
> and use `display-buffer' or `pop-to-buffer'. See also
> `with-output-to-temp-buffer.
thanks men
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: interact with user
2008-11-26 13:46 ` Xah Lee
@ 2008-11-28 2:23 ` Xend
0 siblings, 0 replies; 5+ messages in thread
From: Xend @ 2008-11-28 2:23 UTC (permalink / raw
To: help-gnu-emacs
On Nov 26, 9:46 pm, Xah Lee <xah...@gmail.com> wrote:
> On Nov 26, 5:39 am, Xend <firperf...@gmail.com> wrote:
>
> > how can i get input from user (interact with user)in function with GNU/
> > emacs,the function interactive only work to parse arguments. are there
> > bulitin emacs function or i should programming to do it?
>
> btw, The “interactive” function has a general form like this:
> “(interactive lispExp)”, where in the lispExp is any lisp code, among
> which you can use any lisp function that query user. The return value
> of lispExp becomes the argument of your command.
>
> more answer here:
>
> • Emacs Lisp Idioms
> http://xahlee.org/emacs/elisp_idioms.html
>
> here's relevant excerpt:
>
> ----------------------------------------
> Prompting User for Input
> Get User Input as Arguments
>
> Idiom for promping user for input as the argument to your command.
>
> Use this code “(interactive "‹code›‹promp string›")”. Example:
>
> (defun query-friends-phone (name)
> "..."
> (interactive "sEnter friend's name: ")
> (message "Name: %s" name)
> )
>
> What the “(interactive "sEnter friend's name:")” does is that it will
> ask user to input something, taken as string, and becomes the value of
> your command's parameter.
>
> The “interactive” can be used to get other types of input. Here are
> some basic examples of using “interactive”.
>
> * “(interactive)” makes the function available thru interactive
> use, where user can call it with execute-extended-command (M-x).
> * “(interactive "s")” will prompt user for input, taken as string,
> as argument to the function.
> * “(interactive "n")” will prompt user for input, taken as number,
> as argument to the function.
>
> The prompt text can follow the single-letter code string.
>
> If your function takes multiple inputs, you can promp user multiple
> times, using a single call “interactive”, by joining the promp code
> string with “\n” in between, like this:
>
> (defun query-friends-phone (name age)
> "..."
> (interactive "sEnter friend's name: \nnEnter friend's age: ")
> (message "Name: %s, Age: %d" name age)
> )
>
> (info "(elisp)Defining Commands")
> Query For User Input
>
> The “(interactive ...)” clause is useful for filling parameters of
> your command. But sometimes you need to promp user in the middle of a
> program. For example: “Make change to this file?”. You can use “y-or-n-
> p” function. Like this:
>
> (if (y-or-n-p "Do it?")
> (progn
> ;; code to do something here
> )
> (progn
> ;; code if user answered no.
> )
> )
>
> The y-or-n-p will ask the user to type a “y” or “n” character. You can
> also use “yes-and-no-p”, which forces user to type full “yes” and “no”
> to answer. This can be used for example when you want to confirm
> deleting files.
>
> Yes-or-No-Queries
>
> If you need more general mechanism for getting user input, you'll need
> to use “read-from-minibuffer”. This can be useful for example, when
> you want use features like keyword completion or input history.
>
> (info "(elisp)Text from Minibuffer")
>
> Xah
> ∑http://xahlee.org/
>
> ☄
thanks for your help.men
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2008-11-28 2:23 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-11-26 13:39 interact with user Xend
2008-11-26 13:46 ` Xah Lee
2008-11-28 2:23 ` Xend
2008-11-26 15:25 ` Drew Adams
[not found] ` <mailman.1294.1227713142.26697.help-gnu-emacs@gnu.org>
2008-11-28 2:22 ` Xend
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).