From 64d972eb2840e696731a81b8a71afa1934715dc7 Mon Sep 17 00:00:00 2001 From: Lars Magne Ingebrigtsen Date: Thu, 7 Oct 2010 15:21:13 +0200 Subject: [PATCH 1/1] (shr-insert): Rework the line-breaking algorithm. --- lisp/ChangeLog | 1 + lisp/shr.el | 31 ++++++++++++------------------- 2 files changed, 13 insertions(+), 19 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 92b3b5ba3..ee85479da 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -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-insert): Rework the line-breaking algorithm. 2010-10-07 Katsumi Yamaoka diff --git a/lisp/shr.el b/lisp/shr.el index 73011afed..6124ff7d8 100644 --- a/lisp/shr.el +++ b/lisp/shr.el @@ -188,20 +188,8 @@ redirects somewhere else." column) (when (and (string-match "\\`[ \t\n]" text) (not (bolp))) - (insert " ") - (setq shr-state 'space)) + (insert " ")) (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)) @@ -210,12 +198,17 @@ redirects somewhere else." ;; 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)) -- 2.25.1