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