From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Sean McAfee Newsgroups: gmane.emacs.help Subject: Writing a command that assumes control of the keyboard, like isearch does Date: Mon, 26 Apr 2010 23:18:04 -0700 Message-ID: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: dough.gmane.org 1273015635 7345 80.91.229.12 (4 May 2010 23:27:15 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Tue, 4 May 2010 23:27:15 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed May 05 01:27:14 2010 connect(): No such file or directory Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1O9RWD-0002Mt-H7 for geh-help-gnu-emacs@m.gmane.org; Wed, 05 May 2010 01:27:13 +0200 Original-Received: from localhost ([127.0.0.1]:48097 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1O9RWC-0003HM-K7 for geh-help-gnu-emacs@m.gmane.org; Tue, 04 May 2010 19:27:12 -0400 Original-Path: usenet.stanford.edu!news.isc.org!news.glorb.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!nntp.supernews.com!news.supernews.com.POSTED!not-for-mail Original-NNTP-Posting-Date: Tue, 27 Apr 2010 01:18:05 -0500 Original-Newsgroups: gnu.emacs.help User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.3 (darwin) Cancel-Lock: sha1:d9Dk8Y+dhmA6+e0t4PgtRfeYTnI= Original-Lines: 46 Original-X-Trace: sv3-aktelyzpf8HHQEjylyVmHnPYk4vh+yvJh6bzgYAZIOvrBh+Am0GDFXeky6Ntiw5hwQMOmXIYM2hztYT!/gLlkpPWJ7N+hnjA4Aw0OQZM0VzzlLoWnhsD/QRRb5lySCPg12M1niTF Original-X-Complaints-To: www.supernews.com/docs/abuse.html X-DMCA-Complaints-To: www.supernews.com/docs/dmca.html X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 Original-Xref: usenet.stanford.edu gnu.emacs.help:177870 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:73286 Archived-At: I want to write a command that assumes control of the keyboard until it returns, highlighting and modifying the current buffer in the meantime, like the isearch family of commands do. Specifically, I have some text that is the output from an OCR process, in which the spaces between words have sometimes been lost; for example: GNUEmacsisanextensible,customizabletexteditor—andmore. I want to write a command that will wait for me to type a letter, then advance the cursor to that letter and provisionally insert a space after it, highlighting the passed-over text (the provisional word, that is). If I then type a space, I confirm the provisional word; if I type another letter, the provisional space is removed, and the cursor skips to the newer letter I typed and inserts another provisional space. Therefore, I could break the words in the sample text above with this key sequence: u SPC s SPC s SPC n SPC e e SPC e SPC t t SPC r SPC d SPC Some kind of special handling would probably be needed for punctuation, but I can resolve those details later. And I suppose RET would probably terminate the command. Since the behavior I want to implement broadly resembles what isearch does, I went and read the source code, but found it unsuitable for casual reading. I did note this command near the beginning: ;; For programmed use of isearch-mode, e.g. calling (isearch-forward), ;; isearch-mode behaves modally and does not return until the search ;; is completed. It uses a recursive-edit to behave this way. So, does that mean it *doesn't* use a recursive edit when called interactively? What does it do in that case? Not very illuminating. Browsing the manual, it seems that I might be able to write my own mini event loop using read-char, but I can't help but feel that there must be an easier way. As best I can express it right now, I want to temporarily install a keymap where every key that normally calls self-insert-command calls a routine of my choice instead; SPC and RET have the special meanings described above; and any other key sequence exits my command and has its normal effect (again, like isearch). Any pointers to get me on the right track, or even just references to the appropriate places in the manual that I might have missed, would be greatly appreciated.