From 204380176cb3edf83951e3c8442bf959f077ea2a Mon Sep 17 00:00:00 2001 From: Katsumi Yamaoka Date: Fri, 15 Oct 2010 08:10:56 +0000 Subject: [PATCH] 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. --- lisp/gnus/ChangeLog | 8 +++++++ lisp/gnus/shr.el | 53 +++++++++++++++++++++++++++++++++++---------- 2 files changed, 50 insertions(+), 11 deletions(-) diff --git a/lisp/gnus/ChangeLog b/lisp/gnus/ChangeLog index 27363445e35..4c722b3d8aa 100644 --- a/lisp/gnus/ChangeLog +++ b/lisp/gnus/ChangeLog @@ -1,3 +1,11 @@ +2010-10-15 Katsumi Yamaoka + + * 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 * nnimap.el (nnimap-open-connection): Message when opening connection diff --git a/lisp/gnus/shr.el b/lisp/gnus/shr.el index 4d70a62ac50..0ebd60c7543 100644 --- a/lisp/gnus/shr.el +++ b/lisp/gnus/shr.el @@ -218,20 +218,35 @@ redirects somewhere else." ;; 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 @@ redirects somewhere else." (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)) -- 2.39.5