unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: Ethan Glasser-Camp <ethan.glasser.camp@gmail.com>
To: Mark Walters <markwalters1009@gmail.com>,
	Jameson Graef Rollins <jrollins@finestructure.net>,
	Jani Nikula <jani@nikula.org>,
	notmuch@notmuchmail.org
Subject: Re: [PATCH v2] emacs: add function to toggle display of all multipart/alternative parts
Date: Fri, 19 Oct 2012 12:36:26 -0400	[thread overview]
Message-ID: <87pq4e771x.fsf@betacantrips.com> (raw)
In-Reply-To: <87r4rf9q8x.fsf@qmul.ac.uk>

Mark Walters <markwalters1009@gmail.com> writes:

> Some messages are sent as multipart/alternative but the alternatives
> contain different information. This allows the user to cycle which
> part to view. By default this is bound to 'W'.
> ---
>
> This version at least uses the notmuch escaping for message-id which
> makes me a bit happier: it probably doesn't have any nasty security
> flaws. I do still feel that the lisp is a bit ugly though.

For what it's worth, I don't feel that this code is horrible. It seems
like there remain design decisions to be made about how notmuch show
"ought" to handle multipart/alternatives, but I can at least comment on
this code.

First, the use of a plist looks fine to me because most of the time it's
going to have length 0. At most it will have one entry per message -- a
few hundred. So I'm not worried about efficiency concerns.

>  (defcustom notmuch-show-stash-mlarchive-link-alist
>    '(("Gmane" . "http://mid.gmane.org/")
>      ("MARC" . "http://marc.info/?i=")
> @@ -536,9 +540,19 @@ 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-display-part
> +					(notmuch-id-to-query (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)))

Changing let to let* makes me the slightest bit uneasy, although I'm not
sure I could explain why.

It would be nice if you could wrap the manipulation of
notmuch-show-message-multipart/alternative-display-part in functions,
ideally with names that are shorter than the variable they
manipulate. Specifically, I think the definition of chosen-nth (which is
almost repeated below) could be its own function, something like
(notmuch-show-message-current-multipart msg), which could take a msg-id
or a plist and do the plist-get and id-to-query that you do here.

> +    ;; 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-display-part
> +	    (lax-plist-put notmuch-show-message-multipart/alternative-display-part
> +			   (notmuch-id-to-query (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?
> @@ -942,6 +956,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."

This docstring is broken.

> +  (interactive)
> +  (let* ((msg-id (notmuch-show-get-message-id))
> +	 (next-part (1+ (or (lax-plist-get notmuch-show-message-multipart/alternative-display-part msg-id) 0))))
> +    (setq notmuch-show-message-multipart/alternative-display-part
> +	(lax-plist-put notmuch-show-message-multipart/alternative-display-part msg-id next-part))
> +    (message "Cycling multipart/alternative for current message")
> +    (notmuch-show-refresh-view)))

Maybe move the reset-and-go-back-to-zero behavior to this function
instead of in the display function. This opens you up to weird
situations if one of the multipart/alternatives should disappear from a
message or if some other function should change the alternative on
display for a given message, but both of these seem unlikely to me..

Ethan

  parent reply	other threads:[~2012-10-19 16:36 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-06-15 15:55 [PATCH] emacs: add function to toggle display of all multipart/alternative parts Jani Nikula
2012-06-18 21:26 ` Jameson Graef Rollins
2012-06-19  6:56   ` Mark Walters
2012-08-09 20:52     ` Jameson Graef Rollins
2012-08-10  7:10       ` [PATCH v2] " Mark Walters
2012-08-10 14:53         ` Jani Nikula
2012-08-10 16:18           ` Jameson Graef Rollins
2012-08-10 16:39             ` Jani Nikula
2012-08-10 16:58               ` Mark Walters
2012-08-10 17:49                 ` Jameson Graef Rollins
2012-08-12 17:39         ` [PATCH 1/2] test: add emacs show mode test for toggling display of multipart/alternative Jameson Graef Rollins
2012-08-12 17:39           ` [PATCH 2/2] test: move all emacs show tests to emacs-show test script Jameson Graef Rollins
2012-08-31 19:44             ` David Bremner
2012-10-20  2:31           ` [PATCH 1/2] test: add emacs show mode test for toggling display of multipart/alternative Ethan Glasser-Camp
2012-10-09 22:21         ` [PATCH v2] emacs: add function to toggle display of all multipart/alternative parts Jeremy Nickurak
2012-10-19 16:36         ` Ethan Glasser-Camp [this message]
2012-06-19  6:57   ` [PATCH] " Jani Nikula
2012-06-19 20:14 ` [PATCH v2] " Jani Nikula
2012-06-19 20:25   ` Jani Nikula
2012-06-22 22:34   ` David Bremner
2012-06-24  7:10     ` Jani Nikula
2012-06-24 18:56   ` Mark Walters
2012-10-19 16:14     ` [PATCH] Add NEWS item for multipart/alternative toggle Ethan Glasser-Camp

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=87pq4e771x.fsf@betacantrips.com \
    --to=ethan.glasser.camp@gmail.com \
    --cc=jani@nikula.org \
    --cc=jrollins@finestructure.net \
    --cc=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).