changeset 111002:62243368de05

shr.el (shr-insert): Remove space inserted before or after a breakable character or at the beginning or the end of a line. shr.el (shr-find-fill-point): Do kinsoku; find the second best point or give it up if there's no breakable point.
author Katsumi Yamaoka <yamaoka@jpl.org>
date Fri, 15 Oct 2010 08:10:56 +0000
parents 5c0f2ce9d57f
children d5445d83cf4a
files lisp/gnus/ChangeLog lisp/gnus/shr.el
diffstat 2 files changed, 50 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/gnus/ChangeLog	Fri Oct 15 09:46:47 2010 +0200
+++ b/lisp/gnus/ChangeLog	Fri Oct 15 08:10:56 2010 +0000
@@ -1,3 +1,11 @@
+2010-10-15  Katsumi Yamaoka  <yamaoka@jpl.org>
+
+	* shr.el (shr-generic): Remove trailing space.
+	(shr-insert): Remove space inserted before or after a breakable
+	character or at the beginning or the end of a line.
+	(shr-find-fill-point): Do kinsoku; find the second best point or give
+	it up if there's no breakable point.
+
 2010-10-14  Lars Magne Ingebrigtsen  <larsi@gnus.org>
 
 	* nnimap.el (nnimap-open-connection): Message when opening connection
--- a/lisp/gnus/shr.el	Fri Oct 15 09:46:47 2010 +0200
+++ b/lisp/gnus/shr.el	Fri Oct 15 08:10:56 2010 +0000
@@ -218,20 +218,35 @@
 	;; starts.
 	(unless shr-start
 	  (setq shr-start (point)))
+	;; No space is needed before or after a breakable character or
+	;; at the beginning of a line.
+	(when (and (eq (preceding-char) ? )
+		   (or (= (line-beginning-position) (1- (point)))
+		       (aref fill-find-break-point-function-table
+			     (char-after (- (point) 2)))
+		       (aref fill-find-break-point-function-table
+			     (aref elem 0))))
+	  (delete-char -1))
 	(insert elem)
 	(while (> (current-column) shr-width)
-	  (if (not (shr-find-fill-point))
-	      (insert "\n")
-	    (delete-char 1)
-	    (insert "\n")
+	  (unless (prog1
+		      (shr-find-fill-point)
+		    (when (eq (preceding-char) ? )
+		      (delete-char -1))
+		    (insert "\n"))
 	    (put-text-property (1- (point)) (point) 'shr-break t)
-	    (when (> shr-indentation 0)
-	      (shr-indent))
-	    (end-of-line)))
+	    ;; No space is needed at the beginning of a line.
+	    (if (eq (following-char) ? )
+		(delete-char 1)))
+	  (when (> shr-indentation 0)
+	    (shr-indent))
+	  (end-of-line))
 	(insert " "))
       (unless (string-match "[ \t\n]\\'" text)
 	(delete-char -1))))))
 
+(eval-and-compile (autoload 'kinsoku-longer "kinsoku"))
+
 (defun shr-find-fill-point ()
   (let ((found nil))
     (while (and (not found)
@@ -240,10 +255,26 @@
 		     (aref fill-find-break-point-function-table
 			   (preceding-char)))
 		 (<= (current-column) shr-width))
-	(setq found (point)))
-      (backward-char 1))
-    (or found
-	(end-of-line))))
+	(setq found t))
+      (backward-char 1)
+      (when (bolp)
+	;; There's no breakable point, so we give it up.
+	(end-of-line)
+	(while (aref fill-find-break-point-function-table
+		     (preceding-char))
+	  (backward-char 1))
+	(setq found 'failed)))
+    (cond ((eq found t)
+	   ;; Don't put kinsoku-bol characters at the beginning of a line.
+	   (or (eobp)
+	       (kinsoku-longer)
+	       (not (aref fill-find-break-point-function-table
+			  (following-char)))
+	       (forward-char 1)))
+	  (found t)
+	  (t
+	   (end-of-line)
+	   nil))))
 
 (defun shr-ensure-newline ()
   (unless (zerop (current-column))