]> code.delx.au - gnu-emacs/blobdiff - lisp/net/shr.el
Merge branch 'scratch/follow' of /home/acm/emacs/emacs.git/emacs-25 into scratch...
[gnu-emacs] / lisp / net / shr.el
index 0ce77b9055cd9fa96cddd17ea40cdb0fbedf08e7..a48d098fe2605229f1fea801379aed2fa8193fc8 100644 (file)
@@ -203,6 +203,12 @@ cid: URL as the argument.")
       (goto-char begin)
       (shr-insert-document dom))))
 
+(defun shr--have-one-fringe-p ()
+  "Return non-nil if we know at least one of the fringes has non-zero width."
+  (and (fboundp 'fringe-columns)
+       (or (not (zerop (fringe-columns 'right)))
+           (not (zerop (fringe-columns 'left))))))
+
 ;;;###autoload
 (defun shr-insert-document (dom)
   "Render the parsed document DOM into the current buffer.
@@ -222,10 +228,23 @@ DOM should be a parse tree as generated by
                                     (if (not shr-use-fonts)
                                         shr-width
                                       (* shr-width (frame-char-width))))
+                                ;; We need to adjust the available
+                                ;; width for when the user disables
+                                ;; the fringes, which will cause the
+                                ;; display engine usurp one column for
+                                ;; the continuation glyph.
                                (if (not shr-use-fonts)
-                                   (- (window-width) 2)
-                                 (- (window-pixel-width)
-                                    (* (frame-fringe-width) 2))))))
+                                   (- (window-body-width) 1
+                                       (if (and (null shr-width)
+                                                (not (shr--have-one-fringe-p)))
+                                           0
+                                         1))
+                                 (- (window-body-width nil t)
+                                     (* 2 (frame-char-width))
+                                     (if (and (null shr-width)
+                                              (not (shr--have-one-fringe-p)))
+                                         (* (frame-char-width) 2)
+                                       0))))))
     (shr-descend dom)
     (shr-fill-lines start (point))
     (shr-remove-trailing-whitespace start (point))
@@ -439,8 +458,17 @@ size, and full-buffer size."
     (with-temp-buffer
       (let ((shr-indentation 0)
            (shr-start nil)
-           (shr-internal-width (- (window-pixel-width)
-                                  (* (frame-fringe-width) 2))))
+           (shr-internal-width (- (window-body-width nil t)
+                                   (* 2 (frame-char-width))
+                                   ;; Adjust the window width for when
+                                   ;; the user disables the fringes,
+                                   ;; which causes the display engine
+                                   ;; to usurp one column for the
+                                   ;; continuation glyph.
+                                   (if (and (null shr-width)
+                                            (not (shr--have-one-fringe-p)))
+                                       (* (frame-char-width) 2)
+                                     0))))
        (shr-insert text)
        (buffer-string)))))
 
@@ -620,7 +648,9 @@ size, and full-buffer size."
        ;; There's no breakable point, so we give it up.
        (let (found)
          (goto-char bp)
-         (unless shr-kinsoku-shorten
+          ;; Don't overflow the window edge, even if
+          ;; shr-kinsoku-shorten is nil.
+         (unless (or shr-kinsoku-shorten (null shr-width))
            (while (setq found (re-search-forward
                                "\\(\\c>\\)\\| \\|\\c<\\|\\c|"
                                (line-end-position) 'move)))
@@ -632,9 +662,12 @@ size, and full-buffer size."
        ;; Don't put kinsoku-bol characters at the beginning of a line,
        ;; or kinsoku-eol characters at the end of a line.
        (cond
-       (shr-kinsoku-shorten
+        ;; Don't overflow the window edge, even if shr-kinsoku-shorten
+        ;; is nil.
+       ((or shr-kinsoku-shorten (null shr-width))
         (while (and (not (memq (preceding-char) (list ?\C-@ ?\n ? )))
-                    (shr-char-kinsoku-eol-p (preceding-char)))
+                    (or (shr-char-kinsoku-eol-p (preceding-char))
+                         (shr-char-kinsoku-bol-p (following-char))))
           (backward-char 1))
         (when (setq failed (<= (point) start))
           ;; There's no breakable point that doesn't violate kinsoku,
@@ -1042,7 +1075,7 @@ ones, in case fg and bg are nil."
                (shr-color-visible bg fg)))))))
 
 (defun shr-colorize-region (start end fg &optional bg)
-  (when (or fg bg)
+  (when (and (or fg bg) (>= (display-color-cells) 88))
     (let ((new-colors (shr-color-check fg bg)))
       (when new-colors
        (when fg
@@ -2050,8 +2083,4 @@ The preference is a float determined from `shr-prefer-media-type'."
 
 (provide 'shr)
 
-;; Local Variables:
-;; coding: utf-8
-;; End:
-
 ;;; shr.el ends here