* Interactive-form invoked with specified arg
@ 2013-06-04 16:31 gentsquash
2013-06-04 17:17 ` Emanuel Berg
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: gentsquash @ 2013-06-04 16:31 UTC (permalink / raw)
To: help-gnu-emacs
Consider a FORM which prompts the user to type a character.
E.g, FORM might be
(y-or-n-p "Are you there?")
or
(query-replace "wierd" "weird") .
Is there a way to programmatically invoke FORM with the
character already specified? E.g
(invoke-as-if-I-typed (query-replace "wierd" "weird") "!")
behaves as if I invoked (query-replace "wierd" "weird"),
then, when prompted, typed "!".
-Jonathan
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Interactive-form invoked with specified arg
2013-06-04 16:31 Interactive-form invoked with specified arg gentsquash
@ 2013-06-04 17:17 ` Emanuel Berg
2013-06-04 23:20 ` gentsquash
2013-06-05 2:45 ` Stefan Monnier
[not found] ` <mailman.1012.1370400616.22516.help-gnu-emacs@gnu.org>
2 siblings, 1 reply; 7+ messages in thread
From: Emanuel Berg @ 2013-06-04 17:17 UTC (permalink / raw)
To: help-gnu-emacs
gentsquash <gentsquash@gmail.com> writes:
> (y-or-n-p "Are you there?")
> or
> (query-replace "wierd" "weird") .
>
> Is there a way to programmatically invoke FORM with the
> character already specified? E.g
>
> (invoke-as-if-I-typed (query-replace "wierd" "weird") "!")
>
> behaves as if I invoked (query-replace "wierd" "weird"), then,
> when prompted, typed "!".
Well, why would you want to emulate typing? If you told us the
overall goal perhaps we could find a better solution. Because
intuitively, emulate typing seems a bit strange, as typing *in the
first place* most often is an interface to invoking functions and
passing arguments.
You might check out `C-h f call-interactively'.
--
Emanuel Berg - programmer (hire me! CV below)
computer projects: http://user.it.uu.se/~embe8573
internet activity: http://home.student.uu.se/embe8573
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Interactive-form invoked with specified arg
2013-06-04 17:17 ` Emanuel Berg
@ 2013-06-04 23:20 ` gentsquash
2013-06-04 23:53 ` Emanuel Berg
0 siblings, 1 reply; 7+ messages in thread
From: gentsquash @ 2013-06-04 23:20 UTC (permalink / raw)
To: help-gnu-emacs
On Jun 4, 1:17pm, Emanuel Berg <embe8...@student.uu.se> wrote:
> ... intuitively, emulate typing seems a bit strange...
Not to me. Keyboard macros are a mechanism to convert
typed-actions into programmatic code. E.g, I could use
(execute-kbd-macro
[?\M-x ?q ?u ?e ?r ?y ?- ?r ?e ?p ?l ?a ?c ?e return ?a ?t
return ?@ return ?!] )
in place of my desired
(invoke-as-if-I-typed (query-replace "at" "@") "!")
However, firstly, this is clumsy. Secondly, it
doesn't allow me to pass-in the fnc-name,
e.g sometimes `query-replace',
sometimes `query-replace-regexp',
sometimes `dired-do-query-replace-regexp'.
> ...
> You might check out `C-h f call-interactively'.
I looked at it before I posted. If someone can explain to me
how it does what I want, then I'll be grateful.
As to why I seek `invoke-as-if-I-typed', there are
many reasons, but here is one. Imagine a fnc FOO that
sequentially invokes a bunch of fncs that will
prompt the user. While debugging FOO, I'd like to
make some of the branches in the execution tree [the
tree is controlled by user-input] to be executed
automatically, while I debug the other parts.
-Jonathan
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Interactive-form invoked with specified arg
2013-06-04 23:20 ` gentsquash
@ 2013-06-04 23:53 ` Emanuel Berg
0 siblings, 0 replies; 7+ messages in thread
From: Emanuel Berg @ 2013-06-04 23:53 UTC (permalink / raw)
To: help-gnu-emacs
gentsquash <gentsquash@gmail.com> writes:
> I looked at it before I posted. If someone can explain to me
> how it does what I want, then I'll be grateful.
Well, take replace-string for example. If you want to call it from
Elisp, it looks like this:
(replace-string FROM-STRING TO-STRING &optional DELIMITED START
END)
In the below function, you see how it is combined with
call-interactively. The result is the same as if the user would
have hit `M-x replace-string'. But, you don't have to write a
whole new interface (that does the same thing).
(defun replace-str ()
"Like `replace-string', but reset point when done."
(interactive)
(save-excursion
(call-interactively 'replace-string) ))
But, as for your purposes, now that you have described them in
more detail, I don't think it is the solution.
--
Emanuel Berg - programmer (hire me! CV below)
computer projects: http://user.it.uu.se/~embe8573
internet activity: http://home.student.uu.se/embe8573
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Interactive-form invoked with specified arg
2013-06-04 16:31 Interactive-form invoked with specified arg gentsquash
2013-06-04 17:17 ` Emanuel Berg
@ 2013-06-05 2:45 ` Stefan Monnier
[not found] ` <mailman.1012.1370400616.22516.help-gnu-emacs@gnu.org>
2 siblings, 0 replies; 7+ messages in thread
From: Stefan Monnier @ 2013-06-05 2:45 UTC (permalink / raw)
To: help-gnu-emacs
> (invoke-as-if-I-typed (query-replace "wierd" "weird") "!")
How 'bout
(let ((unread-command-events '(?!)))
(query-replace "wierd" "weird"))
-- Stefan
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Interactive-form invoked with specified arg
[not found] ` <mailman.1012.1370400616.22516.help-gnu-emacs@gnu.org>
@ 2013-06-05 16:49 ` gentsquash
2013-06-05 17:18 ` gentsquash
0 siblings, 1 reply; 7+ messages in thread
From: gentsquash @ 2013-06-05 16:49 UTC (permalink / raw)
To: help-gnu-emacs
On Jun 4, 10:45pm, Stefan Monnier <monn...@iro.umontreal.ca> wrote:
> > (invoke-as-if-I-typed (query-replace "wierd" "weird") "!")
>
> How 'bout
>
> (let ((unread-command-events '(?!)))
> (query-replace "wierd" "weird"))
Ah -that's the ticket! (Strange expression in English -I
wonder where it comes from?)
Thank you, both, Stefan and Emanuel. -Jonathan
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Interactive-form invoked with specified arg
2013-06-05 16:49 ` gentsquash
@ 2013-06-05 17:18 ` gentsquash
0 siblings, 0 replies; 7+ messages in thread
From: gentsquash @ 2013-06-05 17:18 UTC (permalink / raw)
To: help-gnu-emacs
Making Stefan's solution a macro, I am now using
this in my code:
(defmacro invoke-with-typing (FORM &rest CHARS)
"JK:05Jun2013: Executes FORM, which would normally prompt
the user for input. Here, CHARS are characters sent to the
form, as-if the user had typed them.
USAGE: (invoke-with-typing (query-replace \"wierd\" \"STRANGE\") ?y ?
n ?! )
will replace the first occurrence of \"wierd\", not the second,
and
all the remaining occurrences
Note that FORM needs to be a form, rather than evaluate to a form."
`(let ((unread-command-events ',CHARS)) ,FORM)
)
--Jonathan
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2013-06-05 17:18 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-06-04 16:31 Interactive-form invoked with specified arg gentsquash
2013-06-04 17:17 ` Emanuel Berg
2013-06-04 23:20 ` gentsquash
2013-06-04 23:53 ` Emanuel Berg
2013-06-05 2:45 ` Stefan Monnier
[not found] ` <mailman.1012.1370400616.22516.help-gnu-emacs@gnu.org>
2013-06-05 16:49 ` gentsquash
2013-06-05 17:18 ` gentsquash
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).