From: Ralph Schleicher <rs@ralph-schleicher.de>
To: 47705@debbugs.gnu.org
Subject: bug#47705: [PATCH] EWW: Customize display of images
Date: Sun, 11 Apr 2021 12:15:37 +0200 [thread overview]
Message-ID: <86zgy5m8ja.fsf@lima.oberreute.mueller-schleicher.de> (raw)
[-- Attachment #1: Type: text/plain, Size: 327 bytes --]
EWW already supports displaying web pages with ALT texts instead of
images but this feature is not visible to the user. Additionally,
images or ALT texts are always displayed on a line by itself. This
may waste a lot of vertical space, e.g. when displaying the Common
Lisp HyperSpec. The attached patch fixes these issues.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-EWW-Customize-display-of-images.patch --]
[-- Type: text/x-diff, Size: 4995 bytes --]
From 8105b1db4328f212608998bf71187ba196e2205b Mon Sep 17 00:00:00 2001
From: Ralph Schleicher <rs@ralph-schleicher.de>
Date: Sat, 10 Apr 2021 23:08:27 +0200
Subject: [PATCH] EWW: Customize display of images
* lisp/net/eww.el (eww-toggle-images): New function.
(eww-mode-map): Add key binding and menu entry.
* lisp/net/shr.el (shr-inhibit-images): Make it customizable.
(shr-image-newline): New customization variable.
(shr-tag-img, shr-insert): Use shr-image-newline.
* doc/misc/eww.texi (Basics): Document eww-toggle-images.
Fix index entries for shr-use-fonts and shr-use-colors.
(Advanced): Document shr-inhibit-images and shr-image-newline.
---
doc/misc/eww.texi | 22 +++++++++++++++++++---
lisp/net/eww.el | 10 ++++++++++
lisp/net/shr.el | 15 +++++++++++----
3 files changed, 40 insertions(+), 7 deletions(-)
diff --git a/doc/misc/eww.texi b/doc/misc/eww.texi
index 6e82a97030..0ec3b4bf6e 100644
--- a/doc/misc/eww.texi
+++ b/doc/misc/eww.texi
@@ -124,17 +124,25 @@ Basics
only display this part. This usually gets rid of menus and the like.
@findex eww-toggle-fonts
-@findex shr-use-fonts
+@vindex shr-use-fonts
@kindex F
The @kbd{F} command (@code{eww-toggle-fonts}) toggles whether to use
variable-pitch fonts or not. This sets the @code{shr-use-fonts} variable.
@findex eww-toggle-colors
-@findex shr-use-colors
-@kindex F
+@vindex shr-use-colors
+@kindex M-C
The @kbd{M-C} command (@code{eww-toggle-colors}) toggles whether to use
HTML-specified colors or not. This sets the @code{shr-use-colors} variable.
+@findex eww-toggle-images
+@vindex shr-inhibit-images
+@kindex M-I
+@cindex Image Display
+ The @kbd{M-I} command (@code{eww-toggle-images}, capital letter i)
+toggles whether to display images or not. This sets the
+@code{shr-inhibit-images} variable.
+
@findex eww-download
@vindex eww-download-directory
@kindex d
@@ -305,6 +313,14 @@ Advanced
support required) then larger images are scaled down. You can block
specific images completely by customizing @code{shr-blocked-images}.
+@vindex shr-inhibit-images
+@vindex shr-image-newline
+ You can control image display by customizing
+@code{shr-inhibit-images}. If this variable is nil, always display
+the ALT text of images. Images or ALT texts are displayed on a
+separate line by default. You can preserve the normal text flow by
+setting the variable @code{shr-image-newline} to nil.
+
@vindex shr-color-visible-distance-min
@vindex shr-color-visible-luminance-min
@cindex Contrast
diff --git a/lisp/net/eww.el b/lisp/net/eww.el
index 32fe857e65..eec3ec7ba8 100644
--- a/lisp/net/eww.el
+++ b/lisp/net/eww.el
@@ -987,6 +987,7 @@ eww-mode-map
(define-key map "F" 'eww-toggle-fonts)
(define-key map "D" 'eww-toggle-paragraph-direction)
(define-key map [(meta C)] 'eww-toggle-colors)
+ (define-key map [(meta I)] 'eww-toggle-images)
(define-key map "b" 'eww-add-bookmark)
(define-key map "B" 'eww-list-bookmarks)
@@ -1015,6 +1016,7 @@ eww-mode-map
["List cookies" url-cookie-list t]
["Toggle fonts" eww-toggle-fonts t]
["Toggle colors" eww-toggle-colors t]
+ ["Toggle images" eww-toggle-images t]
["Character Encoding" eww-set-character-encoding]
["Toggle Paragraph Direction" eww-toggle-paragraph-direction]))
map))
@@ -1893,6 +1895,14 @@ eww-toggle-colors
"off"))
(eww-reload))
+(defun eww-toggle-images ()
+ "Toggle whether or not to display images."
+ (interactive nil eww-mode)
+ (setq shr-inhibit-images (not shr-inhibit-images))
+ (eww-reload)
+ (message "Images are now %s"
+ (if shr-inhibit-images "off" "on")))
+
;;; Bookmarks code
(defvar eww-bookmarks nil)
diff --git a/lisp/net/shr.el b/lisp/net/shr.el
index c122a19e90..4332a1ef15 100644
--- a/lisp/net/shr.el
+++ b/lisp/net/shr.el
@@ -183,8 +183,13 @@ shr-abbreviation
"Face for <abbr> elements."
:version "27.1")
-(defvar shr-inhibit-images nil
- "If non-nil, inhibit loading images.")
+(defcustom shr-inhibit-images nil
+ "If non-nil, inhibit loading images."
+ :type 'boolean)
+
+(defcustom shr-image-newline t
+ "If non-nil, display images on a separate line."
+ :type 'boolean)
(defvar shr-external-rendering-functions nil
"Alist of tag/function pairs used to alter how shr renders certain tags.
@@ -664,7 +669,8 @@ shr--translate-insertion-chars
(defun shr-insert (text)
(when (and (not (bolp))
- (get-text-property (1- (point)) 'image-url))
+ (get-text-property (1- (point)) 'image-url)
+ shr-image-newline)
(insert "\n"))
(cond
((eq shr-folding-mode 'none)
@@ -1654,7 +1660,8 @@ shr-tag-img
(and dom
(or (> (length (dom-attr dom 'src)) 0)
(> (length (dom-attr dom 'srcset)) 0))))
- (when (> (current-column) 0)
+ (when (and (> (current-column) 0)
+ shr-image-newline)
(insert "\n"))
(let ((alt (dom-attr dom 'alt))
(width (shr-string-number (dom-attr dom 'width)))
--
2.20.1
[-- Attachment #3: Type: text/plain, Size: 10 bytes --]
--
Ralph
next reply other threads:[~2021-04-11 10:15 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-11 10:15 Ralph Schleicher [this message]
2021-04-12 8:36 ` bug#47705: [PATCH] EWW: Customize display of images Lars Ingebrigtsen
2021-04-12 17:36 ` Ralph Schleicher
2021-04-13 7:33 ` Lars Ingebrigtsen
2021-04-13 21:06 ` Ralph Schleicher
2021-04-13 22:08 ` Jose A. Ortega Ruiz
2021-04-14 8:38 ` Lars Ingebrigtsen
2021-04-14 19:27 ` Ralph Schleicher
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=86zgy5m8ja.fsf@lima.oberreute.mueller-schleicher.de \
--to=rs@ralph-schleicher.de \
--cc=47705@debbugs.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).