From fb3a9c806f4e76059094d333dfb57f7026abec77 Mon Sep 17 00:00:00 2001 From: jao Date: Fri, 31 Dec 2021 13:15:40 +0000 Subject: otmuch nits and better eww image activation --- lib/net/jao-notmuch.el | 52 +++++++++++++++++++++++++++++--------------------- 1 file changed, 30 insertions(+), 22 deletions(-) (limited to 'lib') diff --git a/lib/net/jao-notmuch.el b/lib/net/jao-notmuch.el index fd5df2c..320dac7 100644 --- a/lib/net/jao-notmuch.el +++ b/lib/net/jao-notmuch.el @@ -189,31 +189,39 @@ (defvar-local jao-notmuch--showing-images nil) (defun jao-notmuch--setup-w3m-images (&optional activate) - (setq-local w3m-ignored-image-url-regexp - (unless jao-notmuch--showing-images - notmuch-show-text/html-blocked-images)) - (when activate - (setq-local scroll-margin 0) - (w3m-toggle-inline-images (if jao-notmuch--showing-images t 'turnoff)))) + (when (eq mm-text-html-renderer 'w3m) + (setq-local w3m-ignored-image-url-regexp + (unless jao-notmuch--showing-images + notmuch-show-text/html-blocked-images)) + (when activate + (setq-local scroll-margin 0) + (w3m-toggle-inline-images (if jao-notmuch--showing-images t 'turnoff))))) + +(defun jao-notmuch--w3m-toggle-images () + (save-window-excursion + (when (or (derived-mode-p 'notmuch-show-mode) + (jao-notmuch-goto-message-buffer nil t)) + (goto-char (point-min)) + (when (re-search-forward "^\\[ text/html " nil t) + (when (looking-at-p "(hidden)") + (notmuch-show-toggle-part-invisibility)) + (forward-line 1) + (setq jao-notmuch--showing-images (not jao-notmuch--showing-images)) + (jao-notmuch--setup-w3m-images 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-tree-show-message nil))) (defun jao-notmuch-show-images () (interactive) - (if (eq mm-text-html-renderer 'shr) - (let ((shr-blocked-images nil) - (shr-inhibit-images nil) - (notmuch-show-text/html-blocked-images nil)) - (notmuch-tree-close-message-window) - (notmuch-tree-show-message nil)) - (save-window-excursion - (when (or (derived-mode-p 'notmuch-show-mode) - (jao-notmuch-goto-message-buffer nil t)) - (goto-char (point-min)) - (when (re-search-forward "^\\[ text/html " nil t) - (when (looking-at-p "(hidden)") - (notmuch-show-toggle-part-invisibility)) - (forward-line 1) - (setq jao-notmuch--showing-images (not jao-notmuch--showing-images)) - (jao-notmuch--setup-w3m-images t)))))) + (if (eq mm-text-html-renderer 'w3m) + (jao-notmuch--w3m-toggle-images) + (jao-notmuch--shr-toggle-images))) (add-hook 'notmuch-show-mode-hook #'jao-notmuch--setup-w3m-images) -- cgit v1.2.3