emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 02bad11 2/2: Add support for a shr-max-width variable


From: Lars Ingebrigtsen
Subject: master 02bad11 2/2: Add support for a shr-max-width variable
Date: Fri, 17 Jul 2020 09:45:37 -0400 (EDT)

branch: master
commit 02bad11288d630595de7e088584d3f8b60cac676
Author: Lars Ingebrigtsen <larsi@gnus.org>
Commit: Lars Ingebrigtsen <larsi@gnus.org>

    Add support for a shr-max-width variable
    
    * doc/misc/eww.texi (Advanced): Document it.
    
    * lisp/net/shr.el (shr-max-width): Add new variable (bug#40909).
    (shr-insert-document): Use it.
---
 doc/misc/eww.texi |  8 ++++++++
 etc/NEWS          |  8 ++++++++
 lisp/net/shr.el   | 27 ++++++++++++++++++++++++++-
 3 files changed, 42 insertions(+), 1 deletion(-)

diff --git a/doc/misc/eww.texi b/doc/misc/eww.texi
index e3191cb..9bca0fa 100644
--- a/doc/misc/eww.texi
+++ b/doc/misc/eww.texi
@@ -283,6 +283,14 @@ contrast.  If that is still too low for you, you can 
customize the
 variables @code{shr-color-visible-distance-min} and
 @code{shr-color-visible-luminance-min} to get a better contrast.
 
+@vindex shr-max-width
+@vindex shr-width
+  By default, the max width used when rendering is 120 characters, but
+this can be adjusted by changing the @code{shr-max-width} variable.
+If a specified width is preferred no matter what the width of the
+window is, @code{shr-width} can be set.  If both variables are
+@code{nil}, the window width will always be used.
+
 @vindex shr-discard-aria-hidden
 @cindex @code{aria-hidden}, HTML attribute
   The HTML attribute @code{aria-hidden} is meant to tell screen
diff --git a/etc/NEWS b/etc/NEWS
index 4fdfcf9..b3ad562 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -478,6 +478,14 @@ other function, it will now be called instead of the 
default.
 
 ** EWW
 
++++
+*** New variable 'shr-max-width'
+This defaults to 120 characters, which means that even if you have
+very wide frames, HTML text will be rendered more narrowly, which
+usually leads to a more readable text.  If nil, 'shr-width' is adhered
+to as before, and as that defaults to nil, the window width is always
+used.
+
 ---
 *** The command 'eww-follow-link' now supports custom mailto handlers.
 The function that is invoked when clicking on or otherwise following a
diff --git a/lisp/net/shr.el b/lisp/net/shr.el
index daaed3b..d6bdb4c 100644
--- a/lisp/net/shr.el
+++ b/lisp/net/shr.el
@@ -99,11 +99,28 @@ If nil, don't draw horizontal table lines."
 May either be an integer specifying a fixed width in characters,
 or nil, meaning that the full width of the window should be used.
 If `shr-use-fonts' is set, the mean character width is used to
-compute the pixel width, which is used instead."
+compute the pixel width, which is used instead.
+
+Also see `shr-max-width'."
   :version "25.1"
   :type '(choice (integer :tag "Fixed width in characters")
                 (const   :tag "Use the width of the window" nil)))
 
+(defcustom shr-max-width 120
+  "Maximum text width to use for rendering.
+May either be an intereger specifying a fixed width in characters,
+or nil, meaning that there is no maximum width.
+
+If `shr-use-fonts' is set, the mean character width is used to
+compute the pixel width, which is used instead.
+
+Also see `shr-width'.  If `shr-width' is set, it overrides
+`shr-max-width', and if `shr-width' is nil, the frame width is
+used to compute the width to use."
+  :version "28.1"
+  :type '(choice (integer :tag "Fixed width in characters")
+                (const :tag "No maximum width" nil)))
+
 (defcustom shr-bullet "* "
   "Bullet used for unordered lists.
 Alternative suggestions are:
@@ -290,6 +307,14 @@ DOM should be a parse tree as generated by
                 1))))
         (max-specpdl-size max-specpdl-size)
         bidi-display-reordering)
+    ;; Adjust for max width specification.
+    (when (and shr-max-width
+               (not shr-width))
+      (setq shr-internal-width
+            (min shr-internal-width
+                 (if shr-use-fonts
+                     (* shr-max-width (frame-char-width))
+                   shr-max-width))))
     ;; If the window was hscrolled for some reason, shr-fill-lines
     ;; below will misbehave, because it silently assumes that it
     ;; starts with a non-hscrolled window (vertical-motion will move



reply via email to

[Prev in Thread] Current Thread [Next in Thread]