Saturday, August 15, 2015

Re: C comment block indentation woes

On 14.08.15 04:02, Oliver Wraight wrote:
> The behaviour I'm after is ludicrously simple:
>
> /*
> Comment block indented
> by shiftwidth
> */
>
> The behaviour I'm getting is:
>
> /*
> Comment block indented
> by shiftwidth
> */
>
...

> comments=sO:* -,mO:* ,exO:*/,s1:/*,mb:*,ex:*/,://
^^^^^^^^^^^^^^^^
> Last set from /usr/share/vim/vim74/ftplugin/c.vim

that's what needs to be tweaked.

Unfortunately, performing a :set with that here gives:

E518: Unknown option: -,mO:*

So I'll just try tweaking the three-part comment portion of it (see
":h format-comments") to see what can be done with that in a few
minutes. Changing the s,m,e parts of my local setting to:

:set comments=s:/*,mb1:.,ex-1:*/,://,b:#,:%,:XCOMM,n:>,fb:-,fb:o
^^^^^^^^^^^^^^^^

produces:

/*
. Auto-generated middle line start character.
*/

Why the dot? If I replace '.' with a space, Vim barfs:

E525: Zero length string: comments=s1:/*,mb:

which seems to be due to >>>

Three-piece comments must have a middle string because otherwise Vim
can't recognize the middle lines.
<<<

/*
_ Is this any better?
_ (Use "mb1:_")
*/

> Thanks for any help you can offer, even a "Can't be done" would help.

The 'f' flag should ideally (wishfully?) be able to eliminate the
character auto-insertion for comment middle lines:

f Only the first line has the comment string. Do not repeat comment
on the next line, but preserve indentation.

But that is perhaps only for bullet lists, and it can't (at present) be
inveigled in a three-part comment format specification. Nevertheless,
this may be enough to get them off your back. The indentation is
compliant, and the underscore (or more conventional '*'?) might be able
to be sold, at least until a complete solution is winkled out of the
woodwork.

Best of luck with the format police.

Erik
(Who had the luxury, over three decades, of being or having the C local
format police report to him. :-))

--
C hasn't changed much since the 1970s. And let's face it it's ugly.
Can't we do better? C++? (Sorry, never mind.) - Rob Pike

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