From 52bb6f2d832e6a2bfb851a1b53edee14c4049b3d Mon Sep 17 00:00:00 2001 From: jao Date: Tue, 16 Aug 2022 22:52:55 +0100 Subject: w3m/notmuch: toggle images --- custom/jao-custom-w3m.el | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) (limited to 'custom') diff --git a/custom/jao-custom-w3m.el b/custom/jao-custom-w3m.el index 51272ca..0ccd37c 100644 --- a/custom/jao-custom-w3m.el +++ b/custom/jao-custom-w3m.el @@ -26,7 +26,8 @@ (defun jao-w3m-html-renderer (handle) (let ((w3m-message-silent t) (w3m-fill-column 120) - (mm-w3m-safe-url-regexp nil)) + (mm-w3m-safe-url-regexp nil) + (mm-inline-text-html-with-w3m-keymap t)) (condition-case e (mm-inline-text-html-render-with-w3m handle) (error (message "Error rendering page with w3m: %s" e) @@ -36,6 +37,31 @@ (setq mm-text-html-renderer 'jao-w3m-html-renderer) +;;; notmuch integration +(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)))) + +(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))))) + +(add-hook 'notmuch-show-mode-hook #'jao-notmuch--setup-w3m-images) + ;;; org integration (defun jao-w3m-get-link () (let ((wb (w3m-alive-p))) -- cgit v1.2.3