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

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

Invoke-with-typing


From: gentsquash
Subject: Invoke-with-typing
Date: Wed, 5 Jun 2013 10:58:32 -0700 (PDT)
User-agent: G2/1.0

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


reply via email to

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