Non deterministic "gqap"

6 views
Skip to first unread message

Raúl Núñez de Arenas Coronado

unread,
May 13, 2009, 4:12:06 AM5/13/09
to Vim use
Hi all :)

Well, I should have said "half deterministic gqap". This command reflows
a paragraph, and in certain circumstances if you apply it repeteadly on
some paragraphs, the layout is different.

The details: you have a badly flowing paragraph and want to reflow it to
fit nicely in the current textwidth. That produces a new layout of the
words in the paragraph. Once it is properly reflowed, issuing "gqap"
again on the same paragraph shouldn't change the current layout, since
it is already reflowed. The problem is that the algorithm produces a new
layout. No line is longer than textwidth, so the algorithm thinks the
layout is correct. If you use "gqap" again, the previous layout is
generated. Each time you use "gqap" (after the first time, of course)
the algorithm switches between those two layouts.

This doesn't happen always. For example, the paragraphs above only have
that layout after gqap'ing them at my 72 textwidth, but some other
paragraphs don't. I'm afraid that the cause is that sometimes gqap
leaves a line exactly "textwidth" long when it is reflowing, but when
reflowing again, it considers such lines as "long". That is, gqap is
producing lines that are longer than what it considers "long", so
reflowing forces a layout change. If this is so, finding a line that
produces the problem is hard.

I'm sorry I don't have such a paragraph right now: last time I noticed I
didn't save the "offending" paragraph so I cannot show a proper example.
I just want to know if any other has experienced this and if so, try to
isolate the problem and maybe write a patch.

If I can find a problematic paragraph I'll post it as a reply to this
message.

Thanks :)

--
Raúl "DervishD" Núñez de Arenas Coronado
Linux Registered User 88736 | http://www.dervishd.net
It's my PC and I'll cry if I want to... RAmen!

Tim Chase

unread,
May 13, 2009, 9:11:48 AM5/13/09
to vim...@googlegroups.com
> Well, I should have said "half deterministic gqap". This
> command reflows a paragraph, and in certain circumstances if
> you apply it repeteadly on some paragraphs, the layout is
> different.

I can't say that I've noticed a problem with "gqap" and
determinism -- and I use it quite it regularly.

One other possibility that occurs to me for your investigation:
does your unflowed paragraph have a character that would be
treated as a mail/quote/comment-leader. So if you had something like

you see this is > that which is >some other

and it reflows to look like

you see this is
> that which is
>some other

reflows might change their behavior on the next reformat. It's a
bit of a pessimal test-case, but something you can watch for.

That said, just because I haven't reproduced it in years of usage
doesn't mean there's not some confluence of options that causes
problems. :)

It might help to include your settings from

set formatexpr? formatprg? textwidth? formatoptions?

And if you notice it happen again, undo your "gqap"s, yank the
original paragraph, intermediate paragraph, and final results
into an email with the output of the above settings. That may
better allow folks to reproduce the issue.

-tim

Raúl Núñez de Arenas Coronado

unread,
May 13, 2009, 9:41:33 AM5/13/09
to vim...@googlegroups.com
Saluton Tim :)

On Wed 13 May 2009 15:11 +0200, Tim Chase <v...@tim.thechases.com>
dixit:


>> Well, I should have said "half deterministic gqap". This command
>> reflows a paragraph, and in certain circumstances if you apply it
>> repeteadly on some paragraphs, the layout is different.
>
> I can't say that I've noticed a problem with "gqap" and determinism --
> and I use it quite it regularly.
>
> One other possibility that occurs to me for your investigation: does
> your unflowed paragraph have a character that would be treated as a
> mail/quote/comment-leader.  So if you had something like
>
>    you see this is > that which is >some other
>
> and it reflows to look like
>
>    you see this is
>    > that which is
>    >some other
>
> reflows might change their behavior on the next reformat.  It's a
> bit of a pessimal test-case, but something you can watch for.

