(shr-insert): Rework the line-breaking algorithm.
authorLars Magne Ingebrigtsen <larsi@quimbies.gnus.org>
Thu, 7 Oct 2010 13:21:13 +0000 (15:21 +0200)
committerLars Magne Ingebrigtsen <larsi@quimbies.gnus.org>
Thu, 7 Oct 2010 13:21:13 +0000 (15:21 +0200)
lisp/ChangeLog
lisp/shr.el

index 92b3b5b..ee85479 100644 (file)
@@ -2,6 +2,7 @@
 
        * shr.el (shr-render-td): Use a cache for the table rendering function
        to avoid getting an exponential rendering behaviour in nested tables.
 
        * shr.el (shr-render-td): Use a cache for the table rendering function
        to avoid getting an exponential rendering behaviour in nested tables.
+       (shr-insert): Rework the line-breaking algorithm.
 
 2010-10-07  Katsumi Yamaoka  <yamaoka@jpl.org>
 
 
 2010-10-07  Katsumi Yamaoka  <yamaoka@jpl.org>
 
index 73011af..6124ff7 100644 (file)
@@ -188,20 +188,8 @@ redirects somewhere else."
          column)
       (when (and (string-match "\\`[ \t\n]" text)
                 (not (bolp)))
          column)
       (when (and (string-match "\\`[ \t\n]" text)
                 (not (bolp)))
-       (insert " ")
-       (setq shr-state 'space))
+       (insert " "))
       (dolist (elem (split-string text))
       (dolist (elem (split-string text))
-       (setq column (current-column))
-       (when (> column 0)
-         (cond
-          ((and (or (not first)
-                    (eq shr-state 'space))
-                (> (+ column (length elem) 1) shr-width))
-           (insert "\n")
-           (put-text-property (1- (point)) (point) 'shr-break t))
-          ((not first)
-           (insert " "))))
-       (setq first nil)
        (when (and (bolp)
                   (> shr-indentation 0))
          (shr-indent))
        (when (and (bolp)
                   (> shr-indentation 0))
          (shr-indent))
@@ -210,12 +198,17 @@ redirects somewhere else."
        ;; starts.
        (unless shr-start
          (setq shr-start (point)))
        ;; starts.
        (unless shr-start
          (setq shr-start (point)))
-       (insert elem))
-      (setq shr-state nil)
-      (when (and (string-match "[ \t\n]\\'" text)
-                (not (bolp)))
-       (insert " ")
-       (setq shr-state 'space))))))
+       (insert elem)
+       (when (> (current-column) shr-width)
+         (if (not (search-backward " " (line-beginning-position) t))
+             (insert "\n")
+           (delete-char 1)
+           (insert "\n")
+           (put-text-property (1- (point)) (point) 'shr-break t)
+           (when (> shr-indentation 0)
+             (shr-indent))
+           (end-of-line)))
+       (insert " "))))))
 
 (defun shr-ensure-newline ()
   (unless (zerop (current-column))
 
 (defun shr-ensure-newline ()
   (unless (zerop (current-column))