Wednesday, May 27, 2015

Re: reformatting comments

On Mi, 27 Mai 2015, Christian Brabandt wrote:

> On Mi, 27 Mai 2015, Ben Fritz wrote:
>
> > On Wednesday, May 27, 2015 at 10:06:11 AM UTC-5, Christian Brabandt wrote:
> > > Hi,
> > > Can someone explain this behaviour?
> > >
> > > vim -u NONE -N --cmd ':set comments=e:%% tw=20' -c 'call setline(1, "%%
> > > ".repeat("foobar ", 10))' -c 'norm! Vgq'
> > >
> > > Output:
> > > ,----
> > > | %% foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar
> > > `----
> > > Note: not reformated to fit into the textwidth
> > >
> > > Expected Output:
> > > ,----
> > > | %% foobar foobar
> > > | %% foobar foobar
> > > | %% foobar foobar
> > > | %% foobar foobar
> > > | %% foobar foobar
> > > `----
> > > (Reformated to fit into textwidth, the comment leader might be left
> > > away)
> > >
> >
> > Why do you expect this behavior?
>
> Well, this was a reduced example from a tex file, that I could not
> reformat, because a comment started with %%. I expect even the endpart
> of a comment to be reformatable according to the current &tw setting.
>
> > You're specifying only the end part of a 3-part comment, making it an
> > invalid entry. From :help format-comments:
> >
> > > A three-piece comment must always be given as start,middle,end, with
> > > no other parts in between. An example of a three-piece comment is
> > > sr:/*,mb:*,ex:*/
>
> Well, have you tried it with a complete three-piece comment? Latex Files
> are a good example:
> (taken from $VIMRUNTIME/ftplugin/initex.vim)
>
> vim -u NONE -N --cmd ':set comments=sO:%\ -,mO:%\ \ ,eO:%%,:% tw=20' -c
> 'call setline(1, "%% ".repeat("foobar ", 10))' -c 'norm! Vgq'
>
> (still does not reformat).

Source says this:

/*
* Blank lines, and lines containing only the comment leader, are left
* untouched by the formatting. The function returns TRUE in this
* case. It also returns TRUE when a line starts with the end of a comment
* ('e' in comment flags), so that this line is skipped, and not joined to the
* previous line. A new paragraph starts after a blank line, or when the
* comment leader changes -- webb.
*/

This explains it. It should be documented however, but I can understand
why this is done, because when the end comment occurs, it doesn't make
sense to split the line and insert another end comment marker into newly
created line.

But perhaps, it should only be done, if after the end marker, no other
comment occurs? Or perhaps the latex filetype plugin should remove the
three-part comment altogether, as '%%' does not seem to actually end a
comment in tex files? (Maintainer CC'ed for clarification).

Best,
Christian
--
Die Jugend und die schöne Liebe, alles hat sein Ende.
-- Goethe

--
--
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: