From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: harven Newsgroups: gmane.emacs.help Subject: Re: Writing a command that assumes control of the keyboard, like isearch does Date: Tue, 27 Apr 2010 10:25:34 +0200 Organization: http://groups.google.com Message-ID: <87fx2hs3nl.fsf@ergodik.univ-brest.fr> References: 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 1273015708 7516 80.91.229.12 (4 May 2010 23:28:28 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Tue, 4 May 2010 23:28:28 +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:28:27 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 1O9RXO-0002i2-HB for geh-help-gnu-emacs@m.gmane.org; Wed, 05 May 2010 01:28:26 +0200 Original-Received: from localhost ([127.0.0.1]:41021 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1O9RXN-0004qH-Sb for geh-help-gnu-emacs@m.gmane.org; Tue, 04 May 2010 19:28:25 -0400 Original-Path: usenet.stanford.edu!news.tele.dk!news.tele.dk!small.news.tele.dk!kanaga.switch.ch!switch.ch!news.in2p3.fr!in2p3.fr!news.ecp.fr!crihan.fr!news.univ-brest.fr!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 52 Original-NNTP-Posting-Host: mathw171.univ-brest.fr Original-X-Trace: news.univ-brest.fr 1272356820 2659 172.19.130.171 (27 Apr 2010 08:27:00 GMT) Original-X-Complaints-To: usenet@news.univ-brest.fr Original-NNTP-Posting-Date: 27 Apr 2010 08:27:00 GMT User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:0hrJmAofY7f16SalJb0MrSXfkYA= Original-Xref: usenet.stanford.edu gnu.emacs.help:177871 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:73287 Archived-At: Sean McAfee writes: > 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. > 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. A simple while loop (with no body !) together with read-event may be sufficient. Something like (defun essai () (interactive) (let (key (echo-keystrokes 0)) (setq key (read-event)) (while (when (characterp key) (search-forward (char-to-string key) nil t) (insert " ") (setq key (read-event)) (if (equal key ?\ ) (setq key (read-event)) (delete-char -1) t))))) BTW it seems there is a missing e u SPC s SPC s SPC n SPC e e e SPC e SPC t t SPC r SPC d SPC ^