From 21e519036f0672a95c344137800f78c38b18f761 Mon Sep 17 00:00:00 2001 From: jao Date: Mon, 26 Jul 2021 16:28:02 +0100 Subject: notmuch: simpler mime/image toggling for html emails --- lib/net/jao-notmuch.el | 49 ++++++++++++++++++++++++------------------------- notmuch.org | 10 +++++++--- 2 files changed, 31 insertions(+), 28 deletions(-) diff --git a/lib/net/jao-notmuch.el b/lib/net/jao-notmuch.el index 52e0fe8..c470682 100644 --- a/lib/net/jao-notmuch.el +++ b/lib/net/jao-notmuch.el @@ -116,13 +116,6 @@ (goto-char (previous-single-property-change pos 'w3m-href-anchor)) (backward-button 1))) -(defun jao-notmuch-show-ret () - (interactive) - (if-let (url (or (get-text-property (point) 'w3m-href-anchor) - (thing-at-point-url-at-point))) - (browse-url url) - (notmuch-show-toggle-message))) - (defun jao-w3m-get-page-urls (res) (save-excursion (goto-char (point-min)) @@ -132,24 +125,25 @@ (add-to-list 'res url t))) res))) -(defun jao-notmuch-browse-urls () - (interactive) +(defun jao-notmuch-browse-urls (&optional external) + (interactive "P") (when (or (derived-mode-p 'notmuch-show-mode) (jao-notmuch-goto-message-buffer)) - (let ((urls (jao-w3m-get-page-urls (notmuch-show--gather-urls)))) + (let ((urls (jao-w3m-get-page-urls (notmuch-show--gather-urls))) + (fn (if external browse-url-secondary-browser-function #'browse-url))) (if urls - (browse-url (completing-read "Browse URL: " urls)) + (funcall fn (completing-read "Browse URL: " urls)) (message "No URLs in this message"))))) + +;; Toggling mime parts and images + (defun jao-notmuch--toggle-mime () (save-excursion (goto-char (point-min)) - (when (forward-button 1 nil nil t) - (when (looking-at-p "\\[ multipart/alternative") - (when (looking-at-p "\\[ multipart/alternative (hidden)") - (push-button)) - (while (forward-button 1 nil nil t) - (notmuch-show-toggle-part-invisibility)))))) + (while (and (re-search-forward "^\\[ text/\\(html\\|plain\\) " nil t) + (button-at (point))) + (notmuch-show-toggle-part-invisibility)))) (defun jao-notmuch-toggle-mime-parts () (interactive) @@ -164,14 +158,19 @@ (save-window-excursion (when (and (jao-notmuch-goto-message-buffer nil t) (derived-mode-p 'notmuch-show-mode)) - (when (or mm-w3m-safe-url-regexp - notmuch-show-text/html-blocked-images) - (setq-local mm-w3m-safe-url-regexp nil - notmuch-show-text/html-blocked-images nil - shr-inhibit-images nil - shr-blocked-images nil) - (notmuch-refresh-this-buffer)) - (jao-notmuch--toggle-mime)))) + (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) + (w3m-toggle-inline-images))))) + +(defun jao-notmuch-show-ret () + (interactive) + (if-let (url (or (get-text-property (point) 'w3m-href-anchor) + (thing-at-point-url-at-point))) + (browse-url url) + (notmuch-show-toggle-message))) ;; Keeping track of unread messages in current tree view diff --git a/notmuch.org b/notmuch.org index a36be1d..ecf3dd8 100644 --- a/notmuch.org +++ b/notmuch.org @@ -76,11 +76,13 @@ ,@(jao-notmuch--mboxes-search "jao") ,(jao-notmuch--q "feeds" "papers" "fp" '("tag:papers" "tag:new")) ,(jao-notmuch--q "local" nil "l" '("tag:local" "tag:new")) + ,(jao-notmuch--q "emacs" "feeds" "ee" + '("tag:new" "tag:emacs" "not tag:\"/^emacs-/\"")) ,(jao-notmuch--q "emacs" "github" "eg" '("tag:new" "tag:emacs-github")) ,(jao-notmuch--q "emacs" "devel" "ed" '("tag:new" "tag:emacs-devel")) ,(jao-notmuch--q "emacs" "bugs" "eb" '("tag:new" "tag:emacs-bugs")) ,(jao-notmuch--q "emacs" "diffs" "ec" '("tag:new" "tag:emacs-diffs")) - ,@(jao-notmuch--mboxes-search "feeds") + ,@(jao-notmuch--mboxes-search "feeds" "emacs") ,(jao-notmuch--q "bml" "today" "tb" '("tag:bigml" "date:1d..") t) ,(jao-notmuch--q "jao" "today" "tj" '("tag:jao" "date:1d.." @@ -118,7 +120,7 @@ :init (setq notmuch-draft-folder "jao/drafts" notmuch-draft-quoted-tags '("part") - notmuch-column-control 1.0 + notmuch-column-control t ;; 1.0 notmuch-hello-sections '(notmuch-hello-insert-saved-searches notmuch-hello-insert-alltags notmuch-hello-insert-header) @@ -140,6 +142,9 @@ notmuch-wash-citation-lines-prefix 10 notmuch-wash-citation-lines-suffix 20) + (setq gnus-blocked-images ".") + (setq notmuch-show-text/html-blocked-images ".") + :config (when (eq 'notmuch jao-afio-mail-function) @@ -199,7 +204,6 @@ :demand t :config (setq jao-notmuch-mailboxes (jao-mailbox-folders))) - #+end_src * tree view #+begin_src emacs-lisp -- cgit v1.2.3