4

Is there an existing function, and if not how would I write one, that turns this:

/* asdasdasd asdasdasd asdasdasd  */
/* asdasdasd asdasdasd asdasdasd asdasdasd asdasdasd */
/* asdasdasd asdasdasd asdasdasd  asdasdasd asdasdasd asdasdasd */
/* asdasdasd asdasdasd */
/* asdasdasd asdasdasd asdasdasd asdasdasd */

into this?

/* asdasdasd asdasdasd asdasdasd asdasdasd asdasdasd asdasdasd asdasdasd asdasdasd */
/* asdasdasd asdasdasd asdasdasd asdasdasd asdasdasd asdasdasd asdasdasd asdasdasd */
/* asdasdasd asdasdasd asdasdasd asdasdasd */

That function should also work for other languages with multi-line comments, like tuareg-mode with (* … *). I'd like to achieve the same behavior as M-q for line comments (which properly wraps and adjusts comment markers like //.

Clément
  • 3,924
  • 1
  • 22
  • 37
  • You can loop over `forward-comment` (both forwards and backwards) to establish the bounds of the commented region, then `uncomment-region`, `fill-region`, `comment-region` to reformat it. – phils Jun 08 '17 at 22:25
  • @phils That sounds pretty good, though a bit heavy-weight (note to self: I'd also have to change the fill-column to make sure that the added `/*` and `*/` don't make the text too long). I wonder if this could be achieved with a combination of fill-prefix and comment-start and… – Clément Jun 08 '17 at 22:46

1 Answers1

-1

I think you should be able to modify comment-style and perhaps comment-styles to suit your needs, and reformat with comment-region afterwards.

p_wiersig
  • 1,051
  • 9
  • 15