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

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

Re: Writing a command that assumes control of the keyboard, like isearch


From: harven
Subject: Re: Writing a command that assumes control of the keyboard, like isearch does
Date: Tue, 27 Apr 2010 10:25:34 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux)

Sean McAfee <eefacm@gmail.com> 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
                               ^


reply via email to

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