]> git.eshelyaron.com Git - emacs.git/commitdiff
Avoid an infloop in shr filling when not using fonts
authorLars Ingebrigtsen <larsi@gnus.org>
Sun, 15 Apr 2018 13:17:15 +0000 (15:17 +0200)
committerLars Ingebrigtsen <larsi@gnus.org>
Sun, 15 Apr 2018 13:17:15 +0000 (15:17 +0200)
* 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.

lisp/net/shr.el

index 5eb35b74dd19b714356306b3f60512b51e6366e0..655f1420b0a948db17cdaf920f7558793f0fe8b3 100644 (file)
@@ -719,44 +719,47 @@ size, and full-buffer size."
                           `,(shr-face-background face))))
     (setq start (point))
     (setq shr-indentation (or continuation shr-indentation))
-    (shr-vertical-motion shr-internal-width)
-    (when (looking-at " $")
-      (delete-region (point) (line-end-position)))
-    (while (not (eolp))
-      ;; We have to do some folding.  First find the first
-      ;; previous point suitable for folding.
-      (if (or (not (shr-find-fill-point (line-beginning-position)))
-             (= (point) start))
-         ;; We had unbreakable text (for this width), so just go to
-         ;; the first space and carry on.
-         (progn
-           (beginning-of-line)
-           (skip-chars-forward " ")
-           (search-forward " " (line-end-position) 'move)))
-      ;; Success; continue.
-      (when (= (preceding-char) ?\s)
-       (delete-char -1))
-      (let ((gap-start (point)))
-       (insert "\n")
-       (shr-indent)
-        (when (and (> (1- gap-start) (point-min))
-                   ;; The link on both sides of the newline are the
-                   ;; same...
-                   (equal (get-text-property (point) 'shr-url)
-                          (get-text-property (1- gap-start) 'shr-url)))
-          ;; ... so we join the two bits into one link logically, but
-          ;; not visually.  This makes navigation between links work
-          ;; well, but avoids underscores before the link on the next
-          ;; line when indented.
-          (let ((props (copy-sequence (text-properties-at (point)))))
-            ;; We don't want to use the faces on the indentation, because
-            ;; that's ugly.
-            (setq props (plist-put props 'face nil))
-           (add-text-properties gap-start (point) props))))
-      (setq start (point))
+    ;; If we have an indentation that's wider than the width we're
+    ;; trying to fill to, then just give up and don't do any filling.
+    (when (< shr-indentation shr-internal-width)
       (shr-vertical-motion shr-internal-width)
       (when (looking-at " $")
-       (delete-region (point) (line-end-position))))))
+        (delete-region (point) (line-end-position)))
+      (while (not (eolp))
+        ;; We have to do some folding.  First find the first
+        ;; previous point suitable for folding.
+        (if (or (not (shr-find-fill-point (line-beginning-position)))
+               (= (point) start))
+           ;; We had unbreakable text (for this width), so just go to
+           ;; the first space and carry on.
+           (progn
+             (beginning-of-line)
+             (skip-chars-forward " ")
+             (search-forward " " (line-end-position) 'move)))
+        ;; Success; continue.
+        (when (= (preceding-char) ?\s)
+         (delete-char -1))
+        (let ((gap-start (point)))
+         (insert "\n")
+         (shr-indent)
+          (when (and (> (1- gap-start) (point-min))
+                     ;; The link on both sides of the newline are the
+                     ;; same...
+                     (equal (get-text-property (point) 'shr-url)
+                            (get-text-property (1- gap-start) 'shr-url)))
+            ;; ... so we join the two bits into one link logically, but
+            ;; not visually.  This makes navigation between links work
+            ;; well, but avoids underscores before the link on the next
+            ;; line when indented.
+            (let ((props (copy-sequence (text-properties-at (point)))))
+              ;; We don't want to use the faces on the indentation, because
+              ;; that's ugly.
+              (setq props (plist-put props 'face nil))
+             (add-text-properties gap-start (point) props))))
+        (setq start (point))
+        (shr-vertical-motion shr-internal-width)
+        (when (looking-at " $")
+         (delete-region (point) (line-end-position)))))))
 
 (defun shr-find-fill-point (start)
   (let ((bp (point))