Since email is (nowadays) what I write the most, last times I've noticed
the problem has been using email, but the last time has been while
writing an email, with no quotes whatsoever.

> It might help to include your settings from
>
>   set formatexpr? formatprg? textwidth? formatoptions?

formatexpr=
formatprg=
textwidth=72 (although most of the time I use 78)
formatoptions=tcql

Those are, of course, for the filetype I'm using right now, mail, which
has shown the problem.

> And if you notice it happen again, undo your "gqap"s, yank the
> original paragraph, intermediate paragraph, and final results into an
> email with the output of the above settings.  That may better allow
> folks to reproduce the issue.

Yes, I know, but last time it happened I couldn't post the report here
and just wrote a post-it to remember reporting. I was in a hurry so I
didn't save the offending paragraph. I've tried to write tailored
paragraphs this morning to stress the gqap, but without any success.

Dammit, I've noticed right now that I'm using gqip, not gqap, don't know
if that may affect things or not, but I'll post that in another reply,
just in case.

Thanks for your reply, I'll keep investigating.

Raúl Núñez de Arenas Coronado

unread,
May 13, 2009, 9:46:10 AM5/13/09
to Vim use
Saluton everybody :)

On 2009/5/13, Raúl Núñez de Arenas Coronado <r...@gmail.com> dixit:


> The details: you have a badly flowing paragraph and want to reflow it
> to fit nicely in the current textwidth. That produces a new layout of
> the words in the paragraph. Once it is properly reflowed, issuing
> "gqap" again on the same paragraph shouldn't change the current
> layout, since it is already reflowed. The problem is that the
> algorithm produces a new layout. No line is longer than textwidth, so
> the algorithm thinks the layout is correct. If you use "gqap" again,
> the previous layout is generated. Each time you use "gqap" (after the
> first time, of course) the algorithm switches between those two
> layouts.

Just in case it is important, I was using "gqip" and not "gqap". I'm not
going to change the subject to avoid further confusion. For the
documentation, ip and ap should work similar. "ap" selects the empty
line following the paragraph, "ip" doesn't, which means that "ip" is
"safer" in this issue, since it won't try to reflow the empty line the
first time :?

Sorry for the self-reply.

Tim Chase

unread,
May 13, 2009, 10:18:05 AM5/13/09
to vim...@googlegroups.com
>> It might help to include your settings from
>>
>> set formatexpr? formatprg? textwidth? formatoptions?
>
> formatexpr= formatprg= textwidth=72 (although most of the time
> I use 78) formatoptions=tcql

I don't know if it makes a difference but I don't have "l" in my
'fo' setting. Is this by your choice, or automatically set by
ft=mail?

> I've noticed right now that I'm using gqip, not gqap, don't
> know if that may affect things or not, but I'll post that in
> another reply, just in case.

I don't think it should make a great deal of difference, but good
to at least have the accurate information.

-tim


Raúl Núñez de Arenas Coronado

unread,
May 13, 2009, 10:59:47 AM5/13/09
to vim...@googlegroups.com
Saluton Tim :)

On Wed 13 May 2009 16:18 +0200, Tim Chase <v...@tim.thechases.com>
dixit:


>>formatoptions=tcql
>
> I don't know if it makes a difference but I don't have "l" in my 'fo'
> setting.  Is this by your choice, or automatically set by ft=mail?

It was ft=mail, it is in $VIMRUNTIME/ftplugin/mail.vim

Anyway, it shouldn't make a difference since I'm forcing the reflow, so
no matter if a line was longer than tw, it will be reformatted after the
first gqip

>> I've noticed right now that I'm using gqip, not gqap, don't know if
>> that may affect things or not, but I'll post that in another reply,
>> just in case.
>
> I don't think it should make a great deal of difference, but good to
> at least have the accurate information.

Long ago, when I used gq by hand, I used gqap, but when I put it in a
map I used gqip, don't know exactly why I switched. Probably looked
better at the moment :?

Reply all
Reply to author
Forward
0 new messages