GNU bug report logs - #61028
30.0.50; [PATCH] [FEATURE] Balanced fill mode

Previous Next

Package: emacs;

Reported by: Andrew Kensler <andrew <at> eastfarthing.com>

Date: Mon, 23 Jan 2023 14:27:01 UTC

Severity: wishlist

Tags: patch

Found in version 30.0.50

Full log


View this message in rfc822 format

From: Andrew Kensler <andrew <at> eastfarthing.com>
To: 61028 <at> debbugs.gnu.org
Subject: bug#61028: 30.0.50; [PATCH] [FEATURE] Balanced fill mode
Date: Mon, 23 Jan 2023 01:40:40 -0800
[Message part 1 (text/plain, inline)]
Greetings all,

The proposed patch attached adds a new minor balanced-fill-mode with an 
alternate line breaking algorithm for paragraph filling.  When enabled, 
it will try to neatly balance line lengths to reduce raggedness, avoid 
widows, avoid starting a new sentence on the last word of a line, avoid 
ending a sentence on the first word of a line, and so forth.  It is 
heavily inspired by the Knuth-Plass line breaking algorithm and uses 
dynamic programming to try to choose line breaks to minimize a cost 
function.

For example, consider the following mock paragraph as filled by the 
current greedy algorithm with the fill-column set to 15:

Ccc ccc a bb
dddd bb bb a
ccc a
jjjjjjjjjj a
eeeee a
hhhhhhhh bb
dddd.

With the new minor mode enabled, it would instead be filled much more 
nicely as:

Ccc ccc a
bb dddd bb
bb a ccc a
jjjjjjjjjj
a eeeee a
hhhhhhhh
bb dddd.

Often, the result is similar to simply having used a particular slightly 
narrower fill-column with the current greedy algorithm.  The advantage, 
however, is that it figures out the correct column automatically and 
per-paragraph.

The main piece of implementation is in the new 
(balanced-fill-break-lines) function in fill.el, with a modification to 
(fill-region-as-paragraph) to optionally call this before its current 
line breaking loop.  If it runs successfully, then point will be set to 
the end of the paragraph and that loop skipped.

Note that (fill-region-as-paragraph) has no hooks and is too monolithic 
to advise for this kind of thing, hence my hoping to upstream this change.

This is my first time contributing anything significant to Emacs or 
writing here.  I believe that the proposed patch covers all the major 
needs: the code itself, commit message, info documentation, announcement 
in NEWS, and a basic ERT test.  If there's anything I've missed or 
suggestions for improvements, please let me know. (And I hope this is 
the correct mailing list and message format, too.)  I'll be happy to 
sign the copyright assignment paperwork if this looks like something 
you'd like to accept.

Cheers,
- Andrew
[Message part 2 (text/html, inline)]
[0001-Add-new-minor-balanced-fill-mode-to-filling.patch (text/x-patch, attachment)]

This bug report was last modified 1 year and 286 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.