* shr.el: Expand TD elements to fill available space.
authorLars Magne Ingebrigtsen <larsi@quimbies.gnus.org>
Thu, 7 Oct 2010 11:35:14 +0000 (13:35 +0200)
committerLars Magne Ingebrigtsen <larsi@quimbies.gnus.org>
Thu, 7 Oct 2010 11:35:14 +0000 (13:35 +0200)
lisp/ChangeLog
lisp/shr.el

index d459501..1bef46a 100644 (file)
@@ -1,3 +1,8 @@
+2010-10-07  Lars Magne Ingebrigtsen  <larsi@gnus.org>
+
+       * shr.el (shr-table-widths): Expand TD elements to fill available
+       space.
+
 2010-10-07  Julien Danjou  <julien@danjou.info>
 
        * nnimap.el (nnimap-request-rename-group): Add this method.
index 30f7929..ffbb430 100644 (file)
@@ -523,23 +523,31 @@ Return a string with image data."
 
 (defun shr-table-widths (table suggested-widths)
   (let* ((length (length suggested-widths))
-        (widths (make-vector length 0)))
+        (widths (make-vector length 0))
+        (natural-widths (make-vector length 0)))
     (dolist (row table)
       (let ((i 0))
        (dolist (column row)
          (aset widths i (max (aref widths i)
                              (car column)))
+         (aset natural-widths i (max (aref natural-widths i)
+                                     (cadr column)))
          (setq i (1+ i)))))
     (let ((extra (- (reduce '+ suggested-widths)
-                   (reduce '+ widths))))
+                   (reduce '+ widths)))
+         (expanded-columns 0))
       (when (> extra 0)
        (dotimes (i length)
-         (aset widths i
-               (+ (aref widths i)
-                  (truncate
-                   (* extra
-                      (/ (* (aref widths i) 1.0)
-                         (reduce '+ widths)))))))))
+         ;; If the natural width is wider than the rendered width, we
+         ;; want to allow the column to expand.
+         (when (> (aref natural-widths i) (aref widths i))
+           (setq expanded-columns (1+ expanded-columns))))
+       (dotimes (i length)
+         (when (> (aref natural-widths i) (aref widths i))
+           (aset widths i (min
+                           (1+ (aref natural-widths i))
+                           (+ (/ extra expanded-columns)
+                              (aref widths i))))))))
     widths))
 
 (defun shr-make-table (cont widths &optional fill)
@@ -600,11 +608,13 @@ Return a string with image data."
   (let ((current 0)
        (max 0))
     (while (not (eobp))
+      (end-of-line)
       (setq current (+ current (current-column)))
       (unless (get-text-property (point) 'shr-break)
        (setq max (max max current)
              current 0))
-      (forward-line 1))))
+      (forward-line 1))
+    max))
 
 (defun shr-collect-overlays ()
   (save-excursion