diff options
| author | Eli Zaretskii | 2015-07-09 05:38:29 +0300 |
|---|---|---|
| committer | Michael Heerdegen | 2015-10-04 09:35:25 +0200 |
| commit | 45d0b3dd119566b2d2b29526b931eead15cdf740 (patch) | |
| tree | f07e5c51528c12a55749883809036cb1f15b1a14 | |
| parent | fd51234cd3b526edb86e905c96f8cd9f15d9a2d9 (diff) | |
| download | emacs-45d0b3dd119566b2d2b29526b931eead15cdf740.tar.gz emacs-45d0b3dd119566b2d2b29526b931eead15cdf740.zip | |
shr: fix too long lines in rendered buffers (Bug#21012)
Co-authored-by: Michael Heerdegen <michael_heerdegen@web.de>
* lisp/net/shr.el (shr-insert-document, shr-fill-text):
Correct calculation of available width.
(shr-find-fill-point): Don't overflow window edge if shr-kinsoku-shorten
is nil.
| -rw-r--r-- | lisp/net/shr.el | 50 |
1 files changed, 42 insertions, 8 deletions
diff --git a/lisp/net/shr.el b/lisp/net/shr.el index 60203f581ec..9116e506756 100644 --- a/lisp/net/shr.el +++ b/lisp/net/shr.el | |||
| @@ -222,10 +222,29 @@ DOM should be a parse tree as generated by | |||
| 222 | (if (not shr-use-fonts) | 222 | (if (not shr-use-fonts) |
| 223 | shr-width | 223 | shr-width |
| 224 | (* shr-width (frame-char-width)))) | 224 | (* shr-width (frame-char-width)))) |
| 225 | ;; We need to adjust the available | ||
| 226 | ;; width for when the user disables | ||
| 227 | ;; the fringes, which will cause the | ||
| 228 | ;; display engine usurp one column for | ||
| 229 | ;; the continuation glyph. | ||
| 225 | (if (not shr-use-fonts) | 230 | (if (not shr-use-fonts) |
| 226 | (- (window-width) 2) | 231 | (- (window-body-width) 1 |
| 227 | (- (window-pixel-width) | 232 | (if (and (null shr-width) |
| 228 | (* (frame-fringe-width) 2)))))) | 233 | (or (zerop |
| 234 | (fringe-columns 'right)) | ||
| 235 | (zerop | ||
| 236 | (fringe-columns 'left)))) | ||
| 237 | 0 | ||
| 238 | 1)) | ||
| 239 | (- (window-body-width nil t) | ||
| 240 | (* 2 (frame-char-width)) | ||
| 241 | (if (and (null shr-width) | ||
| 242 | (or (zerop | ||
| 243 | (fringe-columns 'right)) | ||
| 244 | (zerop | ||
| 245 | (fringe-columns 'left)))) | ||
| 246 | (* (frame-char-width) 2) | ||
| 247 | 0)))))) | ||
| 229 | (shr-descend dom) | 248 | (shr-descend dom) |
| 230 | (shr-fill-lines start (point)) | 249 | (shr-fill-lines start (point)) |
| 231 | (shr-remove-trailing-whitespace start (point)) | 250 | (shr-remove-trailing-whitespace start (point)) |
| @@ -439,8 +458,18 @@ size, and full-buffer size." | |||
| 439 | (with-temp-buffer | 458 | (with-temp-buffer |
| 440 | (let ((shr-indentation 0) | 459 | (let ((shr-indentation 0) |
| 441 | (shr-start nil) | 460 | (shr-start nil) |
| 442 | (shr-internal-width (- (window-pixel-width) | 461 | (shr-internal-width (- (window-body-width nil t) |
| 443 | (* (frame-fringe-width) 2)))) | 462 | (* 2 (frame-char-width)) |
| 463 | ;; Adjust the window width for when | ||
| 464 | ;; the user disables the fringes, | ||
| 465 | ;; which causes the display engine | ||
| 466 | ;; usurp one coplumn for the | ||
| 467 | ;; continuation glyph. | ||
| 468 | (if (and (null shr-width) | ||
| 469 | (or (zerop (fringe-columns 'right)) | ||
| 470 | (zerop (fringe-columns 'left)))) | ||
| 471 | (* (frame-char-width) 2) | ||
| 472 | 0)))) | ||
| 444 | (shr-insert text) | 473 | (shr-insert text) |
| 445 | (buffer-string))))) | 474 | (buffer-string))))) |
| 446 | 475 | ||
| @@ -620,7 +649,9 @@ size, and full-buffer size." | |||
| 620 | ;; There's no breakable point, so we give it up. | 649 | ;; There's no breakable point, so we give it up. |
| 621 | (let (found) | 650 | (let (found) |
| 622 | (goto-char bp) | 651 | (goto-char bp) |
| 623 | (unless shr-kinsoku-shorten | 652 | ;; Don't overflow the window edge, even if |
| 653 | ;; shr-kinsoku-shorten is nil. | ||
| 654 | (unless (or shr-kinsoku-shorten (null shr-width)) | ||
| 624 | (while (setq found (re-search-forward | 655 | (while (setq found (re-search-forward |
| 625 | "\\(\\c>\\)\\| \\|\\c<\\|\\c|" | 656 | "\\(\\c>\\)\\| \\|\\c<\\|\\c|" |
| 626 | (line-end-position) 'move))) | 657 | (line-end-position) 'move))) |
| @@ -632,9 +663,12 @@ size, and full-buffer size." | |||
| 632 | ;; Don't put kinsoku-bol characters at the beginning of a line, | 663 | ;; Don't put kinsoku-bol characters at the beginning of a line, |
| 633 | ;; or kinsoku-eol characters at the end of a line. | 664 | ;; or kinsoku-eol characters at the end of a line. |
| 634 | (cond | 665 | (cond |
| 635 | (shr-kinsoku-shorten | 666 | ;; Don't overflow the window edge, even if shr-kinsoku-shorten |
| 667 | ;; is nil. | ||
| 668 | ((or shr-kinsoku-shorten (null shr-width)) | ||
| 636 | (while (and (not (memq (preceding-char) (list ?\C-@ ?\n ? ))) | 669 | (while (and (not (memq (preceding-char) (list ?\C-@ ?\n ? ))) |
| 637 | (shr-char-kinsoku-eol-p (preceding-char))) | 670 | (or (shr-char-kinsoku-eol-p (preceding-char)) |
| 671 | (shr-char-kinsoku-bol-p (following-char)))) | ||
| 638 | (backward-char 1)) | 672 | (backward-char 1)) |
| 639 | (when (setq failed (<= (point) start)) | 673 | (when (setq failed (<= (point) start)) |
| 640 | ;; There's no breakable point that doesn't violate kinsoku, | 674 | ;; There's no breakable point that doesn't violate kinsoku, |