Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 20AC4431FBC for ; Mon, 18 Jun 2012 23:56:25 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -1.075 X-Spam-Level: X-Spam-Status: No, score=-1.075 tagged_above=-999 required=5 tests=[DKIM_ADSP_CUSTOM_MED=0.001, FREEMAIL_FROM=0.001, HS_INDEX_PARAM=0.023, NML_ADSP_CUSTOM_MED=1.2, RCVD_IN_DNSWL_MED=-2.3] autolearn=disabled Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id zSGNM+yZiXmJ for ; Mon, 18 Jun 2012 23:56:23 -0700 (PDT) Received: from mail2.qmul.ac.uk (mail2.qmul.ac.uk [138.37.6.6]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id 271D7431FAF for ; Mon, 18 Jun 2012 23:56:23 -0700 (PDT) Received: from smtp.qmul.ac.uk ([138.37.6.40]) by mail2.qmul.ac.uk with esmtp (Exim 4.71) (envelope-from ) id 1SgsML-0001RG-4h; Tue, 19 Jun 2012 07:56:17 +0100 Received: from 94-192-233-223.zone6.bethere.co.uk ([94.192.233.223] helo=localhost) by smtp.qmul.ac.uk with esmtpsa (TLSv1:AES128-SHA:128) (Exim 4.69) (envelope-from ) id 1SgsMK-0001mP-O1; Tue, 19 Jun 2012 07:56:16 +0100 From: Mark Walters To: Jameson Graef Rollins , Jani Nikula , notmuch@notmuchmail.org Subject: Re: [PATCH] emacs: add function to toggle display of all multipart/alternative parts In-Reply-To: <87zk80gvmb.fsf@servo.finestructure.net> References: <1339775751-18002-1-git-send-email-jani@nikula.org> <87zk80gvmb.fsf@servo.finestructure.net> User-Agent: Notmuch/0.13.2+63~g548a9bf (http://notmuchmail.org) Emacs/23.4.1 (x86_64-pc-linux-gnu) Date: Tue, 19 Jun 2012 07:56:14 +0100 Message-ID: <87pq8vokmp.fsf@qmul.ac.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Sender-Host-Address: 94.192.233.223 X-QM-SPAM-Info: Sender has good ham record. :) X-QM-Body-MD5: 351edbcb77f9caf3de3706b36db7fbb1 (of first 20000 bytes) X-SpamAssassin-Score: -1.5 X-SpamAssassin-SpamBar: - X-SpamAssassin-Report: The QM spam filters have analysed this message to determine if it is spam. We require at least 5.0 points to mark a message as spam. This message scored -1.5 points. Summary of the scoring: * -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at http://www.dnswl.org/, * medium trust * [138.37.6.40 listed in list.dnswl.org] * 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider * (markwalters1009[at]gmail.com) * -0.0 T_RP_MATCHES_RCVD Envelope sender domain matches handover relay * domain * 0.5 QM_SPAMMYURI URI: \".info\" uri is common in spam. * 0.0 HS_INDEX_PARAM URI: Link contains a common tracker pattern. * 0.3 AWL AWL: From: address is in the auto white-list X-QM-Scan-Virus: ClamAV says the message is clean X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 19 Jun 2012 06:56:25 -0000 On Mon, 18 Jun 2012, Jameson Graef Rollins wrote: > On Fri, Jun 15 2012, Jani Nikula wrote: >> Add function notmuch-show-toggle-multipart-alternative to make >> notmuch-show-all-multipart/alternative-parts buffer local, toggle its >> value in the buffer, and redisplay the thread with either all or >> preferred alternative parts expanded. >> >> A small wrinkle is that in order to make the variable survive >> notmuch-show-refresh-view (which is required for expanding/collapsing >> the parts, but ends up calling kill-all-local-variables through >> notmuch-show-mode) it is necessary to give it the permanent-local >> property. > > This is a very cool feature. I haven't looked closely at this but can't > this mechanism work the same as the other show-mode toggles, like crypto > or indenting? I wouldn't think it would require any more extra variable > stuff than what is used for those other toggles. > > Also, the *really* sweet thing would be if the toggle actually cycled > through display of the alternatives, only displaying one at a time. > That would be very swank. > > David Edmondson put together the other show-mode toggling stuff, so he > may be able to help with this as well. Hi I agree with this cycling approach but I think it needs to be per message rather than per buffer. I attach a rather hacky attempt at this below: on minimal testing it seems to work. But the lisp is really a bit gross. In particular I have no idea if I should be escaping the message ids (so this could break in unfortunate/insecure ways) Best wishes Mark >From 4164456d225fca3c62bacfdc08a21cf4b32b5067 Mon Sep 17 00:00:00 2001 From: Mark Walters Date: Tue, 19 Jun 2012 07:50:17 +0100 Subject: [PATCH] first attempt at cycling multipart --- emacs/notmuch-show.el | 29 ++++++++++++++++++++++++++--- 1 files changed, 26 insertions(+), 3 deletions(-) diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el index 0f54259..65a89fe 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 nil) +(make-variable-buffer-local 'notmuch-show-message-multipart/alternative) +(put 'notmuch-show-message-multipart/alternative 'permanent-local t) + (defcustom notmuch-show-stash-mlarchive-link-alist '(("Gmane" . "http://mid.gmane.org/") ("MARC" . "http://marc.info/?i=") @@ -537,9 +541,17 @@ message at DEPTH in the current thread." (defun notmuch-show-insert-part-multipart/alternative (msg part content-type nth depth declared-type) (notmuch-show-insert-part-header nth declared-type content-type nil) - (let ((chosen-type (car (notmuch-multipart/alternative-choose (notmuch-show-multipart/*-to-list part)))) - (inner-parts (plist-get part :content)) - (start (point))) + (let* ((chosen-nth (or (lax-plist-get notmuch-show-message-multipart/alternative (plist-get msg :id)) 0)) + (chosen-type (nth chosen-nth + (notmuch-multipart/alternative-choose (notmuch-show-multipart/*-to-list part)))) + (inner-parts (plist-get part :content)) + (start (point))) + ;; If we have run out of possible content-types restart from the beginning + (unless chosen-type + (setq chosen-type (car (notmuch-multipart/alternative-choose (notmuch-show-multipart/*-to-list part)))) + (setq notmuch-show-message-multipart/alternative + (lax-plist-put notmuch-show-message-multipart/alternative (plist-get msg :id) 0))) + ;; 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? @@ -943,6 +955,16 @@ message at DEPTH in the current thread." "Not processing cryptographic MIME parts.")) (notmuch-show-refresh-view)) +(defun notmuch-show-cycle-message-multipart () + "Cycle which part to display of a multipart messageToggle the display of non-matching messages." + (interactive) + (let* ((msg-id (notmuch-show-get-message-id t)) + (next-part (1+ (or (lax-plist-get notmuch-show-message-multipart/alternative msg-id) 0)))) + (setq notmuch-show-message-multipart/alternative + (lax-plist-put notmuch-show-message-multipart/alternative msg-id next-part)) + (message "Cycling multipart/alternative for current message") + (notmuch-show-refresh-view))) + (defun notmuch-show-toggle-elide-non-matching () "Toggle the display of non-matching messages." (interactive) @@ -1155,6 +1177,7 @@ reset based on the original query." (define-key map "R" 'notmuch-show-reply) (define-key map "|" 'notmuch-show-pipe-message) (define-key map "w" 'notmuch-show-save-attachments) + (define-key map "W" 'notmuch-show-cycle-message-multipart) (define-key map "V" 'notmuch-show-view-raw-message) (define-key map "v" 'notmuch-show-view-all-mime-parts) (define-key map "c" 'notmuch-show-stash-map) -- 1.7.9.1