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.
    – phils
    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…
    – Clément
    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.
    – Clément
    Jun 16, 2017 at 17:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.