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

2
  • 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. Commented Jun 8, 2017 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… Commented Jun 8, 2017 at 22:46

1 Answer 1

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

1
  • Can you give a concrete example? AFAIK comment-region doesn't reflow comments. Commented Jun 16, 2017 at 17:38

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.