diff options
| author | Lars Ingebrigtsen | 2018-04-15 15:17:15 +0200 |
|---|---|---|
| committer | Lars Ingebrigtsen | 2018-04-15 15:17:15 +0200 |
| commit | a5f2403cc2d1fb81fa64d2e3650d3a59d47a5637 (patch) | |
| tree | 3cbae7bcea7f7a9fda18e43e8c09eb627f50f108 | |
| parent | ef599f6cac04ddfe09bf1e63f57c4b9fd5f63ce5 (diff) | |
| download | emacs-a5f2403cc2d1fb81fa64d2e3650d3a59d47a5637.tar.gz emacs-a5f2403cc2d1fb81fa64d2e3650d3a59d47a5637.zip | |
Avoid an infloop in shr filling when not using fonts
* lisp/net/shr.el (shr-fill-line): If we have an indentation
that's wider than the width of what we're trying to fill, just
give up. This avoids an infloop when `shr-use-fonts' in nil.
| -rw-r--r-- | lisp/net/shr.el | 75 |
1 files changed, 39 insertions, 36 deletions
diff --git a/lisp/net/shr.el b/lisp/net/shr.el index 5eb35b74dd1..655f1420b0a 100644 --- a/lisp/net/shr.el +++ b/lisp/net/shr.el | |||
| @@ -719,44 +719,47 @@ size, and full-buffer size." | |||
| 719 | `,(shr-face-background face)))) | 719 | `,(shr-face-background face)))) |
| 720 | (setq start (point)) | 720 | (setq start (point)) |
| 721 | (setq shr-indentation (or continuation shr-indentation)) | 721 | (setq shr-indentation (or continuation shr-indentation)) |
| 722 | (shr-vertical-motion shr-internal-width) | 722 | ;; If we have an indentation that's wider than the width we're |
| 723 | (when (looking-at " $") | 723 | ;; trying to fill to, then just give up and don't do any filling. |
| 724 | (delete-region (point) (line-end-position))) | 724 | (when (< shr-indentation shr-internal-width) |
| 725 | (while (not (eolp)) | ||
| 726 | ;; We have to do some folding. First find the first | ||
| 727 | ;; previous point suitable for folding. | ||
| 728 | (if (or (not (shr-find-fill-point (line-beginning-position))) | ||
| 729 | (= (point) start)) | ||
| 730 | ;; We had unbreakable text (for this width), so just go to | ||
| 731 | ;; the first space and carry on. | ||
| 732 | (progn | ||
| 733 | (beginning-of-line) | ||
| 734 | (skip-chars-forward " ") | ||
| 735 | (search-forward " " (line-end-position) 'move))) | ||
| 736 | ;; Success; continue. | ||
| 737 | (when (= (preceding-char) ?\s) | ||
| 738 | (delete-char -1)) | ||
| 739 | (let ((gap-start (point))) | ||
| 740 | (insert "\n") | ||
| 741 | (shr-indent) | ||
| 742 | (when (and (> (1- gap-start) (point-min)) | ||
| 743 | ;; The link on both sides of the newline are the | ||
| 744 | ;; same... | ||
| 745 | (equal (get-text-property (point) 'shr-url) | ||
| 746 | (get-text-property (1- gap-start) 'shr-url))) | ||
| 747 | ;; ... so we join the two bits into one link logically, but | ||
| 748 | ;; not visually. This makes navigation between links work | ||
| 749 | ;; well, but avoids underscores before the link on the next | ||
| 750 | ;; line when indented. | ||
| 751 | (let ((props (copy-sequence (text-properties-at (point))))) | ||
| 752 | ;; We don't want to use the faces on the indentation, because | ||
| 753 | ;; that's ugly. | ||
| 754 | (setq props (plist-put props 'face nil)) | ||
| 755 | (add-text-properties gap-start (point) props)))) | ||
| 756 | (setq start (point)) | ||
| 757 | (shr-vertical-motion shr-internal-width) | 725 | (shr-vertical-motion shr-internal-width) |
| 758 | (when (looking-at " $") | 726 | (when (looking-at " $") |
| 759 | (delete-region (point) (line-end-position)))))) | 727 | (delete-region (point) (line-end-position))) |
| 728 | (while (not (eolp)) | ||
| 729 | ;; We have to do some folding. First find the first | ||
| 730 | ;; previous point suitable for folding. | ||
| 731 | (if (or (not (shr-find-fill-point (line-beginning-position))) | ||
| 732 | (= (point) start)) | ||
| 733 | ;; We had unbreakable text (for this width), so just go to | ||
| 734 | ;; the first space and carry on. | ||
| 735 | (progn | ||
| 736 | (beginning-of-line) | ||
| 737 | (skip-chars-forward " ") | ||
| 738 | (search-forward " " (line-end-position) 'move))) | ||
| 739 | ;; Success; continue. | ||
| 740 | (when (= (preceding-char) ?\s) | ||
| 741 | (delete-char -1)) | ||
| 742 | (let ((gap-start (point))) | ||
| 743 | (insert "\n") | ||
| 744 | (shr-indent) | ||
| 745 | (when (and (> (1- gap-start) (point-min)) | ||
| 746 | ;; The link on both sides of the newline are the | ||
| 747 | ;; same... | ||
| 748 | (equal (get-text-property (point) 'shr-url) | ||
| 749 | (get-text-property (1- gap-start) 'shr-url))) | ||
| 750 | ;; ... so we join the two bits into one link logically, but | ||
| 751 | ;; not visually. This makes navigation between links work | ||
| 752 | ;; well, but avoids underscores before the link on the next | ||
| 753 | ;; line when indented. | ||
| 754 | (let ((props (copy-sequence (text-properties-at (point))))) | ||
| 755 | ;; We don't want to use the faces on the indentation, because | ||
| 756 | ;; that's ugly. | ||
| 757 | (setq props (plist-put props 'face nil)) | ||
| 758 | (add-text-properties gap-start (point) props)))) | ||
| 759 | (setq start (point)) | ||
| 760 | (shr-vertical-motion shr-internal-width) | ||
| 761 | (when (looking-at " $") | ||
| 762 | (delete-region (point) (line-end-position))))))) | ||
| 760 | 763 | ||
| 761 | (defun shr-find-fill-point (start) | 764 | (defun shr-find-fill-point (start) |
| 762 | (let ((bp (point)) | 765 | (let ((bp (point)) |