shithub: neatroff

Download patch

ref: 8cd43423e4842210048f29e450ed339fbd17ea82
parent: ca4bbd28c33899685d9d7362bc90e0545dc118d6
author: Ali Gholami Rudi <[email protected]>
date: Fri Dec 12 13:18:19 EST 2014

fmt: consider line length in short line cost

--- a/fmt.c
+++ b/fmt.c
@@ -472,8 +472,10 @@
 			break;
 		cost = fmt_findcost(f, i);
 		/* the cost of formatting short lines; should prevent widows */
-		if (br && n_pmll && lwid < llen * n_pmll / 100)
-			cost += n_pmllcost;
+		if (br && n_pmll && lwid < llen * n_pmll / 100) {
+			int pmll = llen * n_pmll / 100;
+			cost += (long) n_pmllcost * (pmll - lwid) / pmll;
+		}
 		if (best < 0 || cost < best_cost) {
 			best = i;
 			best_cost = cost;