all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: gentsquash <gentsquash@gmail.com>
To: help-gnu-emacs@gnu.org
Subject: Invoke-with-typing
Date: Wed, 5 Jun 2013 10:58:32 -0700 (PDT)	[thread overview]
Message-ID: <e02aafea-d857-42d3-9040-a807bfcecdd2@ys5g2000pbc.googlegroups.com> (raw)

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	other threads:[~2013-06-05 17:58 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-06-05 17:58 gentsquash [this message]
2013-06-06  0:27 ` Invoke-with-typing Stefan Monnier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=e02aafea-d857-42d3-9040-a807bfcecdd2@ys5g2000pbc.googlegroups.com \
    --to=gentsquash@gmail.com \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.