From: Mark Walters <markwalters1009@gmail.com>
To: notmuch@notmuchmail.org
Subject: [PATCH (draft) 1/2] emacs: allow the user to toggle the visibility of multipart/alternative parts
Date: Thu, 25 Oct 2012 09:09:22 +0100 [thread overview]
Message-ID: <1351152563-27277-2-git-send-email-markwalters1009@gmail.com> (raw)
In-Reply-To: <1351152563-27277-1-git-send-email-markwalters1009@gmail.com>
This patch adds a keybinding to the buttons in the notmuch-show emacs
buffer to allow the user to toggle the visibility of each part of a
message in the show buffer. This is particularly useful for
multipart/alternative parts where the parts are not really
alternatives but contain different information.
---
emacs/notmuch-show.el | 47 +++++++++++++++++++++++++++++++++++++++--------
1 files changed, 39 insertions(+), 8 deletions(-)
diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index 0f54259..9157669 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -155,6 +155,10 @@ indentation."
(make-variable-buffer-local 'notmuch-show-indent-content)
(put 'notmuch-show-indent-content 'permanent-local t)
+(defvar notmuch-show-message-multipart/alternative-display-parts nil)
+(make-variable-buffer-local 'notmuch-show-message-multipart/alternative-display-parts)
+(put 'notmuch-show-message-multipart/alternative-display-parts 'permanent-local t)
+
(defcustom notmuch-show-stash-mlarchive-link-alist
'(("Gmane" . "http://mid.gmane.org/")
("MARC" . "http://marc.info/?i=")
@@ -455,6 +459,7 @@ message at DEPTH in the current thread."
(define-key map "v" 'notmuch-show-part-button-view)
(define-key map "o" 'notmuch-show-part-button-interactively-view)
(define-key map "|" 'notmuch-show-part-button-pipe)
+ (define-key map "t" 'notmuch-show-part-button-internally-show)
map)
"Submap for button commands")
(fset 'notmuch-show-part-button-map notmuch-show-part-button-map)
@@ -531,6 +536,16 @@ message at DEPTH in the current thread."
(let ((handle (mm-make-handle (current-buffer) (list content-type))))
(mm-pipe-part handle))))
+(defun notmuch-show-internally-show-part (message-id nth &optional filename content-type)
+ "Set a part to be displayed internally"
+ (let ((current-parts (lax-plist-get notmuch-show-message-multipart/alternative-display-parts message-id)))
+ (setq notmuch-show-message-multipart/alternative-display-parts
+ (lax-plist-put notmuch-show-message-multipart/alternative-display-parts message-id
+ (if (memq nth current-parts)
+ (delq nth current-parts)
+ (cons nth current-parts)))))
+ (notmuch-show-refresh-view))
+
(defun notmuch-show-multipart/*-to-list (part)
(mapcar (lambda (inner-part) (plist-get inner-part :content-type))
(plist-get part :content)))
@@ -543,12 +558,15 @@ message at DEPTH in the current thread."
;; This inserts all parts of the chosen type rather than just one,
;; but it's not clear that this is the wrong thing to do - which
;; should be chosen if there are more than one that match?
+
+ ;; The variable user-parts says which parts should override the
+ ;; default so we use xor (handcoded since lisp does not have it).
+
(mapc (lambda (inner-part)
(let ((inner-type (plist-get inner-part :content-type)))
- (if (or notmuch-show-all-multipart/alternative-parts
- (string= chosen-type inner-type))
- (notmuch-show-insert-bodypart msg inner-part depth)
- (notmuch-show-insert-part-header (plist-get inner-part :id) inner-type inner-type nil " (not shown)"))))
+ (notmuch-show-insert-bodypart msg inner-part depth
+ (not (or notmuch-show-all-multipart/alternative-parts
+ (string= chosen-type inner-type))))))
inner-parts)
(when notmuch-show-indent-multipart
@@ -806,11 +824,20 @@ message at DEPTH in the current thread."
(setq handlers (cdr handlers))))
t)
-(defun notmuch-show-insert-bodypart (msg part depth)
- "Insert the body part PART at depth DEPTH in the current thread."
- (let ((content-type (downcase (plist-get part :content-type)))
+(defun notmuch-show-insert-bodypart (msg part depth &optional not-shown)
+ "Insert the body part PART at depth DEPTH in the current thread.
+
+If not-shown is TRUE then do not show the part unless the user
+has overridden the default for this part"
+ (let ((user-parts (lax-plist-get notmuch-show-message-multipart/alternative-display-parts
+ (notmuch-id-to-query (plist-get msg :id))))
+ (content-type (downcase (plist-get part :content-type)))
(nth (plist-get part :id)))
- (notmuch-show-insert-bodypart-internal msg part content-type nth depth content-type))
+ (when (memq nth user-parts)
+ (setq not-shown (not not-shown)))
+ (if not-shown
+ (notmuch-show-insert-part-header nth content-type content-type nil " (not shown)")
+ (notmuch-show-insert-bodypart-internal msg part content-type nth depth content-type)))
;; Some of the body part handlers leave point somewhere up in the
;; part, so we make sure that we're down at the end.
(goto-char (point-max))
@@ -1895,6 +1922,10 @@ the user (see `notmuch-show-stash-mlarchive-link-alist')."
(interactive)
(notmuch-show-part-button-internal button #'notmuch-show-pipe-part))
+(defun notmuch-show-part-button-internally-show (&optional button)
+ (interactive)
+ (notmuch-show-part-button-internal button #'notmuch-show-internally-show-part))
+
(defun notmuch-show-part-button-internal (button handler)
(let ((button (or button (button-at (point)))))
(if button
--
1.7.9.1
next prev parent reply other threads:[~2012-10-25 8:09 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-10-25 8:09 [PATCH (draft) 0/2] Allow emacs to toggle display of all parts including multipart Mark Walters
2012-10-25 8:09 ` Mark Walters [this message]
2012-10-28 0:08 ` [PATCH (draft) 1/2] emacs: allow the user to toggle the visibility of multipart/alternative parts Ethan Glasser-Camp
2012-10-28 8:00 ` Mark Walters
2012-10-25 8:09 ` [PATCH (draft) 2/2] emacs: show: make "view part" show hidden parts Mark Walters
2012-12-02 19:48 ` [PATCH (draft) 0/2] Allow emacs to toggle display of all parts including multipart Jani Nikula
2012-12-03 17:15 ` Jameson Graef Rollins
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://notmuchmail.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1351152563-27277-2-git-send-email-markwalters1009@gmail.com \
--to=markwalters1009@gmail.com \
--cc=notmuch@notmuchmail.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://yhetil.org/notmuch.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).