From ec873bca5cfebe194b56ac03e4b760cf63f2156c Mon Sep 17 00:00:00 2001
From: jao <jao@gnu.org>
Date: Thu, 20 Jan 2022 21:35:11 +0000
Subject: jao-notmuch-toggle-images: really toggle for shr renderer

---
 lib/net/jao-notmuch.el | 26 +++++++++++++++++---------
 1 file changed, 17 insertions(+), 9 deletions(-)

(limited to 'lib')

diff --git a/lib/net/jao-notmuch.el b/lib/net/jao-notmuch.el
index 8ff6053..b4c587e 100644
--- a/lib/net/jao-notmuch.el
+++ b/lib/net/jao-notmuch.el
@@ -174,16 +174,24 @@
     (jao-notmuch--toggle-mime)
     (jao-notmuch-goto-tree-buffer t)))
 
-(defun jao-notmuch--shr-toggle-images ()
-  (notmuch-tree-close-message-window)
-  (let ((mm-text-html-renderer 'shr)
-        (shr-blocked-images nil)
-        (shr-inhibit-images nil)
-        (notmuch-show-text/html-blocked-images nil)
-        (notmuch-multipart/alternative-discouraged '("text/plain")))
-    (notmuch-tree-show-message nil)))
+(defvar-local jao-notmuch--showing-images nil)
 
-(defun jao-notmuch-show-images ()
+(defun jao-notmuch--shr-toggle-images ()
+  (let* ((b notmuch-tree-message-buffer)
+         (show (not (buffer-local-value 'jao-notmuch--showing-images b)))
+         (mm-text-html-renderer 'shr)
+         (shr-blocked-images (unless show shr-blocked-images))
+         (shr-inhibit-images (not show))
+         (notmuch-show-text/html-blocked-images
+          (unless show notmuch-show-text/html-blocked-images))
+         (notmuch-multipart/alternative-discouraged
+          (if show '("text/plain") notmuch-multipart/alternative-discouraged)))
+    (notmuch-tree-close-message-window)
+    (notmuch-tree-show-message nil)
+    (with-current-buffer notmuch-tree-message-buffer
+      (setq jao-notmuch--showing-images show))))
+
+(defun jao-notmuch-toggle-images ()
   (interactive)
   (if (eq mm-text-html-renderer 'w3m)
       (when (fboundp 'jao-notmuch--w3m-toggle-images)
-- 
cgit v1.2.3