[PATCH v5 2/7] emacs/show: Accommodate the lack of part header buttons
authorMark Walters <markwalters1009@gmail.com>
Sun, 14 Feb 2016 18:39:54 +0000 (18:39 +0000)
committerW. Trevor King <wking@tremily.us>
Sat, 20 Aug 2016 23:21:07 +0000 (16:21 -0700)
10/e38d89c44836424465e4834d9f6b659e048038 [new file with mode: 0644]

diff --git a/10/e38d89c44836424465e4834d9f6b659e048038 b/10/e38d89c44836424465e4834d9f6b659e048038
new file mode 100644 (file)
index 0000000..ef75d26
--- /dev/null
@@ -0,0 +1,218 @@
+Return-Path: <markwalters1009@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 arlo.cworth.org (Postfix) with ESMTP id BFBA66DE1ABD\r
+ for <notmuch@notmuchmail.org>; Sun, 14 Feb 2016 10:40:24 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at cworth.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.245\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.245 tagged_above=-999 required=5 tests=[AWL=0.325,\r
+  DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,\r
+ FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7,\r
+ RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_PASS=-0.001]\r
+ autolearn=disabled\r
+Received: from arlo.cworth.org ([127.0.0.1])\r
+ by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id gAMLtTLOgIgy for <notmuch@notmuchmail.org>;\r
+ Sun, 14 Feb 2016 10:40:22 -0800 (PST)\r
+Received: from mail-wm0-f66.google.com (mail-wm0-f66.google.com\r
+ [74.125.82.66]) by arlo.cworth.org (Postfix) with ESMTPS id 5CA776DE0A87 for\r
+ <notmuch@notmuchmail.org>; Sun, 14 Feb 2016 10:40:18 -0800 (PST)\r
+Received: by mail-wm0-f66.google.com with SMTP id c200so12198238wme.0\r
+ for <notmuch@notmuchmail.org>; Sun, 14 Feb 2016 10:40:18 -0800 (PST)\r
+DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;\r
+ h=from:to:cc:subject:date:message-id:in-reply-to:references;\r
+ bh=gCEQUDTI2mN64Kcd22gStbK2S8d4mhSuPOKJSkGWhmw=;\r
+ b=VPgsp1SyixpT+9Zz5XUvLHO/bTGFtWo1dZt4o0eicNPxJk6PjyGMxD9+Qb04yZbM9g\r
+ u/KgOwQrdApSmOvlXL0dbv2I6r91M44dywZRarGHrmvXgDZRx+OoanfbJQIXGiqy2fyH\r
+ vgjPBZ1pjPzyQZqI7jMQ8rpKOJrxa5ShHaDPYwk/d7YJsFlOvlmwgtGjFAZR3vANroxr\r
+ oGEwtOt52gTmjsZ/vub6JFNpC9Ixi2pdade6TVVoiN4nc79AYgu0LfITvCkr/Tek/KOX\r
+ pYm1+VC3NGT2TdUFaPExmBloL3CxHu0pO6RiK9ak66DRQMv6UgX9+c7bNi3AUCMRIE2I\r
+ QwzQ==\r
+X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\r
+ d=1e100.net; s=20130820;\r
+ h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to\r
+ :references;\r
+ bh=gCEQUDTI2mN64Kcd22gStbK2S8d4mhSuPOKJSkGWhmw=;\r
+ b=UH0YcFCLc2IRnYxz1o7hYigNn6LP8E/sabPvGqdrklx8iFIg1sxHjqOROeCQ3YNRmK\r
+ jOyNjMDf9KcoUxRDhRLO3W9P35D6EB2EQMkmdFd6CpdL7jyXW5oT47uLPxDTkH+hv5S1\r
+ wNXbKkX6MDoU+WmyG/B/AkBONy8zMNDodIu42HgSjqCX1iymIT8dXey/1b32q47Hu77+\r
+ LRobqbGxZ5JM9j9loMs4UzI7VSXIALcLcT0afoaE32PaM3XfBRNPt6NhC5YjDVmkw6dT\r
+ 4hb3AJID6FLxnCHgmADDr/xmCGsdZjkSN4Bj4MXBtwk42/amtsOiikH6tm+5Y0ghtUD7\r
+ qtdA==\r
+X-Gm-Message-State:\r
+ AG10YOT7roZv4ogbHAI7BNxAmJQM/n1wzZRlCKld5Z9irQQETgoqDyL/LDx6/oEhbZcyLQ==\r
+X-Received: by 10.28.68.139 with SMTP id r133mr8319922wma.13.1455475217106;\r
+ Sun, 14 Feb 2016 10:40:17 -0800 (PST)\r
+Received: from localhost (5751dfa2.skybroadband.com. [87.81.223.162])\r
+ by smtp.gmail.com with ESMTPSA id r10sm21676952wjz.24.2016.02.14.10.40.16\r
+ (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);\r
+ Sun, 14 Feb 2016 10:40:16 -0800 (PST)\r
+From: Mark Walters <markwalters1009@gmail.com>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH v5 2/7] emacs/show: Accommodate the lack of part header\r
+ buttons\r
+Date: Sun, 14 Feb 2016 18:39:54 +0000\r
+Message-Id: <1455475199-32622-3-git-send-email-markwalters1009@gmail.com>\r
+X-Mailer: git-send-email 2.1.4\r
+In-Reply-To: <1455475199-32622-1-git-send-email-markwalters1009@gmail.com>\r
+References: <1455475199-32622-1-git-send-email-markwalters1009@gmail.com>\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.20\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+ <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <https://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: <https://notmuchmail.org/mailman/listinfo/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Sun, 14 Feb 2016 18:40:24 -0000\r
+\r
+From: David Edmondson <dme@dme.org>\r
+\r
+Various pieces of code assumed (reasonably) that part header buttons\r
+are present. Modify them to avoid problems if no part headers were\r
+inserted.\r
+---\r
+ emacs/notmuch-show.el | 88 ++++++++++++++++++++++++++++-----------------------\r
+ 1 file changed, 48 insertions(+), 40 deletions(-)\r
+\r
+diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el\r
+index 70cdb9d..37ed74d 100644\r
+--- a/emacs/notmuch-show.el\r
++++ b/emacs/notmuch-show.el\r
+@@ -507,36 +507,37 @@ message at DEPTH in the current thread."\r
\r
+ (defun notmuch-show-toggle-part-invisibility (&optional button)\r
+   (interactive)\r
+-  (let* ((button (or button (button-at (point))))\r
+-       (overlay (button-get button 'overlay))\r
+-       (lazy-part (button-get button :notmuch-lazy-part)))\r
+-    ;; We have a part to toggle if there is an overlay or if there is a lazy part.\r
+-    ;; If neither is present we cannot toggle the part so we just return nil.\r
+-    (when (or overlay lazy-part)\r
+-      (let* ((show (button-get button :notmuch-part-hidden))\r
+-           (new-start (button-start button))\r
+-           (button-label (button-get button :base-label))\r
+-           (old-point (point))\r
+-           (properties (text-properties-at (button-start button)))\r
+-           (inhibit-read-only t))\r
+-      ;; Toggle the button itself.\r
+-      (button-put button :notmuch-part-hidden (not show))\r
+-      (goto-char new-start)\r
+-      (insert "[ " button-label (if show " ]" " (hidden) ]"))\r
+-      (set-text-properties new-start (point) properties)\r
+-      (let ((old-end (button-end button)))\r
+-        (move-overlay button new-start (point))\r
+-        (delete-region (point) old-end))\r
+-      (goto-char (min old-point (1- (button-end button))))\r
+-      ;; Return nil if there is a lazy-part, it is empty, and we are\r
+-      ;; trying to show it.  In all other cases return t.\r
+-      (if lazy-part\r
+-          (when show\r
+-            (button-put button :notmuch-lazy-part nil)\r
+-            (notmuch-show-lazy-part lazy-part button))\r
+-        ;; else there must be an overlay.\r
+-        (overlay-put overlay 'invisible (not show))\r
+-        t)))))\r
++  (let ((button (or button (button-at (point)))))\r
++    (when button\r
++      (let ((overlay (button-get button 'overlay))\r
++          (lazy-part (button-get button :notmuch-lazy-part)))\r
++      ;; We have a part to toggle if there is an overlay or if there is a lazy part.\r
++      ;; If neither is present we cannot toggle the part so we just return nil.\r
++      (when (or overlay lazy-part)\r
++        (let* ((show (button-get button :notmuch-part-hidden))\r
++               (new-start (button-start button))\r
++               (button-label (button-get button :base-label))\r
++               (old-point (point))\r
++               (properties (text-properties-at (button-start button)))\r
++               (inhibit-read-only t))\r
++          ;; Toggle the button itself.\r
++          (button-put button :notmuch-part-hidden (not show))\r
++          (goto-char new-start)\r
++          (insert "[ " button-label (if show " ]" " (hidden) ]"))\r
++          (set-text-properties new-start (point) properties)\r
++          (let ((old-end (button-end button)))\r
++            (move-overlay button new-start (point))\r
++            (delete-region (point) old-end))\r
++          (goto-char (min old-point (1- (button-end button))))\r
++          ;; Return nil if there is a lazy-part, it is empty, and we are\r
++          ;; trying to show it.  In all other cases return t.\r
++          (if lazy-part\r
++              (when show\r
++                (button-put button :notmuch-lazy-part nil)\r
++                (notmuch-show-lazy-part lazy-part button))\r
++            ;; else there must be an overlay.\r
++            (overlay-put overlay 'invisible (not show))\r
++            t)))))))\r
\r
+ ;; Part content ID handling\r
\r
+@@ -645,14 +646,17 @@ will return nil if the CID is unknown or cannot be retrieved."\r
+   t)\r
\r
+ (defun notmuch-show-insert-part-multipart/signed (msg part content-type nth depth button)\r
+-  (button-put button 'face 'notmuch-crypto-part-header)\r
+-  ;; add signature status button if sigstatus provided\r
++  (when button\r
++    (button-put button 'face 'notmuch-crypto-part-header))\r
++  ;; Add signature status button if sigstatus provided.\r
+   (if (plist-member part :sigstatus)\r
+       (let* ((from (notmuch-show-get-header :From msg))\r
+            (sigstatus (car (plist-get part :sigstatus))))\r
+       (notmuch-crypto-insert-sigstatus-button sigstatus from))\r
+-    ;; if we're not adding sigstatus, tell the user how they can get it\r
+-    (button-put button 'help-echo "Set notmuch-crypto-process-mime to process cryptographic MIME parts."))\r
++    ;; If we're not adding the signature status, tell the user how\r
++    ;; they can get it.\r
++    (when button\r
++      (button-put button 'help-echo "Set notmuch-crypto-process-mime to process cryptographic MIME parts.")))\r
\r
+   (let ((inner-parts (plist-get part :content))\r
+       (start (point)))\r
+@@ -666,17 +670,20 @@ will return nil if the CID is unknown or cannot be retrieved."\r
+   t)\r
\r
+ (defun notmuch-show-insert-part-multipart/encrypted (msg part content-type nth depth button)\r
+-  (button-put button 'face 'notmuch-crypto-part-header)\r
+-  ;; add encryption status button if encstatus specified\r
++  (when button\r
++    (button-put button 'face 'notmuch-crypto-part-header))\r
++  ;; Add encryption status button if encryption status is specified.\r
+   (if (plist-member part :encstatus)\r
+       (let ((encstatus (car (plist-get part :encstatus))))\r
+       (notmuch-crypto-insert-encstatus-button encstatus)\r
+-      ;; add signature status button if sigstatus specified\r
++      ;; Add signature status button if signature status is\r
++      ;; specified.\r
+       (if (plist-member part :sigstatus)\r
+           (let* ((from (notmuch-show-get-header :From msg))\r
+                  (sigstatus (car (plist-get part :sigstatus))))\r
+             (notmuch-crypto-insert-sigstatus-button sigstatus from))))\r
+-    ;; if we're not adding encstatus, tell the user how they can get it\r
++    ;; If we're not adding the encryption status, tell the user how\r
++    ;; they can get it.\r
+     (button-put button 'help-echo "Set notmuch-crypto-process-mime to process cryptographic MIME parts."))\r
\r
+   (let ((inner-parts (plist-get part :content))\r
+@@ -976,8 +983,9 @@ useful for quoting in replies)."\r
\r
+     (if show-part\r
+         (notmuch-show-insert-bodypart-internal msg part mime-type nth depth button)\r
+-      (button-put button :notmuch-lazy-part\r
+-                  (list msg part mime-type nth depth button)))\r
++      (when button\r
++      (button-put button :notmuch-lazy-part\r
++                  (list msg part mime-type nth depth button))))\r
\r
+     ;; Some of the body part handlers leave point somewhere up in the\r
+     ;; part, so we make sure that we're down at the end.\r
+-- \r
+2.1.4\r
+\r