Monday, November 17, 2014

Re: :%s//\=@o/gce ignores c flag in key mapping

I thank you both, Tim and Ben, for your help.  Let me explain the situation more fully.  I'm testing the feasibility of semi-automated repair of texts that have been ocr-ed from less than ideal sources, most notably from books.google.com.  To that end I've written two scripts; the first in sed to detect and impose formatting structure on the text from cues within the text itself; the second in awk to refer every word in the text to a word-list, and to prepend every word not in the list with @@.

At this point the text must be inspected visually to decide if each @@word is an error or not.  If not, the @@ is removed and the actual word is saved to be added to the awk script's word list.  If an error, the @@ is changed to qq (for later manual correction), so that errors that have already been processed will not be reprocessed by this vim script.

For my test file the awk program tagged some 3500 words, with 1960 of them unique, so this vim script must run within a loop to avoid the tedium and 4000 odd keystrokes required to invoke it individually for each unique error, which I assume invalidates the method I'm trying here, Tim, because then the :s...gce command cannot be forced to be last in the script, it must be followed by 'endw'.  That is not a problem as the same effect can be achieved using the input() function, and I have written such two ways, as a key-mapping and as a .vim script.  Both of these will do the job, but neither is actually useful for visual reasons.

It is essential that the user be able to read the text about the current @@word, to determine whether or not it is an error.  But when the key-mapping stops at the input() prompt vim lists above it all preceding commands in the while loop, which often has the effect of pushing the sentence of interest off the top of the screen.  How can I prevent that behavior?

The .vim approach is even worse as with that the screen does not update at all as the script works its way throuhg the text.  I cannot find any function in :h function-list that will actually cause the screen to show the text surrounding the current cursor position, and including say 'norm zz' immediately before input() has no effect at all.  Is there a method of getting the screen to constantly show the cursor as a .vim script progresses?


On Mon, Nov 17, 2014 at 9:01 AM, Ben Fritz <fritzophrenic@gmail.com> wrote:
On Monday, November 17, 2014 5:27:47 AM UTC-6, Tim Chase wrote:
> On 2014-11-15 13:59, porphyry5 wrote:
> > On Friday, November 14, 2014 4:02:55 PM UTC-8, porphyry5 wrote:
> > > In a key mapping I use the command ':%s//\=@o/gce'.
> > >
> > > The command executes as expected except that it behaves as if the
> > > c flag were not set.  Is this flag unavailable in a key mapping,
> > > or is there some other option that needs to be set for it to
> > > work.  It works as expected at the command line.
> >
> > This is the mapping concerned:
> > "map ,, /@@<CR>"myWcwqq<Esc>h"oywxx"nywma:let
> > @/=@m<CR>:%s//\=@n/ge<CR>:let @/=@n<CR>:%s//\=@o/gce<CR>`ay2h`a:if
> > @" != 'qq'<CR>:norm "Zyw<CR>:en<CR><CR>
>
> Ah, I believe the problem is triggered because the atoms after the
> ":%s//\=@o/gce<CR>" are interpreted as answers to the y/n/a/q/l/^E/^Y
> prompt.  The back-tick is ignored and the "a" (the subsequent atom)
> is interpreted as "a"ll the remaining matches.
>
> For this to work (actually prompting the user), the
> ":%s//\=@o/gce<cr>" has to be the last item in your mapping, leaving
> the :s command in the user-prompting state.
>

If this is the cause, it's probably cleaner to wrap everything in a function with one command per line, and call the function from the mapping. Then there are fewer ways for it to go awry.



--
Graham Lawrence

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment