[PATCH 2/3] emacs: `notmuch-show-buttonize-links' only `notmuch-show's a message...
authorPieter Praet <pieter@praet.org>
Thu, 12 Jan 2012 17:23:44 +0000 (18:23 +0100)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:41:59 +0000 (09:41 -0800)
83/7284120f8ade66b23e8f5eaee179247ac7b636 [new file with mode: 0644]

diff --git a/83/7284120f8ade66b23e8f5eaee179247ac7b636 b/83/7284120f8ade66b23e8f5eaee179247ac7b636
new file mode 100644 (file)
index 0000000..3a20331
--- /dev/null
@@ -0,0 +1,112 @@
+Return-Path: <pieter@praet.org>\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 9AE55429E37\r
+       for <notmuch@notmuchmail.org>; Thu, 12 Jan 2012 09:25:48 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.7\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
+       tests=[RCVD_IN_DNSWL_LOW=-0.7] 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 QR1TMh8i7tIb for <notmuch@notmuchmail.org>;\r
+       Thu, 12 Jan 2012 09:25:48 -0800 (PST)\r
+Received: from mail-we0-f181.google.com (mail-we0-f181.google.com\r
+       [74.125.82.181]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id 064DA429E30\r
+       for <notmuch@notmuchmail.org>; Thu, 12 Jan 2012 09:25:47 -0800 (PST)\r
+Received: by werm12 with SMTP id m12so1808422wer.26\r
+       for <notmuch@notmuchmail.org>; Thu, 12 Jan 2012 09:25:46 -0800 (PST)\r
+Received: by 10.216.135.208 with SMTP id u58mr254136wei.56.1326389146877;\r
+       Thu, 12 Jan 2012 09:25:46 -0800 (PST)\r
+Received: from localhost ([109.131.126.209])\r
+       by mx.google.com with ESMTPS id g12sm10093619wiw.10.2012.01.12.09.25.46\r
+       (version=TLSv1/SSLv3 cipher=OTHER);\r
+       Thu, 12 Jan 2012 09:25:46 -0800 (PST)\r
+From: Pieter Praet <pieter@praet.org>\r
+To: Jameson Graef Rollins <jrollins@finestructure.net>\r
+Subject: [PATCH 2/3] emacs: `notmuch-show-buttonize-links' only\r
+       `notmuch-show's a message if it exists\r
+Date: Thu, 12 Jan 2012 18:23:44 +0100\r
+Message-Id: <1326389025-18877-2-git-send-email-pieter@praet.org>\r
+X-Mailer: git-send-email 1.7.8.1\r
+In-Reply-To: <1326389025-18877-1-git-send-email-pieter@praet.org>\r
+References: <874nw0ltwz.fsf@praet.org>\r
+       <1326389025-18877-1-git-send-email-pieter@praet.org>\r
+Cc: Notmuch Mail <notmuch@notmuchmail.org>\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: Thu, 12 Jan 2012 17:25:48 -0000\r
+\r
+* emacs/notmuch-show.el (notmuch-show-found-target-p): new predicate function\r
+  that uses notmuch(1) 'count' to see if a query turns up any results.\r
+\r
+* emacs/notmuch-show.el (notmuch-show-if-found): new function that only shows\r
+  a message/thread if present in the database and otherwise returns an error.\r
+\r
+* emacs/notmuch-show.el (notmuch-show-buttonize-links): some deduplication,\r
+  and use new function `notmuch-show-if-found' instead of `notmuch-show'\r
+  to prevent showing a blank screen for Message-Id's which aren't present\r
+  in the database.\r
+---\r
+ emacs/notmuch-show.el |   21 ++++++++++++++++++---\r
+ 1 files changed, 18 insertions(+), 3 deletions(-)\r
+\r
+diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el\r
+index c55a1d1..8f12955 100644\r
+--- a/emacs/notmuch-show.el\r
++++ b/emacs/notmuch-show.el\r
+@@ -806,11 +806,14 @@ a corresponding notmuch search."\r
+   (save-excursion\r
+     (goto-char start)\r
+     (while (re-search-forward "id:\\(\"?\\)[^[:space:]\"]+\\1" end t)\r
++      (let ((message-id (match-string-no-properties 0))\r
++          (string-start (match-beginning 0))\r
++          (string-end (match-end 0)))\r
+       ;; remove the overlay created by goto-address-mode\r
+-      (remove-overlays (match-beginning 0) (match-end 0) 'goto-address t)\r
+-      (make-text-button (match-beginning 0) (match-end 0)\r
++      (remove-overlays string-start string-end 'goto-address t)\r
++      (make-text-button string-start string-end\r
+                       'action `(lambda (arg)\r
+-                                 (notmuch-show ,(match-string-no-properties 0)))\r
++                                 (notmuch-show-if-found ,message-id))\r
+                       'follow-link t\r
+                       'help-echo "Mouse-1, RET: search for this message"\r
+                       'face goto-address-mail-face))))\r
+@@ -906,6 +909,18 @@ thread id.  If a prefix is given, crypto processing is toggled."\r
+     (notmuch-kill-this-buffer)\r
+     (notmuch-show-worker thread-id parent-buffer query-context buffer-name process-crypto)))\r
\r
++(defun notmuch-show-found-target-p (target)\r
++  (let ((args `("count" ,target)))\r
++    (> (string-to-number (substring\r
++      (with-output-to-string\r
++        (apply 'call-process notmuch-command nil standard-output nil args))\r
++      0 -1)) 0)))\r
++\r
++(defun notmuch-show-if-found (target &rest args)\r
++  (if (notmuch-show-found-target-p target nil)\r
++      (notmuch-show target args)\r
++    (error (format "Can't find target: %s" target))))\r
++\r
+ (defvar notmuch-show-stash-map\r
+   (let ((map (make-sparse-keymap)))\r
+     (define-key map "c" 'notmuch-show-stash-cc)\r
+-- \r
+1.7.8.1\r
+\r