From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Ralph Schleicher Newsgroups: gmane.emacs.bugs Subject: bug#47705: [PATCH] EWW: Customize display of images Date: Sun, 11 Apr 2021 12:15:37 +0200 Organization: Ralph Schleicher Message-ID: <86zgy5m8ja.fsf@lima.oberreute.mueller-schleicher.de> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="31594"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) To: 47705@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Apr 11 12:16:26 2021 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lVX8i-000864-Uc for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 11 Apr 2021 12:16:25 +0200 Original-Received: from localhost ([::1]:49664 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lVX8h-0005pV-VQ for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 11 Apr 2021 06:16:23 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:57712) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lVX8M-0005pA-3N for bug-gnu-emacs@gnu.org; Sun, 11 Apr 2021 06:16:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:42512) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lVX8L-0004Go-Rv for bug-gnu-emacs@gnu.org; Sun, 11 Apr 2021 06:16:01 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1lVX8L-0005wT-OK for bug-gnu-emacs@gnu.org; Sun, 11 Apr 2021 06:16:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Ralph Schleicher Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 11 Apr 2021 10:16:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 47705 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.161813615722827 (code B ref -1); Sun, 11 Apr 2021 10:16:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 11 Apr 2021 10:15:57 +0000 Original-Received: from localhost ([127.0.0.1]:54058 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lVX8H-0005w6-Cu for submit@debbugs.gnu.org; Sun, 11 Apr 2021 06:15:57 -0400 Original-Received: from lists.gnu.org ([209.51.188.17]:51276) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lVX8G-0005vz-A8 for submit@debbugs.gnu.org; Sun, 11 Apr 2021 06:15:56 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:57710) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lVX8F-0005p0-Pw for bug-gnu-emacs@gnu.org; Sun, 11 Apr 2021 06:15:56 -0400 Original-Received: from dd22110.kasserver.com ([85.13.141.233]:45380) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lVX88-00047u-7A for bug-gnu-emacs@gnu.org; Sun, 11 Apr 2021 06:15:55 -0400 Original-Received: from charlie.oberreute.mueller-schleicher.de (dslb-094-216-126-070.094.216.pools.vodafone-ip.de [94.216.126.70]) by dd22110.kasserver.com (Postfix) with ESMTPA id ED59E1802CC for ; Sun, 11 Apr 2021 12:15:37 +0200 (CEST) Original-Received: from lima.oberreute.mueller-schleicher.de (lima.oberreute.mueller-schleicher.de [192.168.23.12]) by charlie.oberreute.mueller-schleicher.de (Postfix) with ESMTP id 756492050D for ; Sun, 11 Apr 2021 12:15:37 +0200 (CEST) Original-Received: by lima.oberreute.mueller-schleicher.de (Postfix, from userid 1001) id 2C57D4A03C1; Sun, 11 Apr 2021 12:15:37 +0200 (CEST) Received-SPF: none client-ip=85.13.141.233; envelope-from=rs@ralph-schleicher.de; helo=dd22110.kasserver.com X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:203838 Archived-At: --=-=-= Content-Type: text/plain 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. --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-EWW-Customize-display-of-images.patch >From 8105b1db4328f212608998bf71187ba196e2205b Mon Sep 17 00:00:00 2001 From: Ralph Schleicher 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 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 --=-=-= Content-Type: text/plain -- Ralph --=-=-=--