all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#50383: 28.0.50; [PATCH] Feature suggestion, gnus-article-toggle-fonts to toggle fonts for HTML articles
@ 2021-09-04 20:54 Alex Bochannek
  2021-09-05  1:18 ` Alex Bochannek
  2021-09-05 10:06 ` Lars Ingebrigtsen
  0 siblings, 2 replies; 8+ messages in thread
From: Alex Bochannek @ 2021-09-04 20:54 UTC (permalink / raw)
  To: 50383

[-- Attachment #1: Type: text/plain, Size: 636 bytes --]

Hello!

A while back I turned off `shr-use-fonts' for my HTML email but found
that occasionally proportional fonts are useful when reading my
messages.

I am proposing the below `gnus-article-toggle-fonts' function with a
keybinding of `W D F'.

	New Gnus article washing option to toggle HTML fonts

	* lisp/gnus/gnus-sum.el (gnus-summary-wash-display-map): 
	(gnus-summary-make-menu-bar): Add mode mapping and menu item for
	article HTML font toggle.

	* lisp/gnus/gnus-art.el (gnus-article-toggle-fonts): Toggle
	shr-use-fonts and redisplay message.

	* doc/misc/gnus.texi (Article Washing): Document new HTML font
	toggle function.

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Type: text/x-patch, Size: 2378 bytes --]

diff --git a/doc/misc/gnus.texi b/doc/misc/gnus.texi
index 5f3fba00df..c8aec4eea1 100644
--- a/doc/misc/gnus.texi
+++ b/doc/misc/gnus.texi
@@ -9374,6 +9374,12 @@ Article Washing
 
 @end table
 
+@item W D F
+@kindex W D F @r{(Summary)}
+@findex gnus-article-toggle-fonts
+Toggle proportional fonts for @acronym{HTML} articles.  This temporarily
+changes the @code{shr-use-fonts} variable in the current buffer.
+
 @item W b
 @kindex W b @r{(Summary)}
 @findex gnus-article-add-buttons
diff --git a/lisp/gnus/gnus-art.el b/lisp/gnus/gnus-art.el
index 3c1403e155..7f48191085 100644
--- a/lisp/gnus/gnus-art.el
+++ b/lisp/gnus/gnus-art.el
@@ -2243,6 +2243,19 @@ gnus-article-show-images
 	    (funcall function (get-text-property start 'image-url)
 		     start end)))))))
 
+(defun gnus-article-toggle-fonts ()
+  "Toggle the use of proportional fonts for HTML articles."
+  (interactive nil gnus-article-mode gnus-summary-mode)
+  (gnus-with-article-buffer
+    (if (eq mm-text-html-renderer 'shr)
+        (progn
+          (if (not (local-variable-p 'gnus-article-shr-use-fonts))
+              (setq-local gnus-article-shr-use-fonts shr-use-fonts))
+          (setq-local gnus-article-shr-use-fonts
+                      (not gnus-article-shr-use-fonts))
+          (let ((shr-use-fonts gnus-article-shr-use-fonts))
+            (gnus-summary-show-article))))))
+
 (defun gnus-article-treat-fold-newsgroups ()
   "Fold the Newsgroups and Followup-To message headers."
   (interactive nil gnus-article-mode gnus-summary-mode)
diff --git a/lisp/gnus/gnus-sum.el b/lisp/gnus/gnus-sum.el
index 856e95c0ba..c28e38e315 100644
--- a/lisp/gnus/gnus-sum.el
+++ b/lisp/gnus/gnus-sum.el
@@ -2252,6 +2252,7 @@ gnus-summary-mode-map
   "s" gnus-treat-smiley
   "D" gnus-article-remove-images
   "W" gnus-article-show-images
+  "F" gnus-article-toggle-fonts
   "f" gnus-treat-from-picon
   "m" gnus-treat-mail-picon
   "n" gnus-treat-newsgroups-picon
@@ -2561,6 +2562,7 @@ gnus-summary-make-menu-bar
 	      ["Unfold headers" gnus-article-treat-unfold-headers t]
 	      ["Fold newsgroups" gnus-article-treat-fold-newsgroups t]
 	      ["Html" gnus-article-wash-html t]
+	      ["Toggle HTML fonts" gnus-article-toggle-fonts t]
 	      ["Unsplit URLs" gnus-article-unsplit-urls t]
 	      ["Verify X-PGP-Sig" gnus-article-verify-x-pgp-sig t]
 	      ["Decode HZ" gnus-article-decode-HZ t]

[-- Attachment #3: Type: text/plain, Size: 10 bytes --]

-- 
Alex.

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* bug#50383: 28.0.50; [PATCH] Feature suggestion, gnus-article-toggle-fonts to toggle fonts for HTML articles
  2021-09-04 20:54 bug#50383: 28.0.50; [PATCH] Feature suggestion, gnus-article-toggle-fonts to toggle fonts for HTML articles Alex Bochannek
@ 2021-09-05  1:18 ` Alex Bochannek
  2021-09-05 10:06 ` Lars Ingebrigtsen
  1 sibling, 0 replies; 8+ messages in thread
From: Alex Bochannek @ 2021-09-05  1:18 UTC (permalink / raw)
  To: 50383

[-- Attachment #1: Type: text/plain, Size: 596 bytes --]

Alex Bochannek <alex@bochannek.com> writes:

> Hello!
>
> A while back I turned off `shr-use-fonts' for my HTML email but found
> that occasionally proportional fonts are useful when reading my
> messages.
>
> I am proposing the below `gnus-article-toggle-fonts' function with a
> keybinding of `W D F'.

The patch did not keep the fonts toggled when selecting the next message
or reloading the current one. I am proposing the below change. I am not
sure how you feel about buffer-local Gnus variables in `mm-decode.el',
so please let me know if an alternative approach would be better.

Thanks!

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Type: text/x-patch, Size: 605 bytes --]

diff --git a/lisp/gnus/mm-decode.el b/lisp/gnus/mm-decode.el
index 82d1de25f3..5c5896446e 100644
--- a/lisp/gnus/mm-decode.el
+++ b/lisp/gnus/mm-decode.el
@@ -1843,6 +1843,9 @@ mm-shr
 				      (buffer-string))))))
 	(shr-inhibit-images mm-html-inhibit-images)
 	(shr-blocked-images mm-html-blocked-images)
+	(shr-use-fonts (if (local-variable-p 'gnus-article-shr-use-fonts)
+                           gnus-article-shr-use-fonts
+                         shr-use-fonts))
 	charset coding char document)
     (mm-with-part (or handle (setq handle (mm-dissect-buffer t)))
       (setq case-fold-search t)

[-- Attachment #3: Type: text/plain, Size: 10 bytes --]

-- 
Alex.

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* bug#50383: 28.0.50; [PATCH] Feature suggestion, gnus-article-toggle-fonts to toggle fonts for HTML articles
  2021-09-04 20:54 bug#50383: 28.0.50; [PATCH] Feature suggestion, gnus-article-toggle-fonts to toggle fonts for HTML articles Alex Bochannek
  2021-09-05  1:18 ` Alex Bochannek
@ 2021-09-05 10:06 ` Lars Ingebrigtsen
  2021-09-06  5:22   ` Alex Bochannek
  1 sibling, 1 reply; 8+ messages in thread
From: Lars Ingebrigtsen @ 2021-09-05 10:06 UTC (permalink / raw)
  To: Alex Bochannek; +Cc: 50383

Alex Bochannek <alex@bochannek.com> writes:

> I am proposing the below `gnus-article-toggle-fonts' function with a
> keybinding of `W D F'.

Sounds good to me.


[...]

> +          (setq-local gnus-article-shr-use-fonts
> +                      (not gnus-article-shr-use-fonts))

[...]

> The patch did not keep the fonts toggled when selecting the next message
> or reloading the current one. I am proposing the below change. I am not
> sure how you feel about buffer-local Gnus variables in `mm-decode.el',
> so please let me know if an alternative approach would be better.

Yeah, it would be best to avoid doing that.  How about changing the
patch to have a buffer-local `shr-use-fonts' in the Gnus article buffer
and use that instead?

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





^ permalink raw reply	[flat|nested] 8+ messages in thread

* bug#50383: 28.0.50; [PATCH] Feature suggestion, gnus-article-toggle-fonts to toggle fonts for HTML articles
  2021-09-05 10:06 ` Lars Ingebrigtsen
@ 2021-09-06  5:22   ` Alex Bochannek
  2021-09-06  8:35     ` Lars Ingebrigtsen
  0 siblings, 1 reply; 8+ messages in thread
From: Alex Bochannek @ 2021-09-06  5:22 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: 50383

[-- Attachment #1: Type: text/plain, Size: 838 bytes --]

Lars Ingebrigtsen <larsi@gnus.org> writes:

> Alex Bochannek <alex@bochannek.com> writes:
>
>> I am proposing the below `gnus-article-toggle-fonts' function with a
>> keybinding of `W D F'.
>
> Sounds good to me.
>
>
> [...]
>
>> +          (setq-local gnus-article-shr-use-fonts
>> +                      (not gnus-article-shr-use-fonts))
>
> [...]
>
>> The patch did not keep the fonts toggled when selecting the next message
>> or reloading the current one. I am proposing the below change. I am not
>> sure how you feel about buffer-local Gnus variables in `mm-decode.el',
>> so please let me know if an alternative approach would be better.
>
> Yeah, it would be best to avoid doing that.  How about changing the
> patch to have a buffer-local `shr-use-fonts' in the Gnus article buffer
> and use that instead?

Just like this then?

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Type: text/x-patch, Size: 1228 bytes --]

diff --git a/lisp/gnus/gnus-art.el b/lisp/gnus/gnus-art.el
index 3c1403e155..05d0be8ca2 100644
--- a/lisp/gnus/gnus-art.el
+++ b/lisp/gnus/gnus-art.el
@@ -2243,6 +2243,15 @@ gnus-article-show-images
 	    (funcall function (get-text-property start 'image-url)
 		     start end)))))))
 
+(defun gnus-article-toggle-fonts ()
+  "Toggle the use of proportional fonts for HTML articles."
+  (interactive nil gnus-article-mode gnus-summary-mode)
+  (gnus-with-article-buffer
+    (if (eq mm-text-html-renderer 'shr)
+        (progn
+          (setq-local shr-use-fonts (not shr-use-fonts))
+          (gnus-summary-show-article)))))
+
 (defun gnus-article-treat-fold-newsgroups ()
   "Fold the Newsgroups and Followup-To message headers."
   (interactive nil gnus-article-mode gnus-summary-mode)
@@ -4494,6 +4503,8 @@ gnus-article-mode
   (setq-local nobreak-char-display nil)
   ;; Enable `gnus-article-remove-images' to delete images shr.el renders.
   (setq-local shr-put-image-function #'gnus-shr-put-image)
+  ;; Shadow global shr-use-fonts to support font toggling.
+  (setq-local shr-use-fonts shr-use-fonts)
   (unless gnus-article-show-cursor
     (setq cursor-in-non-selected-windows nil))
   (gnus-set-default-directory)

[-- Attachment #3: Type: text/plain, Size: 10 bytes --]

-- 
Alex.

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* bug#50383: 28.0.50; [PATCH] Feature suggestion, gnus-article-toggle-fonts to toggle fonts for HTML articles
  2021-09-06  5:22   ` Alex Bochannek
@ 2021-09-06  8:35     ` Lars Ingebrigtsen
  2021-09-06 22:41       ` Alex Bochannek
  0 siblings, 1 reply; 8+ messages in thread
From: Lars Ingebrigtsen @ 2021-09-06  8:35 UTC (permalink / raw)
  To: Alex Bochannek; +Cc: 50383

Alex Bochannek <alex@bochannek.com> writes:

> Just like this then?

Yup, if that does indeed work.  :-)

> +  ;; Shadow global shr-use-fonts to support font toggling.
> +  (setq-local shr-use-fonts shr-use-fonts)

But perhaps this should be set only if the user uses this command.  Can
you respin the entire patch and we'll get it applied...

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





^ permalink raw reply	[flat|nested] 8+ messages in thread

* bug#50383: 28.0.50; [PATCH] Feature suggestion, gnus-article-toggle-fonts to toggle fonts for HTML articles
  2021-09-06  8:35     ` Lars Ingebrigtsen
@ 2021-09-06 22:41       ` Alex Bochannek
  2021-09-07 15:13         ` Lars Ingebrigtsen
  0 siblings, 1 reply; 8+ messages in thread
From: Alex Bochannek @ 2021-09-06 22:41 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: 50383

[-- Attachment #1: Type: text/plain, Size: 1047 bytes --]

Lars Ingebrigtsen <larsi@gnus.org> writes:

> Alex Bochannek <alex@bochannek.com> writes:
>
>> Just like this then?
>
> Yup, if that does indeed work.  :-)
>
>> +  ;; Shadow global shr-use-fonts to support font toggling.
>> +  (setq-local shr-use-fonts shr-use-fonts)
>
> But perhaps this should be set only if the user uses this command.  Can
> you respin the entire patch and we'll get it applied...

I thought about it some more and I don't think it's necessary at all to
initialize the local variable, because it will happen automatically the
first time the command is used. The below should be enough. I tested it
a bit and it works for me.

	New Gnus article washing function to toggle HTML fonts

	* lisp/gnus/gnus-sum.el (gnus-summary-wash-display-map),
	(gnus-summary-make-menu-bar): Add mode mapping and menu item for
	article HTML font toggle.

	* lisp/gnus/gnus-art.el (gnus-article-toggle-fonts): Toggle
	shr-use-fonts and redisplay message.

	* doc/misc/gnus.texi (Article Washing): Document new HTML font
	toggle function.

Thanks!

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Type: text/x-patch, Size: 2127 bytes --]

diff --git a/doc/misc/gnus.texi b/doc/misc/gnus.texi
index 5f3fba00df..c8aec4eea1 100644
--- a/doc/misc/gnus.texi
+++ b/doc/misc/gnus.texi
@@ -9374,6 +9374,12 @@ Article Washing
 
 @end table
 
+@item W D F
+@kindex W D F @r{(Summary)}
+@findex gnus-article-toggle-fonts
+Toggle proportional fonts for @acronym{HTML} articles.  This temporarily
+changes the @code{shr-use-fonts} variable in the current buffer.
+
 @item W b
 @kindex W b @r{(Summary)}
 @findex gnus-article-add-buttons
diff --git a/lisp/gnus/gnus-art.el b/lisp/gnus/gnus-art.el
index 3c1403e155..a962b06372 100644
--- a/lisp/gnus/gnus-art.el
+++ b/lisp/gnus/gnus-art.el
@@ -2243,6 +2243,15 @@ gnus-article-show-images
 	    (funcall function (get-text-property start 'image-url)
 		     start end)))))))
 
