Re: [PATCH (draft) 1/2] emacs: allow the user to toggle the visibility of multipart...
authorEthan Glasser-Camp <ethan.glasser.camp@gmail.com>
Sun, 28 Oct 2012 00:08:49 +0000 (20:08 +2000)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:50:07 +0000 (09:50 -0800)
ec/97b6db36af9aa7a40217da9a78e959ac0e55a0 [new file with mode: 0644]

diff --git a/ec/97b6db36af9aa7a40217da9a78e959ac0e55a0 b/ec/97b6db36af9aa7a40217da9a78e959ac0e55a0
new file mode 100644 (file)
index 0000000..2b12019
--- /dev/null
@@ -0,0 +1,167 @@
+Return-Path: <ethan.glasser.camp@gmail.com>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+       by olra.theworths.org (Postfix) with ESMTP id 695CB431FB6\r
+       for <notmuch@notmuchmail.org>; Sat, 27 Oct 2012 17:08:58 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.776\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.776 tagged_above=-999 required=5\r
+       tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,\r
+       FREEMAIL_FROM=0.001, HS_INDEX_PARAM=0.023, RCVD_IN_DNSWL_LOW=-0.7]\r
+       autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+       by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+       with ESMTP id 9EcVQPzK08vB for <notmuch@notmuchmail.org>;\r
+       Sat, 27 Oct 2012 17:08:54 -0700 (PDT)\r
+Received: from mail-qc0-f181.google.com (mail-qc0-f181.google.com\r
+       [209.85.216.181]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id E9DA0431FAF\r
+       for <notmuch@notmuchmail.org>; Sat, 27 Oct 2012 17:08:53 -0700 (PDT)\r
+Received: by mail-qc0-f181.google.com with SMTP id x40so2310975qcp.26\r
+       for <notmuch@notmuchmail.org>; Sat, 27 Oct 2012 17:08:52 -0700 (PDT)\r
+DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;\r
+       h=from:to:subject:in-reply-to:references:user-agent:date:message-id\r
+       :mime-version:content-type;\r
+       bh=B8rkjqe5YyFWY0Ty/OOTXjyJoY5CcBSoeMjgnw3CMjc=;\r
+       b=HXor86Nje+zDMilqk+GJwQ+D5U6445DCh164scrG3NpDQn3MsW1hOzOtDPWui8n3mY\r
+       ZXB54Ha1WxcHlgJJI4HDLMCfwAWkux/XgCqMuCAe6Yc9/XZe+yk1MKh0A0etyUTR07Kb\r
+       JPlZN+LPpFe/Ak1kFMwu3hiKsm9LI8TRRzddU1pHwMzRGJclZNOYQtr1joT5qJUHY9fq\r
+       Ujg8BJHHkvJRoKHNqIbqU8Nm3a5/jcyW81WVK6Qs++AnR0YWn8vaHRw3zXBKyqtP3MTb\r
+       AEorxyVybRioCSFZ8mHoSenl4ESriEX2Sl3t+QmRScxCBM+bPQv6JImM0RUr6yOfz58C\r
+       e7yg==\r
+Received: by 10.224.194.193 with SMTP id dz1mr14727965qab.0.1351382932078;\r
+       Sat, 27 Oct 2012 17:08:52 -0700 (PDT)\r
+Received: from smtp.gmail.com (p70-80.acedsl.com. [66.114.70.80])\r
+       by mx.google.com with ESMTPS id bc9sm3485926qab.2.2012.10.27.17.08.50\r
+       (version=TLSv1/SSLv3 cipher=OTHER);\r
+       Sat, 27 Oct 2012 17:08:51 -0700 (PDT)\r
+From: Ethan Glasser-Camp <ethan.glasser.camp@gmail.com>\r
+To: Mark Walters <markwalters1009@gmail.com>, notmuch@notmuchmail.org\r
+Subject: Re: [PATCH (draft) 1/2] emacs: allow the user to toggle the\r
+       visibility of multipart/alternative parts\r
+In-Reply-To: <1351152563-27277-2-git-send-email-markwalters1009@gmail.com>\r
+References: <1351152563-27277-1-git-send-email-markwalters1009@gmail.com>\r
+       <1351152563-27277-2-git-send-email-markwalters1009@gmail.com>\r
+User-Agent: Notmuch/0.14+45~g6ea9330 (http://notmuchmail.org) Emacs/23.4.1\r
+       (x86_64-pc-linux-gnu)\r
+Date: Sat, 27 Oct 2012 20:08:49 -0400\r
+Message-ID: <87sj8zh2zy.fsf@betacantrips.com>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain; charset=us-ascii\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+       <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Sun, 28 Oct 2012 00:08:58 -0000\r
+\r
+Mark Walters <markwalters1009@gmail.com> writes:\r
+\r
+> This patch adds a keybinding to the buttons in the notmuch-show emacs\r
+> buffer to allow the user to toggle the visibility of each part of a\r
+> message in the show buffer.  This is particularly useful for\r
+> multipart/alternative parts where the parts are not really\r
+> alternatives but contain different information.\r
+> ---\r
+>  emacs/notmuch-show.el |   47 +++++++++++++++++++++++++++++++++++++++--------\r
+>  1 files changed, 39 insertions(+), 8 deletions(-)\r
+>\r
+> diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el\r
+> index 0f54259..9157669 100644\r
+> --- a/emacs/notmuch-show.el\r
+> +++ b/emacs/notmuch-show.el\r
+> @@ -155,6 +155,10 @@ indentation."\r
+>  (make-variable-buffer-local 'notmuch-show-indent-content)\r
+>  (put 'notmuch-show-indent-content 'permanent-local t)\r
+>\r
+> +(defvar notmuch-show-message-multipart/alternative-display-parts nil)\r
+> +(make-variable-buffer-local 'notmuch-show-message-multipart/alternative-display-parts)\r
+> +(put 'notmuch-show-message-multipart/alternative-display-parts 'permanent-local t)\r
+> +\r
+>  (defcustom notmuch-show-stash-mlarchive-link-alist\r
+>    '(("Gmane" . "http://mid.gmane.org/")\r
+>      ("MARC" . "http://marc.info/?i=")\r
+> @@ -455,6 +459,7 @@ message at DEPTH in the current thread."\r
+>      (define-key map "v" 'notmuch-show-part-button-view)\r
+>      (define-key map "o" 'notmuch-show-part-button-interactively-view)\r
+>      (define-key map "|" 'notmuch-show-part-button-pipe)\r
+> +    (define-key map "t" 'notmuch-show-part-button-internally-show)\r
+>      map)\r
+>    "Submap for button commands")\r
+>  (fset 'notmuch-show-part-button-map notmuch-show-part-button-map)\r
+> @@ -531,6 +536,16 @@ message at DEPTH in the current thread."\r
+>      (let ((handle (mm-make-handle (current-buffer) (list content-type))))\r
+>        (mm-pipe-part handle))))\r
+>\r
+> +(defun notmuch-show-internally-show-part (message-id nth &optional filename content-type)\r
+> +  "Set a part to be displayed internally"\r
+> +  (let ((current-parts (lax-plist-get notmuch-show-message-multipart/alternative-display-parts message-id)))\r
+> +    (setq notmuch-show-message-multipart/alternative-display-parts\r
+> +       (lax-plist-put notmuch-show-message-multipart/alternative-display-parts message-id\r
+> +                      (if (memq nth current-parts)\r
+> +                          (delq nth current-parts)\r
+> +                        (cons nth current-parts)))))\r
+> +  (notmuch-show-refresh-view))\r
+> +\r
+>  (defun notmuch-show-multipart/*-to-list (part)\r
+>    (mapcar (lambda (inner-part) (plist-get inner-part :content-type))\r
+>         (plist-get part :content)))\r
+> @@ -543,12 +558,15 @@ message at DEPTH in the current thread."\r
+>      ;; This inserts all parts of the chosen type rather than just one,\r
+>      ;; but it's not clear that this is the wrong thing to do - which\r
+>      ;; should be chosen if there are more than one that match?\r
+> +\r
+> +    ;; The variable user-parts says which parts should override the\r
+> +    ;; default so we use xor (handcoded since lisp does not have it).\r
+\r
+I don't follow the comment. user-parts isn't used in this\r
+function. Neither is xor.\r
+\r
+>      (mapc (lambda (inner-part)\r
+>           (let ((inner-type (plist-get inner-part :content-type)))\r
+> -           (if (or notmuch-show-all-multipart/alternative-parts\r
+> -                   (string= chosen-type inner-type))\r
+> -               (notmuch-show-insert-bodypart msg inner-part depth)\r
+> -             (notmuch-show-insert-part-header (plist-get inner-part :id) inner-type inner-type nil " (not shown)"))))\r
+> +           (notmuch-show-insert-bodypart msg inner-part depth\r
+> +                                         (not (or notmuch-show-all-multipart/alternative-parts\r
+> +                                                  (string=\r
+>           chosen-type inner-type))))))\r
+\r
+For what it's worth, I found this not-shown logic very confusing, and\r
+have had to think about it seven or eight different times to make sure I\r
+understood what's going on. I'm not sure why exactly this is, though I\r
+could offer hypotheses -- the fact that it's split across two functions,\r
+or the fiddling with mime-types. I'm satisfied that it's correct, but I\r
+wish it could be made clearer.\r
+\r
+This is just armchair hypothesizing, but here are some ideas that might\r
+make it more obvious what's going on: bringing the user-parts logic into\r
+this function; making user-parts, instead of a "t" meaning "user has\r
+toggled this", something like 'opened or 'closed and if user-parts for\r
+this message is absent, falling back to this calculation; alternately,\r
+prefilling user-parts with t when show is invoked, according to this\r
+calculation, and then not using it any more; moving this\r
+not-shown calculation into a separate function, something like notmuch-show-get-message-visibility.\r
+\r
+I guess I jumped into this series halfway, but why are we doing this\r
+with the wipe/redraw technique instead of just using invisible overlays,\r
+like we do more generally with notmuch-show? I think I agree that\r
+toggling individual parts is a good UI approach, and this isn't a bad\r
+way to implement it, but I wonder if we could do it better/easier if we\r
+used emacs's builtin functionality.\r
+\r
+Thanks!\r
+\r
+Ethan\r