0

Inspired by a recent addition of text-wrap: balance to CSS I've suddenly realized I'd like to have balanced comments in my code. Current behaviour of fill-paragraph (with my current settings) converts this:

# Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna

to this

# Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore
# magna

while I'd like it to become more like this:

# Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam
# nonumy eirmod tempor invidunt ut labore et dolore magna

Is there any easy way to tune fill-paragraph to balance the lines like this?

2
  • I'm not sure I understand... do you just want to change the fill-column ?
    – phils
    Commented Mar 17, 2023 at 9:41
  • @phils no, fill-column stays the same, but the length of all lines is rebalanced to avoid typographic widows, i.e. a single word on a line. With a longer paragraph, line length would be closer to fill-column, but could become quite short with two-liners like in the example. Commented Mar 17, 2023 at 10:13

1 Answer 1

3

avoid typographic widows, i.e. a single word on a line.

If you just want to avoid single word lines, then see user option fill-nobreak-predicate and its standard option fill-single-word-nobreak-p which says "Don't break a line after the first or before the last word of a sentence."

You could undoubtedly adapt that to more custom requirements as well.

1
  • Thanks, that looks like the hook to implement something like this. Commented Mar 17, 2023 at 14:42

Your Answer

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

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