unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Invoke-with-typing
@ 2013-06-05 17:58 gentsquash
  2013-06-06  0:27 ` Invoke-with-typing Stefan Monnier
  0 siblings, 1 reply; 2+ messages in thread
From: gentsquash @ 2013-06-05 17:58 UTC (permalink / raw)
  To: help-gnu-emacs

In case it can be of use to someone else, in thread

  http://groups.google.com/group/gnu.emacs.help/browse_thread/thread/2241ae1fdd5b201c#

Stefan Monnier gave a soln, which I wrote into two macros.  (Yes,
I know the doc-string is longer than the macro.)   -Jonathan



(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 1st occurrence of \"wierd\", not the 2nd, and
  all the remaining occurrences

Note that FORM needs to be a form, rather than evaluate to a form.
For a nestable version, (describe-function 'IWT-nestable)"
  `(let ((unread-command-events ',CHARS)) ,FORM)
  )



(defmacro IWT-nestable (FORM &rest CHARS)
  "JK:05Jun2013: Like (describe-function 'invoke-with-typing)
but nestable, e.g:

USAGE: (IWT-nestable (IWT-nestable (query-replace \"wierd\" \"STRANGE
\") ?y ?n ) ?y ?n )
  will replace the 1st and 3rd occurrences, not the 2nd and 4th,
  then await user input."
  `(let ((unread-command-events (append ',CHARS unread-command-
events))) ,FORM)
  )


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

* Re: Invoke-with-typing
  2013-06-05 17:58 Invoke-with-typing gentsquash
@ 2013-06-06  0:27 ` Stefan Monnier
  0 siblings, 0 replies; 2+ messages in thread
From: Stefan Monnier @ 2013-06-06  0:27 UTC (permalink / raw)
  To: help-gnu-emacs

> (defmacro IWT-nestable (FORM &rest CHARS)
>   "JK:05Jun2013: Like (describe-function 'invoke-with-typing)
> but nestable, e.g:

> USAGE: (IWT-nestable (IWT-nestable (query-replace \"wierd\" \"STRANGE
> \") ?y ?n ) ?y ?n )
>   will replace the 1st and 3rd occurrences, not the 2nd and 4th,
>   then await user input."
>   `(let ((unread-command-events (append ',CHARS unread-command-
> events))) ,FORM)
>   )

That should use setq, not let.


        Stefan




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

end of thread, other threads:[~2013-06-06  0:27 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-06-05 17:58 Invoke-with-typing gentsquash
2013-06-06  0:27 ` Invoke-with-typing Stefan Monnier

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