unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* a function more than interactive..
@ 2010-05-11 13:11 jdx2172
  2010-05-11 13:46 ` Alan Mackenzie
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: jdx2172 @ 2010-05-11 13:11 UTC (permalink / raw)
  To: help-gnu-emacs

[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.





^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: a function more than interactive..
  2010-05-11 13:11 a function more than interactive jdx2172
@ 2010-05-11 13:46 ` Alan Mackenzie
       [not found] ` <lztyqejwer.fsf@informatimago.com>
  2010-05-11 22:57 ` Tim X
  2 siblings, 0 replies; 5+ messages in thread
From: Alan Mackenzie @ 2010-05-11 13:46 UTC (permalink / raw)
  To: help-gnu-emacs

jdx2172 <dj9027@gmail.com> wrote:
> [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.

If you're prompting the user at the start of the command, use
`interactive'.  It has lots of rarely used argument types, which together
will probably do what you want.  "C-h f interactive" is your friend.

-- 
Alan Mackenzie (Nuremberg, Germany).



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: a function more than interactive..
       [not found] ` <lztyqejwer.fsf@informatimago.com>
@ 2010-05-11 15:57   ` jdx2172
  0 siblings, 0 replies; 5+ messages in thread
From: jdx2172 @ 2010-05-11 15:57 UTC (permalink / raw)
  To: help-gnu-emacs

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.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: a function more than interactive..
  2010-05-11 13:11 a function more than interactive jdx2172
  2010-05-11 13:46 ` Alan Mackenzie
       [not found] ` <lztyqejwer.fsf@informatimago.com>
@ 2010-05-11 22:57 ` Tim X
  2010-05-12 21:45   ` jdx2172
  2 siblings, 1 reply; 5+ messages in thread
From: Tim X @ 2010-05-11 22:57 UTC (permalink / raw)
  To: help-gnu-emacs

jdx2172 <dj9027@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.
>
>
>

Just use multiple argument specifiers in your call to interactive

,----[ C-h f interactive RET ]
| interactive is a special form in `C source code'.
| 
| (interactive &optional ARGS)
| 
| Specify a way of parsing arguments for interactive use of a function.
| For example, write
|  (defun foo (arg buf) "Doc string" (interactive "P\nbbuffer: ") .... )
|  to make ARG be the raw prefix argument, and set BUF to an existing buffer,
|  when `foo' is called as a command.
| The "call" to `interactive' is actually a declaration rather than a function;
|  it tells `call-interactively' how to read arguments
|  to pass to the function.
| When actually called, `interactive' just returns nil.
| 
| Usually the argument of `interactive' is a string containing a code letter
|  followed optionally by a prompt.  (Some code letters do not use I/O to get
|  the argument and do not use prompts.)  To get several arguments, concatenate
|  the individual strings, separating them by newline characters.
| Prompts are passed to format, and may use % escapes to print the
|  arguments that have already been read.
| If the argument is not a string, it is evaluated to get a list of
|  arguments to pass to the function.
| Just `(interactive)' means pass no args when calling interactively.
| 
| Code letters available are:
| a -- Function name: symbol with a function definition.
| b -- Name of existing buffer.
| B -- Name of buffer, possibly nonexistent.
| c -- Character (no input method is used).
| C -- Command name: symbol with interactive function definition.
| d -- Value of point as number.  Does not do I/O.
| D -- Directory name.
| e -- Parametrized event (i.e., one that's a list) that invoked this command.
|      If used more than once, the Nth `e' returns the Nth parameterized event.
|      This skips events that are integers or symbols.
| f -- Existing file name.
| F -- Possibly nonexistent file name.
| G -- Possibly nonexistent file name, defaulting to just directory name.
| i -- Ignored, i.e. always nil.  Does not do I/O.
| k -- Key sequence (downcase the last event if needed to get a definition).
| K -- Key sequence to be redefined (do not downcase the last event).
| m -- Value of mark as number.  Does not do I/O.
| M -- Any string.  Inherits the current input method.
| n -- Number read using minibuffer.
| N -- Numeric prefix arg, or if none, do like code `n'.
| p -- Prefix arg converted to number.  Does not do I/O.
| P -- Prefix arg in raw form.  Does not do I/O.
| r -- Region: point and mark as 2 numeric args, smallest first.  Does no I/O.
| s -- Any string.  Does not inherit the current input method.
| S -- Any symbol.
| U -- Mouse up event discarded by a previous k or K argument.
| v -- Variable name: symbol that is user-variable-p.
| x -- Lisp expression read but not evaluated.
| X -- Lisp expression read and evaluated.
| z -- Coding system.
| Z -- Coding system, nil if no prefix arg.
| 
| In addition, if the string begins with `*', an error is signaled if
|   the buffer is read-only.
| If the string begins with `@', Emacs searches the key sequence which
|  invoked the command for its first mouse click (or any other event
|  which specifies a window).
| If the string begins with `^' and `shift-select-mode' is non-nil,
|  Emacs first calls the function `handle-shift-selection'.
| You may use `@', `*', and `^' together.  They are processed in the
|  order that they appear, before reading any arguments.
`----

-- 
tcross (at) rapttech dot com dot au


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: a function more than interactive..
  2010-05-11 22:57 ` Tim X
@ 2010-05-12 21:45   ` jdx2172
  0 siblings, 0 replies; 5+ messages in thread
From: jdx2172 @ 2010-05-12 21:45 UTC (permalink / raw)
  To: help-gnu-emacs

On May 11, 6:57 pm, Tim X <t...@nospam.dev.null> 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.
>
> Just use multiple argument specifiers in your call to interactive
>
> ,----[ C-h f interactive RET ]
> | interactive is a special form in `C source code'.
> |
> | (interactive &optional ARGS)
> |
> | Specify a way of parsing arguments for interactive use of a function.
> | For example, write
> |  (defun foo (arg buf) "Doc string" (interactive "P\nbbuffer: ") .... )
> |  to make ARG be the raw prefix argument, and set BUF to an existing buffer,
> |  when `foo' is called as a command.
> | The "call" to `interactive' is actually a declaration rather than a function;
> |  it tells `call-interactively' how to read arguments
> |  to pass to the function.
> | When actually called, `interactive' just returns nil.
> |
> | Usually the argument of `interactive' is a string containing a code letter
> |  followed optionally by a prompt.  (Some code letters do not use I/O to get
> |  the argument and do not use prompts.)  To get several arguments, concatenate
> |  the individual strings, separating them by newline characters.
> | Prompts are passed to format, and may use % escapes to print the
> |  arguments that have already been read.
> | If the argument is not a string, it is evaluated to get a list of
> |  arguments to pass to the function.
> | Just `(interactive)' means pass no args when calling interactively.
> |
> | Code letters available are:
> | a -- Function name: symbol with a function definition.
> | b -- Name of existing buffer.
> | B -- Name of buffer, possibly nonexistent.
> | c -- Character (no input method is used).
> | C -- Command name: symbol with interactive function definition.
> | d -- Value of point as number.  Does not do I/O.
> | D -- Directory name.
> | e -- Parametrized event (i.e., one that's a list) that invoked this command.
> |      If used more than once, the Nth `e' returns the Nth parameterized event.
> |      This skips events that are integers or symbols.
> | f -- Existing file name.
> | F -- Possibly nonexistent file name.
> | G -- Possibly nonexistent file name, defaulting to just directory name.
> | i -- Ignored, i.e. always nil.  Does not do I/O.
> | k -- Key sequence (downcase the last event if needed to get a definition).
> | K -- Key sequence to be redefined (do not downcase the last event).
> | m -- Value of mark as number.  Does not do I/O.
> | M -- Any string.  Inherits the current input method.
> | n -- Number read using minibuffer.
> | N -- Numeric prefix arg, or if none, do like code `n'.
> | p -- Prefix arg converted to number.  Does not do I/O.
> | P -- Prefix arg in raw form.  Does not do I/O.
> | r -- Region: point and mark as 2 numeric args, smallest first.  Does no I/O.
> | s -- Any string.  Does not inherit the current input method.
> | S -- Any symbol.
> | U -- Mouse up event discarded by a previous k or K argument.
> | v -- Variable name: symbol that is user-variable-p.
> | x -- Lisp expression read but not evaluated.
> | X -- Lisp expression read and evaluated.
> | z -- Coding system.
> | Z -- Coding system, nil if no prefix arg.
> |
> | In addition, if the string begins with `*', an error is signaled if
> |   the buffer is read-only.
> | If the string begins with `@', Emacs searches the key sequence which
> |  invoked the command for its first mouse click (or any other event
> |  which specifies a window).
> | If the string begins with `^' and `shift-select-mode' is non-nil,
> |  Emacs first calls the function `handle-shift-selection'.
> | You may use `@', `*', and `^' together.  They are processed in the
> |  order that they appear, before reading any arguments.
> `----
>
> --
> tcross (at) rapttech dot com dot au

thanks everyone for all the help.
read-from-minibuffer was the exactly the interactivity I was looking
for.


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2010-05-12 21:45 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-05-11 13:11 a function more than interactive jdx2172
2010-05-11 13:46 ` Alan Mackenzie
     [not found] ` <lztyqejwer.fsf@informatimago.com>
2010-05-11 15:57   ` jdx2172
2010-05-11 22:57 ` Tim X
2010-05-12 21:45   ` jdx2172

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).