+(defun gnus-article-toggle-fonts ()
+  "Toggle the use of proportional fonts for HTML articles."
+  (interactive nil gnus-article-mode gnus-summary-mode)
+  (gnus-with-article-buffer
+    (if (eq mm-text-html-renderer 'shr)
+        (progn
+          (setq-local shr-use-fonts (not shr-use-fonts))
+          (gnus-summary-show-article)))))
+
 (defun gnus-article-treat-fold-newsgroups ()
   "Fold the Newsgroups and Followup-To message headers."
   (interactive nil gnus-article-mode gnus-summary-mode)
diff --git a/lisp/gnus/gnus-sum.el b/lisp/gnus/gnus-sum.el
index 856e95c0ba..c28e38e315 100644
--- a/lisp/gnus/gnus-sum.el
+++ b/lisp/gnus/gnus-sum.el
@@ -2252,6 +2252,7 @@ gnus-summary-mode-map
   "s" gnus-treat-smiley
   "D" gnus-article-remove-images
   "W" gnus-article-show-images
+  "F" gnus-article-toggle-fonts
   "f" gnus-treat-from-picon
   "m" gnus-treat-mail-picon
   "n" gnus-treat-newsgroups-picon
@@ -2561,6 +2562,7 @@ gnus-summary-make-menu-bar
 	      ["Unfold headers" gnus-article-treat-unfold-headers t]
 	      ["Fold newsgroups" gnus-article-treat-fold-newsgroups t]
 	      ["Html" gnus-article-wash-html t]
+	      ["Toggle HTML fonts" gnus-article-toggle-fonts t]
 	      ["Unsplit URLs" gnus-article-unsplit-urls t]
 	      ["Verify X-PGP-Sig" gnus-article-verify-x-pgp-sig t]
 	      ["Decode HZ" gnus-article-decode-HZ t]

[-- Attachment #3: Type: text/plain, Size: 10 bytes --]

-- 
Alex.

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* bug#50383: 28.0.50; [PATCH] Feature suggestion, gnus-article-toggle-fonts to toggle fonts for HTML articles
  2021-09-06 22:41       ` Alex Bochannek
@ 2021-09-07 15:13         ` Lars Ingebrigtsen
  2021-09-07 17:15           ` Alex Bochannek
  0 siblings, 1 reply; 8+ messages in thread
From: Lars Ingebrigtsen @ 2021-09-07 15:13 UTC (permalink / raw)
  To: Alex Bochannek; +Cc: 50383

Alex Bochannek <alex@bochannek.com> writes:

> I thought about it some more and I don't think it's necessary at all to
> initialize the local variable, because it will happen automatically the
> first time the command is used. The below should be enough. I tested it
> a bit and it works for me.

Thanks, looks good to me, so I've pushed it to Emacs 28 (with a trivial
change -- I morphed the `(if ..  (progn' into a `when').

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





^ permalink raw reply	[flat|nested] 8+ messages in thread

* bug#50383: 28.0.50; [PATCH] Feature suggestion, gnus-article-toggle-fonts to toggle fonts for HTML articles
  2021-09-07 15:13         ` Lars Ingebrigtsen
@ 2021-09-07 17:15           ` Alex Bochannek
  0 siblings, 0 replies; 8+ messages in thread
From: Alex Bochannek @ 2021-09-07 17:15 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: 50383

Lars Ingebrigtsen <larsi@gnus.org> writes:

> Alex Bochannek <alex@bochannek.com> writes:
>
>> I thought about it some more and I don't think it's necessary at all to
>> initialize the local variable, because it will happen automatically the
>> first time the command is used. The below should be enough. I tested it
>> a bit and it works for me.
>
> Thanks, looks good to me, so I've pushed it to Emacs 28 (with a trivial
> change -- I morphed the `(if ..  (progn' into a `when').

Thanks! I keep forgetting that the `when' macro has an implicit `progn',
which also reads nicer.

-- 
Alex.





^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2021-09-07 17:15 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-09-04 20:54 bug#50383: 28.0.50; [PATCH] Feature suggestion, gnus-article-toggle-fonts to toggle fonts for HTML articles Alex Bochannek
2021-09-05  1:18 ` Alex Bochannek
2021-09-05 10:06 ` Lars Ingebrigtsen
2021-09-06  5:22   ` Alex Bochannek
2021-09-06  8:35     ` Lars Ingebrigtsen
2021-09-06 22:41       ` Alex Bochannek
2021-09-07 15:13         ` Lars Ingebrigtsen
2021-09-07 17:15           ` Alex Bochannek

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.